@@ -16,33 +16,52 @@ import (
1616 "github.com/ActiveState/cli/internal/condition"
1717)
1818
19- var awsRegionName , awsBucketName string
19+ var awsRegionName , awsBucketName , basePrefix string
2020var client * s3.Client
2121
2222func main () {
2323 if ! condition .InUnitTest () {
24- if len (os .Args ) != 3 {
25- log .Fatalf ("Usage: %s <region-name> <bucket-name>" , os .Args [0 ])
24+ if len (os .Args ) != 3 && len ( os . Args ) != 4 {
25+ log .Fatalf ("Usage: %s <region-name> <bucket-name> [base-prefix] " , os .Args [0 ])
2626 }
2727
2828 awsRegionName = os .Args [1 ]
2929 awsBucketName = os .Args [2 ]
30+ if len (os .Args ) == 4 {
31+ basePrefix = os .Args [3 ]
32+ if basePrefix != "" && ! strings .HasSuffix (basePrefix , "/" ) {
33+ basePrefix += "/"
34+ }
35+ }
3036
3137 run ()
3238 }
3339}
3440
3541func run () {
3642 fmt .Printf ("Promoting staging files to production in bucket: %s\n " , awsBucketName )
43+ if basePrefix != "" {
44+ fmt .Printf ("Using base prefix: %s\n " , basePrefix )
45+ }
3746
3847 createClient ()
3948
40- // List all objects with staging/ prefix
41- stagingObjects , err := listObjectsWithPrefix ("staging/" )
49+ // List all objects with <basePrefix> staging/ prefix
50+ allObjects , err := listObjectsWithPrefix (basePrefix + "staging/" )
4251 if err != nil {
4352 log .Fatalf ("Failed to list staging objects: %v" , err )
4453 }
4554
55+ // Filter out the root staging directory itself (but keep subdirectories)
56+ var stagingObjects []types.Object
57+ stagingPrefix := basePrefix + "staging/"
58+ for _ , obj := range allObjects {
59+ if * obj .Key == stagingPrefix {
60+ continue
61+ }
62+ stagingObjects = append (stagingObjects , obj )
63+ }
64+
4665 if len (stagingObjects ) == 0 {
4766 fmt .Println ("No staging files found to promote." )
4867 return
@@ -56,13 +75,14 @@ func run() {
5675 // Copy each staging object to production location and delete the staging version
5776 for _ , obj := range stagingObjects {
5877 stagingKey := * obj .Key
59- productionKey := strings .TrimPrefix (stagingKey , "staging/" )
78+ relativeKey := strings .TrimPrefix (stagingKey , basePrefix + "staging/" )
79+ destinationKey := basePrefix + "release/" + relativeKey
6080
61- fmt .Printf ("Promoting %s -> %s\n " , stagingKey , productionKey )
81+ fmt .Printf ("Promoting %s -> %s\n " , stagingKey , destinationKey )
6282
63- err := copyObject (stagingKey , productionKey )
83+ err := copyObject (stagingKey , destinationKey )
6484 if err != nil {
65- log .Fatalf ("Failed to copy %s to %s: %v" , stagingKey , productionKey , err )
85+ log .Fatalf ("Failed to copy %s to %s: %v" , stagingKey , destinationKey , err )
6686 }
6787
6888 err = deleteObject (stagingKey )
0 commit comments