Skip to content

Releasing in the Plugins directory #5

Releasing in the Plugins directory

Releasing in the Plugins directory #5

#
# Whenever a new tag starting with "v" is pushed, create a new GitHub release,
# and add the tagged version to the Moodle Plugins directory at https://moodle.org/plugins.
#
# Sources:
# * https://github.com/moodlehq/moodle-plugin-release
# * https://github.com/softprops/action-gh-release
#
name: Releasing in the Plugins directory
on:
# Trigger the release when the CI build for a tag was completed successfully.
workflow_run:
workflows:
- Moodle Plugin CI
branches:
- main
types:
- completed
workflow_dispatch:
inputs:
tag:
description: 'Tag to be released'
required: true
defaults:
run:
shell: bash
jobs:
release:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.workflow_dispatch.inputs.tag }}
env:
PLUGIN: mod_kialo
CURL: curl -s
ENDPOINT: https://moodle.org/webservice/rest/server.php
TOKEN: ${{ secrets.MOODLE_ORG_TOKEN }} # see https://moodle.org/user/managetoken.php
FUNCTION: local_plugins_add_version
permissions:
contents: write
steps:
- name: Check out repository code
uses: actions/checkout@v3
with:
path: plugin
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
# Creates plugin/development/mod_kialo.zip with the current version
- name: Create bundle
run: |
cd plugin/development
./bundle.sh
# Create a new release on GitHub
- name: Release to GitHub
id: github-release
uses: softprops/action-gh-release@v1
with:
files: |
plugin/development/mod_kialo.zip
generate_release_notes: true
# Uploads the release to Moodle using its Plugin Directory API
- name: Call the service function
id: add-version
run: |
if [[ ! -z "${{ github.event.inputs.tag }}" ]]; then
TAGNAME="${{ github.event.inputs.tag }}"
elif [[ $GITHUB_REF = refs/tags/* ]]; then
TAGNAME="${GITHUB_REF##*/}"
fi
if [[ -z "${TAGNAME}" ]]; then
echo "No tag name has been provided!"
exit 1
fi
ZIPURL="${{ fromJSON(steps.github-release.outputs.assets)[0].browser_download_url }}"
RESPONSE=$(${CURL} ${ENDPOINT} --data-urlencode "wstoken=${TOKEN}" \
--data-urlencode "wsfunction=${FUNCTION}" \
--data-urlencode "moodlewsrestformat=json" \
--data-urlencode "frankenstyle=${PLUGIN}" \
--data-urlencode "zipurl=${ZIPURL}" \
--data-urlencode "vcssystem=git" \
--data-urlencode "vcsrepositoryurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" \
--data-urlencode "vcstag=${TAGNAME}" \
--data-urlencode "changelogurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commits/${TAGNAME}" \
--data-urlencode "altdownloadurl=${ZIPURL}")
echo "response=${RESPONSE}" >> $GITHUB_OUTPUT
- name: Evaluate the response
id: evaluate-response
env:
RESPONSE: ${{ steps.add-version.outputs.response }}
run: |
jq <<< ${RESPONSE}
jq --exit-status ".id" <<< ${RESPONSE} > /dev/null