Merge pull request #285 from richm/cl-20240405 #16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# yamllint disable rule:line-length | |
name: Pushing CHANGELOG.md triggers tag, release, and Galaxy publish | |
on: # yamllint disable-line rule:truthy | |
push: | |
branches: | |
- main | |
- master | |
paths: | |
- CHANGELOG.md | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | |
jobs: | |
tag_release_publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout PR | |
uses: actions/checkout@v4 | |
- name: Get tag and message from the latest CHANGELOG.md commit | |
id: tag | |
run: | | |
set -euxo pipefail | |
print=false | |
while read -r line; do | |
if [[ "$line" =~ ^\[(v[0-9]+\.[0-9]+\.[0-9]+)\]\ -\ [0-9-]+ ]]; then | |
if [ "$print" = false ]; then | |
_tagname="${BASH_REMATCH[1]}" | |
echo "$line" | |
print=true | |
else | |
break | |
fi | |
elif [ "$print" = true ]; then | |
echo "$line" | |
fi | |
done < CHANGELOG.md > ./.tagmsg.txt | |
git fetch --all --tags | |
for t in $( git tag -l ); do | |
if [ "$t" = "$_tagname" ]; then | |
echo INFO: tag "$t" already exists | |
exit 1 | |
fi | |
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=branch::"$_branch" | |
- name: Create tag | |
uses: mathieudutour/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
custom_tag: ${{ steps.tag.outputs.tagname }} | |
tag_prefix: '' | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
with: | |
tag_name: ${{ steps.tag.outputs.tagname }} | |
release_name: Version ${{ steps.tag.outputs.tagname }} | |
body_path: ./.tagmsg.txt | |
draft: false | |
prerelease: false |