From 9208e55701dfa9cdf80c54d1b68ffc0e4d27bce2 Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Wed, 11 Jan 2023 10:42:59 +0100 Subject: [PATCH] Inject release-notes branch from GitHub actions Signed-off-by: Sascha Grunert --- .github/workflows/test.yml | 5 +++++ scripts/release-notes/release_notes.go | 26 +++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 528e6d55177..cad3f76e83c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -354,6 +354,11 @@ jobs: ~/.cache/go-build key: go-build-${{ hashFiles('**/go.sum') }} restore-keys: go-build- + - name: Set current branch + run: | + raw=$(git branch -r --contains ${{ github.ref }}) + branch=${raw##*/} + echo "CURRENT_BRANCH=$branch" >> $GITHUB_ENV - run: make release-notes env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} diff --git a/scripts/release-notes/release_notes.go b/scripts/release-notes/release_notes.go index 6663124d656..65ce8f2f225 100644 --- a/scripts/release-notes/release_notes.go +++ b/scripts/release-notes/release_notes.go @@ -17,9 +17,10 @@ import ( ) const ( - branch = "gh-pages" - tokenKey = "GITHUB_TOKEN" - defaultBranch = "main" + branch = "gh-pages" + currentBranchKey = "CURRENT_BRANCH" + tokenKey = "GITHUB_TOKEN" + defaultBranch = "main" ) var outputPath string @@ -72,16 +73,15 @@ func run() error { } logrus.Infof("Using HEAD commit %s", head) - targetBranch := defaultBranch - currentBranch, err := repo.CurrentBranch() - if err != nil { - return fmt.Errorf("get current branch: %w", err) - } - logrus.Infof("Found current branch %s", currentBranch) - if git.IsReleaseBranch(currentBranch) && currentBranch != defaultBranch { - targetBranch = currentBranch + currentBranch, currentBranchSet := os.LookupEnv(currentBranchKey) + if !currentBranchSet || currentBranch == "" { + logrus.Infof( + "%s environment variable is not set, using default branch `%s`", + currentBranchKey, defaultBranch, + ) + currentBranch = defaultBranch } - logrus.Infof("Using target branch %s", targetBranch) + logrus.Infof("Using branch: %s", currentBranch) templateFile, err := os.CreateTemp("", "") if err != nil { @@ -186,7 +186,7 @@ To verify the bill of materials (SBOM) in [SPDX](https://spdx.org) format using "./build/bin/release-notes", "--org=cri-o", "--repo=cri-o", - "--branch="+targetBranch, + "--branch="+currentBranch, "--repo-path=/tmp/cri-o-repo", "--required-author=", "--start-rev="+startTag,