Skip to content

Create Release

Create Release #14

Workflow file for this run

name: Create Release
# example: gh workflow run release.yml -f tag_name=v1.1.4
on:
workflow_dispatch:
branches:
- main
inputs:
tag_name:
type: string
required: true
jobs:
prepare-release:
name: Prepare release
runs-on: ubuntu-latest
permissions:
contents: write
env:
TAG_NAME: ${{ github.event.inputs.tag_name }}
steps:
- name: Check naming convention
run: |
VERIF=$(echo ${{ env.TAG_NAME }} | grep -E "^v([0-9]{1,}\.)([0-9]{1,}\.)([0-9]{1,})(-(alpha|beta)\.[0-9]{1,})?$")
if [ ! ${VERIF} ]
then
echo "Tag name '${{ env.TAG_NAME }}' does not comply with naming convention vX.Y.Z"
exit 1
fi
- name: Set version number without v
id: set-version-number
run: |
echo "version_number=$(echo ${{ env.TAG_NAME }} | sed 's/v//g' )" >> $GITHUB_OUTPUT
- name: Clone sources
uses: actions/checkout@v4
- name: Check version consistency in files
# Check src/Constants.php and CHANGELOG.md
run: |
# Check public const VERSION = 'vVERSION_NUMBER'; in src/Constants.php
CONSTANT_VERSION=$(grep -E "public const VERSION = 'v(.*)';" src/Constants.php | sed 's/ //g')
if [[ $CONSTANT_VERSION == "publicconstVERSION='${{ env.TAG_NAME }}';" ]]
then
echo "CONSTANT VERSION OK"
else
echo "CONSTANT VERSION KO"
exit 1
fi
# Check top ## [VERSION_NUMBER](GITHUB_URL/releases/tag/vVERSION_NUMBER) - yyyy-mm-dd in CHANGELOG.md
CURRENT_DATE=$(date +'%Y-%m-%d')
echo $CURRENT_DATE
CHANGELOG_VERSION=$(grep -o -E "## \[(.*)\].* - $CURRENT_DATE" CHANGELOG.md | head -1 | sed 's/ //g')
echo $CHANGELOG_VERSION
if [[ $CHANGELOG_VERSION == "##[${{ steps.set-version-number.outputs.version_number }}]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/${{ env.TAG_NAME }})-$CURRENT_DATE" ]]
then
echo "CHANGELOG VERSION OK"
else
echo "CHANGELOG VERSION KO"
exit 1
fi
# Check top [_Compare with previous release_](GITHUB_URL/compare/vLAST_TAG...vVERSION_NUMBER) in CHANGELOG.md
COMPARISON=$(grep -oP "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/compare/\K(.*)$" CHANGELOG.md | head -1)
LAST_TAG=$(curl -Ls -o /dev/null -w %{url_effective} $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/latest | grep -oP "\/tag\/\K(.*)$")
if [[ $COMPARISON == "$LAST_TAG...${{ env.TAG_NAME }})" ]]
then
echo "VERSION COMPARISON OK"
else
echo "VERSION COMPARISON KO"
echo $COMPARISON
echo "$LAST_TAG...${{ env.TAG_NAME }})"
exit 1
fi
- name: Create Tag
uses: actions/github-script@v7
with:
github-token: ${{ github.token }}
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/${{ env.TAG_NAME }}",
sha: context.sha
})
- name: Prepare release notes
run: |
# Retrieve release body and remove ---
VERSION_RELEASE_NOTES=$(awk -v ver="[${{ steps.set-version-number.outputs.version_number }}]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/${{ env.TAG_NAME }})" '/^## / { if (p) { exit }; if ($2 == ver) { p=1; next} } p && NF' CHANGELOG.md | sed ':a;N;$!ba;s/\n---/ /g')
echo "$VERSION_RELEASE_NOTES" >> CHANGELOG.txt
- name: Create release
uses: softprops/action-gh-release@v2
with:
body_path: CHANGELOG.txt
name: ${{ steps.set-version-number.outputs.version_number }}
tag_name: ${{ env.TAG_NAME }}