Skip to content

Commit f042a6a

Browse files
authored
Use GITHUB_REF_NAME if main or master [citest skip] (#294)
Use GITHUB_REF_NAME for the push branch name if main or master, otherwise use other methods. Fix a bug with using git branch -r to ignore errors if branch did not match pattern.
1 parent b2177a6 commit f042a6a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

.github/workflows/changelog_to_tag.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
id: tag
2020
run: |
2121
set -euxo pipefail
22-
echo GITHUB_REF = "${GITHUB_REF:-none}"
23-
echo GITHUB_REF_NAME = "${GITHUB_REF_NAME:-none}"
2422
print=false
2523
while read -r line; do
2624
if [[ "$line" =~ ^\[([0-9]+\.[0-9]+\.[0-9]+)\]\ -\ [0-9-]+ ]]; then
@@ -42,14 +40,20 @@ jobs:
4240
exit 1
4341
fi
4442
done
45-
# Get the main branch name
46-
_branch=$( git branch -r | grep -o 'origin/HEAD -> origin/.*$' | \
47-
awk -F'/' '{print $3}' )
43+
# Get name of the branch that the change was pushed to
44+
_branch="${GITHUB_REF_NAME:-}"
45+
if [ "$_branch" = master ] || [ "$_branch" = main ]; then
46+
echo Using branch name ["$_branch"] as push branch
47+
else
48+
echo WARNING: GITHUB_REF_NAME ["$_branch"] is not main or master
49+
_branch=$( git branch -r | grep -o 'origin/HEAD -> origin/.*$' | \
50+
awk -F'/' '{print $3}' || : )
51+
fi
4852
if [ -z "$_branch" ]; then
4953
_branch=$( git branch --points-at HEAD --no-color --format='%(refname:short)' )
5054
fi
5155
if [ -z "$_branch" ]; then
52-
echo ERROR: unable to determine main branch
56+
echo ERROR: unable to determine push branch
5357
git branch -a
5458
exit 1
5559
fi

0 commit comments

Comments
 (0)