From ea5fca9fb186838b49481fe7f5156f6effc3aebf Mon Sep 17 00:00:00 2001 From: "Matthew \"strager\" Glazar" Date: Wed, 25 Oct 2023 22:03:00 -0400 Subject: [PATCH] fix(dist): don't accidentally include old files in release When releasing quick-lint-js version 2.17.0, I accidentally included some files from the 2.16.0 release. This is because I had stale builds and signed-builds folders from when I released 2.16.0. Update the release script to complain if an old builds or signed-builds folder is found. --- dist/release.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/dist/release.go b/dist/release.go index 81227eb83d..44edeb6449 100644 --- a/dist/release.go +++ b/dist/release.go @@ -165,6 +165,13 @@ var Steps []Step = []Step{ }, }, + Step{ + Title: "Check builds folder", + Run: func() { + EnsureEmptyDirectory("builds") + }, + }, + Step{ Title: "Download builds", Run: func() { @@ -177,6 +184,13 @@ var Steps []Step = []Step{ }, }, + Step{ + Title: "Check signed-builds folder", + Run: func() { + EnsureEmptyDirectory("signed-builds") + }, + }, + Step{ Title: "Sign the build artifacts", Run: func() { @@ -684,6 +698,28 @@ func UpdateDebianChangelog(changelogFilePath string, versionInfo VersionFileInfo return nil } +func EnsureEmptyDirectory(path string) { +Retry: + err := os.Mkdir(path, 0700) + if err == nil { + // A newly-created directory is empty. + return + } + if !os.IsExist(err) { + // Unknown error. Report it to the user. + Stopf("%v", err) + } + entries, readError := os.ReadDir(path) + directoryIsEmpty := readError == nil && len(entries) == 0 + if directoryIsEmpty { + return + } + + fmt.Printf("Error: A '%s' folder already exists. Delete it then type 'done'.\n", path) + WaitForDone() + goto Retry +} + func StringLines(s string) []string { return strings.Split(s, "\n") }