Skip to content

Deploy and Create Release #49

Deploy and Create Release

Deploy and Create Release #49

Workflow file for this run

name: Deploy and Create Release
# example: gh workflow run release.yml -f tag_name=v1.1.4 -f deploy_to_wordpress=true
on:
workflow_dispatch:
inputs:
tag_name:
type: string
required: true
deploy_to_wordpress:
type: boolean
description: Deploy to WordPress
default: true
required: true
permissions:
contents: write
env:
# Allow ddev get to use a GitHub token to prevent rate limiting by tests
DDEV_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ github.event.inputs.tag_name }}
jobs:
deploy-create-release:
name: Deploy and create release
runs-on: ubuntu-latest
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 ${{ github.event.inputs.tag_name }} | sed 's/v//g' )" >> $GITHUB_OUTPUT
- name: Clone sources
uses: actions/checkout@v4
- name: Check version consistency in files
# Check crowdsec.php (2), readme.txt (1), inc/Constants.php (1) and CHANGELOG.md (3)
run: |
CURRENT_DATE=$(date +'%Y-%m-%d')
CHANGELOG_VERSION=$(grep -o -E "## \[(.*)\].* - $CURRENT_DATE" CHANGELOG.md | head -1 | sed 's/ //g')
echo $CURRENT_DATE
echo $CHANGELOG_VERSION
echo "##[${{ steps.set-version-number.outputs.version_number }}]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/${{ env.TAG_NAME }})-$CURRENT_DATE"
if [[ $CHANGELOG_VERSION == "##[${{ steps.set-version-number.outputs.version_number }}]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/${{ env.TAG_NAME }})-$CURRENT_DATE" ]]
then
echo "Version in CHANGELOG.md: OK"
else
echo "Version in CHANGELOG.md: KO"
exit 1
fi
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
VERSION=$(grep -E "Version: (.*)" crowdsec.php | sed 's/ //g')
echo $VERSION
echo "*Version:${{ steps.set-version-number.outputs.version_number }}"
if [[ $VERSION == "*Version:${{ steps.set-version-number.outputs.version_number}}" ]]
then
echo "Version in crowdsec.php: OK"
else
echo "Version in crowdsec.php: KO"
exit 1
fi
CROWDSEC_STABLE=$(grep -E "Stable tag: (.*)" crowdsec.php | sed 's/ //g')
echo $CROWDSEC_STABLE
echo "*Stabletag:${{ steps.set-version-number.outputs.version_number }}"
if [[ $CROWDSEC_STABLE == "*Stabletag:${{ steps.set-version-number.outputs.version_number }}" ]]
then
echo "Stable tag in crowdsec.php: OK"
else
echo "Stable tag in crowdsec.php: KO"
exit 1
fi
README_STABLE=$(grep -E "Stable tag: (.*)" readme.txt | sed 's/ //g')
echo $README_STABLE
echo "Stabletag:${{ steps.set-version-number.outputs.version_number }}"
if [[ $README_STABLE == "Stabletag:${{ steps.set-version-number.outputs.version_number }}" ]]
then
echo "Stable tag in readme.txt: OK"
else
echo "Stable tag in readme.txt: KO"
exit 1
fi
CONSTANT_VERSION=$(grep -E "VERSION = 'v(.*)" inc/Constants.php | sed 's/[\x27(),/ ]//g')
echo $CONSTANT_VERSION
echo "publicconstVERSION=${{ env.TAG_NAME }};"
if [[ $CONSTANT_VERSION == "publicconstVERSION=${{ env.TAG_NAME }};" ]]
then
echo "Version in inc/Constants.php: OK"
else
echo "Version in inc/Constants.php: KO"
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: WordPress Plugin Deploy
if: github.event.inputs.deploy_to_wordpress == 'true'
id: deploy
uses: 10up/[email protected]
with:
generate-zip: true
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SLUG: crowdsec
VERSION: ${{ steps.set-version-number.outputs.version_number }}
- name: Prepare release notes
run: |
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
cat CHANGELOG.txt
- name: Create release with Wordpress zip
if: github.event.inputs.deploy_to_wordpress == 'true'
uses: softprops/action-gh-release@v2
with:
files: crowdsec.zip
body_path: CHANGELOG.txt
name: ${{ steps.set-version-number.outputs.version_number }}
tag_name: ${{ env.TAG_NAME }}
draft: false
prerelease: false
- name: Create release without Wordpress zip
if: github.event.inputs.deploy_to_wordpress != 'true'
uses: softprops/action-gh-release@v2
with:
body_path: CHANGELOG.txt
name: ${{ steps.set-version-number.outputs.version_number }}
tag_name: ${{ env.TAG_NAME }}
draft: false
prerelease: false