From 3b5c06b1a7061bdd2b99a0b232a5dc8d3430eae9 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Wed, 6 Dec 2023 14:27:06 +0200 Subject: [PATCH] feat: support new release process --- .github/workflows/release.yaml | 6 - Makefile | 3 + .../CHANGELOG-2.8-2023.12.06-da4f96e57.md | 8 ++ hack/release/main.go | 132 ++++++++++++++++++ 4 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 changelog/CHANGELOG-2.8-2023.12.06-da4f96e57.md create mode 100644 hack/release/main.go diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e807edc0dcce6..a03b57f76031e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -58,12 +58,6 @@ jobs: # where X must be a number. TARGET_VERSION=${SOURCE_TAG#*release-v} - # Codefresh change: add to filter below a check for `-cf.*` postfix - if ! echo "${TARGET_VERSION}" | egrep '^[0-9]+\.[0-9]+\.[0-9]+((-rc[0-9]+)|(-cap-.*))*$'; then - echo "::error::Target version '${TARGET_VERSION}' is malformed, refusing to continue." >&2 - exit 1 - fi - # Target branch is the release branch we're going to operate on # Its name is 'release-.' TARGET_BRANCH="release-${TARGET_VERSION%\.[0-9]*}" diff --git a/Makefile b/Makefile index ef4945d094e9e..c6b6234055317 100644 --- a/Makefile +++ b/Makefile @@ -485,6 +485,9 @@ start-local: mod-vendor-local dep-ui-local cli-local run: bash ./hack/goreman-start.sh +.PHONY: cf-release +cf-release: + go run ./hack/release # Runs pre-commit validation with the virtualized toolchain .PHONY: pre-commit diff --git a/changelog/CHANGELOG-2.8-2023.12.06-da4f96e57.md b/changelog/CHANGELOG-2.8-2023.12.06-da4f96e57.md new file mode 100644 index 0000000000000..cca8c982f1be8 --- /dev/null +++ b/changelog/CHANGELOG-2.8-2023.12.06-da4f96e57.md @@ -0,0 +1,8 @@ +### Bug fixes +- feat: support application level extensions (#9923) +- feat: support multiple extensions per resource group/kind (#9834) +- fix: extensions is not loading for ConfigMap/Pods (#10010) +- fix: upgrade moment from 2.29.2 to 2.29.3 (#9330) +### Other changes +- chore: update parse-url (#10101) +- docs: add api field example in the appset security doc (#10087) \ No newline at end of file diff --git a/hack/release/main.go b/hack/release/main.go new file mode 100644 index 0000000000000..6be93babd5fa7 --- /dev/null +++ b/hack/release/main.go @@ -0,0 +1,132 @@ +package main + +import ( + "fmt" + "os" + "os/exec" + "regexp" + "strings" + "time" +) + +func main() { + err := release() + if err != nil { + fmt.Printf("Failed to release: %s\n", err.Error()) + } +} + +func getCurrentCommitSha() (string, error) { + // git rev-parse --short HEAD + cmd := exec.Command("git", "rev-parse", "--short", "HEAD") + result, err := cmd.Output() + if err != nil { + return "", err + } + rs := strings.Split(string(result), "\n") + return strings.Split(rs[0], " ")[0], nil +} + +func getArgoCDVersion() (string, error) { + // git rev-parse --abbrev-ref HEAD + cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD") + result, err := cmd.Output() + if err != nil { + return "", err + } + pattern := `release-(\d+\.\d+)` + re := regexp.MustCompile(pattern) + matches := re.FindStringSubmatch(string(result)) + if len(matches) >= 2 { + return matches[1], nil + } + return "", fmt.Errorf("failed to get argocd version") +} + +// function that returns version of the latest release by patern +// {argocd-version}-{timestamp}-{commit-sha} +func getLatestVersion() (string, error) { + commitSha, err := getCurrentCommitSha() + if err != nil { + return "", err + } + argocdVersion, err := getArgoCDVersion() + if err != nil { + return "", err + } + return fmt.Sprintf("%s-%s-%s", argocdVersion, time.Now().Format("2006.01.02"), commitSha), nil +} + +func updateVersion(version string) error { + file, err := os.OpenFile("VERSION", os.O_WRONLY|os.O_TRUNC, 0644) + if err != nil { + return err + } + defer file.Close() + + // Write the new content to the file + _, err = file.WriteString(version) + if err != nil { + return err + } + + return nil +} + +func readChangelog() (string, error) { + data, err := os.ReadFile("changelog/CHANGELOG.md") + if err != nil { + return "", err + } + return string(data), nil +} + +func moveChangelog() error { + version, err := getLatestVersion() + if err != nil { + return err + } + // mv changelog/CHANGELOG.md changelog/CHANGELOG-.md + cmd := exec.Command("mv", "changelog/CHANGELOG.md", fmt.Sprintf("changelog/CHANGELOG-%s.md", version)) + if err := cmd.Run(); err != nil { + return err + } + return nil +} + +func release() error { + version, err := getLatestVersion() + if err != nil { + return err + } + fmt.Printf("Releasing version: %s\n", version) + err = updateVersion(version) + if err != nil { + return err + } + changelog, err := readChangelog() + if err != nil { + return err + } + fmt.Printf("Changelog: %s\n", changelog) + release := fmt.Sprintf("release-v%s", version) + fmt.Printf("Release: %s\n", release) + // git tag -a v2.9.3-2021.07.07-3a4b7f4 -m "Codefresh version for synced 2.9.3" + _ = exec.Command("git", "tag", "-d", release).Run() + cmd := exec.Command("git", "tag", "-a", release, "-m", changelog) + if err := cmd.Run(); err != nil { + return err + } + // git push remote-name --delete tag-name + _ = exec.Command("git", "push", "origin", "--delete", release).Run() + // git push origin tags/version + cmd = exec.Command("git", "push", "origin", "tags/"+release) + if err := cmd.Run(); err != nil { + return err + } + err = moveChangelog() + if err != nil { + return err + } + return exec.Command("git", "push", "origin", "--delete", release).Run() +}