Create Release #10
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
name: Create Release | |
# example: gh workflow run release.yml -f tag_name=v1.1.4 -f draft=false | |
on: | |
workflow_dispatch: | |
inputs: | |
tag_name: | |
type: string | |
required: true | |
draft: | |
type: boolean | |
description: Draft release | |
default: false | |
prerelease: | |
type: boolean | |
description: Prerelease | |
default: false | |
jobs: | |
create-release: | |
name: Create release | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
env: | |
EXTENSION_ZIP_NAME: "okaeli-magento2-category-code" | |
steps: | |
- name: Check naming convention | |
run: | | |
VERIF=$(echo ${{ github.event.inputs.tag_name }} | grep -E "^v([0-9]{1,}\.)([0-9]{1,}\.)([0-9]{1,})$") | |
if [ ! ${VERIF} ] | |
then | |
echo "Tag name '${{ github.event.inputs.tag_name }}' does not comply with naming convention vX.Y.Z" | |
exit 1 | |
fi | |
- name: Set version number without v | |
run: | | |
echo "VERSION_NUMBER=$(echo ${{ github.event.inputs.tag_name }} | sed 's/v//g' )" >> $GITHUB_ENV | |
- name: Set version sources | |
run: | | |
echo "VERSION_SOURCES=$(echo ${{ env.EXTENSION_ZIP_NAME }}-${{ env.VERSION_NUMBER }} )" >> $GITHUB_ENV | |
- name: Clone sources | |
uses: actions/checkout@v4 | |
with: | |
path: ${{ env.VERSION_SOURCES }} | |
- name: Check version ${{ env.VERSION_NUMBER }} consistency in files | |
# Check composer.json and CHANGELOG.md | |
run: | | |
cd ${{ env.VERSION_SOURCES }} | |
COMPOSER_VERSION=$(grep -E '\"version\": \"(.*)\",' composer.json | sed 's/ //g') | |
if [[ $COMPOSER_VERSION == "\"version\":\"${{ env.VERSION_NUMBER }}\"," ]] | |
then | |
echo "COMPOSER VERSION OK" | |
else | |
echo "COMPOSER VERSION KO" | |
exit 1 | |
fi | |
CURRENT_DATE=$(date +'%Y-%m-%d') | |
CHANGELOG_VERSION=$(grep -o -E "## \[(.*)\].* - $CURRENT_DATE" CHANGELOG.md | head -1 | sed 's/ //g') | |
if [[ $CHANGELOG_VERSION == "##[${{ env.VERSION_NUMBER }}]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/v${{ env.VERSION_NUMBER }})-$CURRENT_DATE" ]] | |
then | |
echo "CHANGELOG VERSION OK" | |
else | |
echo "CHANGELOG VERSION KO" | |
exit 1 | |
fi | |
COMPARISON=$(grep -oP "\/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...v${{ env.VERSION_NUMBER }})" ]] | |
then | |
echo "VERSION COMPARISON OK" | |
else | |
echo "VERSION COMPARISON KO" | |
echo $COMPARISON | |
echo "$LAST_TAG...v${{ env.VERSION_NUMBER }})" | |
exit 1 | |
fi | |
- name: Create zip | |
run: | | |
zip -r ${{ env.VERSION_SOURCES }}.zip ${{ env.VERSION_SOURCES }}/ -x '${{ env.VERSION_SOURCES }}/.git*' | |
- name: Clone zip validator | |
uses: actions/checkout@v4 | |
with: | |
repository: julienloizelet/m2-extension-zip-validator | |
path: zip-validator | |
- name: Validate zip | |
run: | | |
chmod +x zip-validator/validate_m2_package.php | |
php zip-validator/validate_m2_package.php ${{ env.VERSION_SOURCES }}.zip | |
- name: Create Tag | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ github.token }} | |
script: | | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: "refs/tags/${{ github.event.inputs.tag_name }}", | |
sha: context.sha | |
}) | |
- name: Prepare release notes | |
run: | | |
VERSION_RELEASE_NOTES=$(awk -v ver="[${{ env.VERSION_NUMBER }}]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/v${{ env.VERSION_NUMBER }})" '/^## / { if (p) { exit }; if ($2 == ver) { p=1; next} } p && NF' ${{ env.VERSION_SOURCES }}/CHANGELOG.md | sed ':a;N;$!ba;s/\n---/ /g') | |
echo "$VERSION_RELEASE_NOTES" >> CHANGELOG.txt | |
- name: Create release ${{ env.VERSION_NUMBER }} | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: ${{ env.VERSION_SOURCES }}.zip | |
body_path: CHANGELOG.txt | |
name: ${{ env.VERSION_NUMBER }} | |
tag_name: ${{ github.event.inputs.tag_name }} | |
draft: ${{ github.event.inputs.draft }} | |
prerelease: ${{ github.event.inputs.prerelease }} |