nats-upload: support just cleaning

This commit is contained in:
2026-02-25 08:19:41 +01:00
parent ebe428eee9
commit c776d47714
2 changed files with 48 additions and 44 deletions

1
.gitignore vendored
View File

@@ -27,3 +27,4 @@ go.work.sum
./bin ./bin
bin bin
nats-upload

View File

@@ -28,11 +28,12 @@ func main() {
skipNotify = flag.Bool("skip-notify", getEnvBool("INPUT_SKIP_NOTIFY", false), "Skip publishing update notification") skipNotify = flag.Bool("skip-notify", getEnvBool("INPUT_SKIP_NOTIFY", false), "Skip publishing update notification")
cleanup = flag.Int("cleanup", getEnvInt("INPUT_CLEANUP", 0), "Keep only N most recent versions (0 disables cleanup)") cleanup = flag.Int("cleanup", getEnvInt("INPUT_CLEANUP", 0), "Keep only N most recent versions (0 disables cleanup)")
cleanupAll = flag.Bool("cleanup-all", getEnvBool("INPUT_CLEANUP_ALL", false), "Cleanup all binaries, not just current one") cleanupAll = flag.Bool("cleanup-all", getEnvBool("INPUT_CLEANUP_ALL", false), "Cleanup all binaries, not just current one")
justClean = flag.Bool("just-clean", getEnvBool("INPUT_JUST_CLEAN", false), "Dont upload, just cleanup old versions")
) )
flag.Parse() flag.Parse()
if *directory == "" { if *directory == "" && *cleanup == 0 && *justClean == false {
log.Fatal("Directory path is required") log.Fatal("Directory path is required or cleanup must be enabled")
} }
ctx := context.Background() ctx := context.Background()
@@ -60,6 +61,7 @@ func main() {
log.Printf("Created object store: %s", *bucketName) log.Printf("Created object store: %s", *bucketName)
} }
if *directory != "" && *justClean == false {
err = filepath.Walk(*directory, func(path string, info os.FileInfo, err error) error { err = filepath.Walk(*directory, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
@@ -109,6 +111,7 @@ func main() {
} }
log.Printf("Successfully uploaded all files from %s to NATS object store '%s'", *directory, *bucketName) log.Printf("Successfully uploaded all files from %s to NATS object store '%s'", *directory, *bucketName)
}
if *cleanup > 0 { if *cleanup > 0 {
log.Printf("Cleaning up old versions, keeping %d most recent", *cleanup) log.Printf("Cleaning up old versions, keeping %d most recent", *cleanup)