Skip to content

Check Moodle Version and Tag #302

Check Moodle Version and Tag

Check Moodle Version and Tag #302

name: Check Moodle Version and Tag
on:
schedule:
- cron: '0 0 * * *' # Run this task daily
workflow_dispatch: # Allows manually triggering
jobs:
check-version-and-tag:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check Moodle Latest Version
id: check_moodle
run: |
LATEST_MOODLE_VERSION=$(curl -s https://api.github.com/repos/moodle/moodle/tags | jq -r '.[0].name')
echo "LATEST_MOODLE_VERSION=$LATEST_MOODLE_VERSION" >> $GITHUB_ENV
- name: Get Current Version from Git Tags
id: get_current_version
run: |
# Get the latest stable tag (no pre-release)
CURRENT_VERSION=$(git tag | grep -vE '(-rc|-beta|-alpha)' | sort -V | tail -n 1)
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
- name: Compare Versions
id: version_compare
uses: madhead/semver-utils@latest
with:
version: '${{ env.LATEST_MOODLE_VERSION }}'
compare-to: '${{ env.CURRENT_VERSION }}'
- name: Create Tag if New
if: steps.version_compare.outputs.comparison-result == '>'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LATEST_MOODLE_VERSION: ${{ env.LATEST_MOODLE_VERSION }}
GH_PAT: ${{ secrets.GH_PAT }}
run: |
echo "Creating new tag for $LATEST_MOODLE_VERSION"
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git tag $LATEST_MOODLE_VERSION
git push origin $LATEST_MOODLE_VERSION
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $GH_PAT" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/build.yml/dispatches \
-d '{"ref":"refs/tags/'"$LATEST_MOODLE_VERSION"'"}'
- name: No New Version
if: steps.version_compare.outputs.comparison-result != '>'
run: echo "Latest version is already tagged or is older."