Skip to content

Create release

Create release #5

Workflow file for this run

name: Create release
on:
release:
types: [created]
jobs:
release:
runs-on: ubuntu-22.04
env:
PLUGIN_NAME: 'local_declarativesetup'
permissions:
contents: write
steps:
- name: Check out code
uses: actions/checkout@v4
- name: update release version.php
run: |
sed -i "s/^\$plugin->release\s=\s'[^']*';/\$plugin->release = '${{ github.ref_name }}';/" version.php # set release
cli/bump_version.py # set version
# set maturity to
# - default: MATURITY_STABLE
# - release is marked as pre-release on github, then MATURITY_BETA
# - release name contains 'rc', then MATURITY_RC
if [[ "${{ github.ref_name }}" == *"rc"* ]]; then
sed -i "s/^\$plugin->maturity\s=\sMATURITY_[A-Z]*;/\$plugin->maturity = MATURITY_RC;/" version.php
elif [[ "${{ github.event_name }}" == "release" && "${{ github.event.release.prerelease }}" == "true" ]]; then
sed -i "s/^\$plugin->maturity\s=\sMATURITY_[A-Z]*;/\$plugin->maturity = MATURITY_BETA;/" version.php
else
sed -i "s/^\$plugin->maturity\s=\sMATURITY_[A-Z]*;/\$plugin->maturity = MATURITY_STABLE;/" version.php
fi
- name: remove files not needed for release
run: |
rm -rf .github tests vendor .gitignore composer.json composer.lock phpunit.xml dev_utils phpunit.xml infection.json5
- name: Create release archive
run: |
FOLDER_NAME=$(echo ${{ env.PLUGIN_NAME }} | cut -d'_' -f2)
mkdir -p /tmp/$FOLDER_NAME
cp -r * /tmp/$FOLDER_NAME
cd /tmp
zip -r moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip $FOLDER_NAME
- name: Calculate MD5 hash
run: |
cd /tmp
md5sum /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip > /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip.md5
- name: Upload release archive (ZIP)
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip
tag: ${{ github.ref_name }}
- name: Upload MD5 hash files (ZIP)
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip.md5
tag: ${{ github.ref_name }}
- name: Upload to package registry
run: |
cd /tmp
awk '{print $1 " moodle-'${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip'"}' /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip.md5 > /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip.md5
curl --fail-with-body -u upload:${{ secrets.PACKAGE_REGISTRY_UPLOAD_PASSWORD }} -T /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip https://packages.projekt-adler.eu/upload/moodle/${{ env.PLUGIN_NAME }}/${{ github.ref_name }}.zip
curl --fail-with-body -u upload:${{ secrets.PACKAGE_REGISTRY_UPLOAD_PASSWORD }} -T /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip.md5 https://packages.projekt-adler.eu/upload/moodle/${{ env.PLUGIN_NAME }}/${{ github.ref_name }}.zip.md5