diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4e36b05fbc7..032a30370c0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -366,6 +366,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,