Skip to content

Release

Release #11

Workflow file for this run

name: Release
# example: gh workflow run release.yml -f tag_name=v1.1.4 -f draft=true
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
env:
# Allow ddev get to use a GitHub token to prevent rate limiting by tests
DDEV_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
create-release:
name: Create release
runs-on: ubuntu-latest
permissions:
contents: write
env:
EXTENSION_ZIP_NAME: "crowdsec-magento2-module-bouncer"
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,})(-(alpha|beta)\.[0-9]{1,})?$")
if [ ! ${VERIF} ]
then
echo "Tag name '${{ github.event.inputs.tag_name }}' does not comply with naming convention vX.Y.Z (vX.Y.Z-alpha.W or vX.Y.Z-beta.W)"
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@v3
with:
path: ${{ env.VERSION_SOURCES }}
- name: Check version ${{ env.VERSION_NUMBER }} consistency in files
# Check composer.json, Constants.php 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
CONSTANT_VERSION=$(grep -E "public const VERSION = 'v(.*)';" Constants.php | sed 's/ //g')
if [[ $CONSTANT_VERSION == "publicconstVERSION='v${{ env.VERSION_NUMBER }}';" ]]
then
echo "CONSTANT VERSION OK"
else
echo "CONSTANT 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@v3
with:
repository: julienloizelet/m2-extension-zip-validator
path: zip-validator
- name: Validate zip ${{ env.VERSION_SOURCES }}.zip
run: |
chmod +x zip-validator/validate_m2_package.php
php zip-validator/validate_m2_package.php ${{ env.VERSION_SOURCES }}.zip
- name: Create Tag ${{ github.event.inputs.tag_name }}
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 }}
after-release:
strategy:
fail-fast: false
matrix:
# Last 2 patches for the current minor, and last patch for the previous minor, greatest php version
include:
- m2-version: '2.3.7'
php-version: '7.4'
- m2-version: '2.4.5'
php-version: '8.1'
- m2-version: '2.4.6'
php-version: '8.2'
name: After release test suite
if: success()
needs: [ create-release ]
runs-on: ubuntu-latest
env:
EXTENSION_PACKAGE_NAME: "crowdsec/magento2-module-bouncer"
EXTENSION_NAME: "CrowdSec_Bouncer"
EXTENSION_PATH: "crowdsec-bouncer"
steps:
- name: Install Magento 2 with DDEV
uses: julienloizelet/[email protected]
with:
php_version: ${{ matrix.php-version }}
magento_version: ${{ matrix.m2-version }}
composer_auth: ${{ secrets.M2_COMPOSER_AUTH }}
magento_repository: "https://repo.magento.com/"
- name: Add Redis and Memcached
run: |
ddev get ddev/ddev-redis
ddev get ddev/ddev-memcached
# override redis.conf
ddev get julienloizelet/ddev-tools
- name: Playwright
run: ddev get julienloizelet/ddev-playwright
- name: Clone M2 ${{ env.EXTENSION_NAME }} files
uses: actions/checkout@v3
with:
path: module-sources
- name: Retrieve last stable release zip
run: |
LAST_TAG=$(curl -Ls -o /dev/null -w %{url_effective} $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/latest | grep -oP "\/tag\/v\K(.*)$")
curl -fL $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/download/v$LAST_TAG/crowdsec-magento2-module-bouncer-$LAST_TAG.zip -o crowdsec.$LAST_TAG.zip
mkdir release-sources
unzip crowdsec.$LAST_TAG.zip -d release-sources
mkdir -p ${{ github.workspace }}/my-own-modules/${{ env.EXTENSION_PATH }}
cd release-sources/crowdsec-magento2-module-bouncer-$LAST_TAG
cp -r . ${{ github.workspace }}/my-own-modules/${{ env.EXTENSION_PATH }}
ls -al ${{ github.workspace }}/my-own-modules/${{ env.EXTENSION_PATH }}
- name: Validate composer.json
run: ddev composer validate --working-dir ./my-own-modules/${{ env.EXTENSION_PATH }}
- name: Prepare composer repositories
run: |
ddev composer config --unset repositories.0
ddev composer config repositories.0 '{"type": "path", "url":"my-own-modules/${{ env.EXTENSION_PATH }}/", "canonical": true}'
ddev composer config repositories.1 '{"type": "composer", "url":"https://repo.magento.com/", "exclude": ["${{ env.EXTENSION_PACKAGE_NAME }}", "magento/composer-dependency-version-audit-plugin"]}'
- name: Add ${{ env.EXTENSION_NAME }} as composer dependency
run: |
ddev composer require ${{ env.EXTENSION_PACKAGE_NAME }}:@dev --no-interaction
- name: Disable some extensions for 2.4.6
if: startsWith(matrix.m2-version, '2.4.6')
run: |
ddev magento module:disable Magento_AdminAdobeImsTwoFactorAuth
- name: Disable some extensions for 2.4
if: startsWith(matrix.m2-version, '2.4')
run: |
ddev magento module:disable Magento_TwoFactorAuth
ddev magento module:disable Magento_AdminNotification
- name: Make some workaround for 2.3.5
if: startsWith(matrix.m2-version, '2.3.5')
run: |
ddev magento module:disable Dotdigitalgroup_Chat
ddev magento module:disable Dotdigitalgroup_Email
- name: Enable extension
run: |
ddev magento deploy:mode:set developer
ddev magento module:enable ${{ env.EXTENSION_NAME }}
ddev magento setup:upgrade
ddev magento setup:static-content:deploy -f
ddev magento cache:flush
ddev get julienloizelet/ddev-crowdsec-php
ddev restart
- name: Prepare for playwright test
run: |
cp .ddev/okaeli-add-on/magento2/custom_files/varnish-profile.xml varnish-profile.xml
ddev magento setup:performance:generate-fixtures ./varnish-profile.xml
ddev magento cache:flush
mkdir -p var/crowdsec/tls
cp -r .ddev/okaeli-add-on/custom_files/crowdsec/cfssl/* var/crowdsec/tls
ddev maxmind-download DEFAULT GeoLite2-City /var/www/html/var/crowdsec
ddev maxmind-download DEFAULT GeoLite2-Country /var/www/html/var/crowdsec
cd var/crowdsec
sha256sum -c GeoLite2-Country.tar.gz.sha256.txt
sha256sum -c GeoLite2-City.tar.gz.sha256.txt
tar -xf GeoLite2-Country.tar.gz
tar -xf GeoLite2-City.tar.gz
rm GeoLite2-Country.tar.gz GeoLite2-Country.tar.gz.sha256.txt GeoLite2-City.tar.gz GeoLite2-City.tar.gz.sha256.txt
cd ${{ github.workspace }}
cp .ddev/okaeli-add-on/magento2/custom_scripts/cronLaunch.php ${{ github.workspace }}/pub/cronLaunch.php
cp .ddev/okaeli-add-on/magento2/custom_scripts/crowdsec/cacheActions.php ${{ github.workspace }}/pub/cacheActions.php
cd ${{ github.workspace }}/my-own-modules/${{ env.EXTENSION_PATH }}/Test/EndToEnd/__scripts__
chmod +x test-init.sh
./test-init.sh
chmod +x run-tests.sh
cd ${{ github.workspace }}/module-sources
cp -r .github ${{ github.workspace }}/my-own-modules/${{ env.EXTENSION_PATH }}
ls -al ${{ github.workspace }}/my-own-modules/${{ env.EXTENSION_PATH }}
- name: Run config test
uses: ./my-own-modules/crowdsec-bouncer/.github/workflows/end-to-end/run-single-test
with:
test_path: ${{ github.workspace }}/my-own-modules/${{ env.EXTENSION_PATH }}/Test/EndToEnd
file_path: 1-config.js
- name: Run live mode test
uses: ./my-own-modules/crowdsec-bouncer/.github/workflows/end-to-end/run-single-test
with:
test_path: ${{ github.workspace }}/my-own-modules/${{ env.EXTENSION_PATH }}/Test/EndToEnd
file_path: 2-live-mode.js
- name: Run stream mode test
uses: ./my-own-modules/crowdsec-bouncer/.github/workflows/end-to-end/run-single-test
with:
test_path: ${{ github.workspace }}/my-own-modules/${{ env.EXTENSION_PATH }}/Test/EndToEnd
file_path: 3-stream-mode.js
- name: Run cron test
uses: ./my-own-modules/crowdsec-bouncer/.github/workflows/end-to-end/run-single-test
with:
test_path: ${{ github.workspace }}/my-own-modules/${{ env.EXTENSION_PATH }}/Test/EndToEnd
file_path: 4-cron.js
- name: Run api tests
uses: ./my-own-modules/crowdsec-bouncer/.github/workflows/end-to-end/run-single-test
with:
test_path: ${{ github.workspace }}/my-own-modules/${{ env.EXTENSION_PATH }}/Test/EndToEnd
file_path: 5-api.js
- name: Run geolocation test
uses: ./my-own-modules/crowdsec-bouncer/.github/workflows/end-to-end/run-single-test
with:
test_path: ${{ github.workspace }}/my-own-modules/${{ env.EXTENSION_PATH }}/Test/EndToEnd
file_path: 7-geolocation.js
- name: Debug with tmate
uses: mxschmitt/action-tmate@v3
with:
limit-access-to-actor: true
github-token: ${{ secrets.GITHUB_TOKEN }}
timeout-minutes: 30
if: failure()