Check Moodle Version and Tag #247
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Create Tag if New | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
LATEST_MOODLE_VERSION: ${{ env.LATEST_MOODLE_VERSION }} | |
GH_PAT: ${{ secrets.GH_PAT }} | |
run: | | |
# Get the highest version tag from the repo, using version sorting | |
CURRENT_VERSION=$(git tag | sort -V | tail -n 1) | |
echo "Latest MOODLE Version from API: $LATEST_MOODLE_VERSION" | |
echo "Current MOODLE version from Git tags: $CURRENT_VERSION" | |
# Compare versions | |
if [ "$(printf '%s\n' "$LATEST_MOODLE_VERSION" "$CURRENT_VERSION" | sort -V | head -n 1)" != "$LATEST_MOODLE_VERSION" ]; then | |
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"'"}' | |
else | |
echo "Latest version is already tagged." | |
fi |