parse [vX.Y.Z] correctly from CHANGELOG.md

This commit is contained in:
Rich Megginson 2022-08-18 07:26:09 -06:00
parent b75ef4c630
commit 91b97deb1c

View file

@ -1,5 +1,5 @@
# yamllint disable rule:line-length # yamllint disable rule:line-length
name: Pushing CHANGELOG.md triggers tagging name: Pushing CHANGELOG.md triggers tag, release, and Galaxy publish
on: # yamllint disable-line rule:truthy on: # yamllint disable-line rule:truthy
push: push:
branches: branches:
@ -10,7 +10,7 @@ on: # yamllint disable-line rule:truthy
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
jobs: jobs:
tagging: tag_release_publish:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: checkout PR - name: checkout PR
@ -19,28 +19,46 @@ jobs:
id: tag id: tag
run: | run: |
set -euxo pipefail set -euxo pipefail
pat='\[v[0-9]*\.[0-9]*\.[0-9]*\] - [0-9\-]*'
print=false print=false
cat CHANGELOG.md | while read -r line; do while read -r line; do
if [[ "$line" =~ $pat ]] && [[ "$print" == false ]]; then if [[ "$line" =~ ^\[([0-9]+\.[0-9]+\.[0-9]+)\]\ -\ [0-9-]+ ]]; then
if [ "$print" = false ]; then
_tagname="${BASH_REMATCH[1]}"
echo "$line" echo "$line"
print=true print=true
elif [[ "$line" =~ $pat ]] && [[ "$print" == true ]]; then else
break break
elif [[ "$print" == true ]]; then fi
elif [ "$print" = true ]; then
echo "$line" echo "$line"
fi fi
done > ./.tagmsg.txt done < CHANGELOG.md > ./.tagmsg.txt
_tagname=$( grep -m 1 "[0-9]*\.[0-9]*\.[0-9]*" CHANGELOG.md | \
sed -e "s/^.*\[\([0-9]*\.[0-9]*\.[0-9]*\)\].*/\1/" )
git fetch --all --tags git fetch --all --tags
for t in $( git tag -l ); do for t in $( git tag -l ); do
if [[ $t == "$_tagname" ]]; then if [ "$t" = "$_tagname" ]; then
echo INFO: tag $t already exists echo INFO: tag "$t" already exists
exit 1 exit 1
fi fi
done done
# Get name of the branch that the change was pushed to
_branch="${GITHUB_REF_NAME:-}"
if [ "$_branch" = master ] || [ "$_branch" = main ]; then
echo Using branch name ["$_branch"] as push branch
else
echo WARNING: GITHUB_REF_NAME ["$_branch"] is not main or master
_branch=$( git branch -r | grep -o 'origin/HEAD -> origin/.*$' | \
awk -F'/' '{print $3}' || : )
fi
if [ -z "$_branch" ]; then
_branch=$( git branch --points-at HEAD --no-color --format='%(refname:short)' )
fi
if [ -z "$_branch" ]; then
echo ERROR: unable to determine push branch
git branch -a
exit 1
fi
echo ::set-output name=tagname::"$_tagname" echo ::set-output name=tagname::"$_tagname"
echo ::set-output name=branch::"$_branch"
- name: Create tag - name: Create tag
uses: mathieudutour/github-tag-action@v6.0 uses: mathieudutour/github-tag-action@v6.0
with: with:
@ -56,3 +74,8 @@ jobs:
body_path: ./.tagmsg.txt body_path: ./.tagmsg.txt
draft: false draft: false
prerelease: false prerelease: false
- name: Publish role to Galaxy
uses: robertdebock/galaxy-action@1.2.0
with:
galaxy_api_key: ${{ secrets.galaxy_api_key }}
git_branch: ${{ steps.tag.outputs.branch }}