Skip to content

Commit

Permalink
feat: support new release process
Browse files Browse the repository at this point in the history
  • Loading branch information
pasha-codefresh committed Dec 6, 2023
1 parent 7e55146 commit da4f96e
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 7 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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-<major>.<minor>'
TARGET_BRANCH="release-${TARGET_VERSION%\.[0-9]*}"
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.8.1-cap-CR-create-apps-with-err
2.8-2023.12.06-7e551467f
8 changes: 8 additions & 0 deletions changelog/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
128 changes: 128 additions & 0 deletions hack/release/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
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-<version>.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
}
return moveChangelog()
}

0 comments on commit da4f96e

Please sign in to comment.