go-gluon-publisher/release.go
Stefan aaa1cb8ff3
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline failed
Added dryrun and folder check
2023-05-30 19:57:42 +02:00

42 lines
956 B
Go

package main
import (
"log"
"os"
)
func release_branch(branch string, source_dir string, target_dir string, dryrun bool) {
checkOldFolder, _ := os.ReadDir(source_dir)
checkNewFolder, _ := os.ReadDir(target_dir)
var newImages bool = false
if len(checkOldFolder) > 0 {
newImages = true
}
if newImages {
// delete old firmware files in public folder
for _, file := range checkNewFolder {
if !(dryrun) {
err := os.RemoveAll(target_dir + file.Name())
if err != nil {
log.Println("error deleting file: ", err)
} else {
log.Println("removed file: ", file.Name())
}
} else {
log.Println("DRYRUN: delete folder :", file.Name())
}
}
//move new files to folder
for _, file := range checkOldFolder {
if !(dryrun) {
os.Rename(source_dir+file.Name(), target_dir+file.Name())
log.Println("moved file: ", file.Name())
} else {
log.Println("DRYRUN: move folder: ", file.Name())
}
}
}
}