Skip to content

Commit

Permalink
Update check-moodle-version.yml
Browse files Browse the repository at this point in the history
Fix version comparison to handle pre-release versions correctly

This commit fixes issue #64 by updating the GitHub Actions workflow to correctly compare versions according to Semantic Versioning (SemVer) rules. Previously, the workflow used `sort -V` for version comparison, which did not properly handle pre-release identifiers like `-rc2`. As a result, it failed to recognize that a final release (e.g., `v4.5.0`) is greater than its pre-release versions (e.g., `v4.5.0-rc2`).

The fix involves integrating the `madhead/semver-utils` GitHub Action to accurately compare versions, ensuring that the workflow triggers the build and tagging process when a new final version is released.

Thank you to @jimsihk for reporting this issue and helping us improve our workflow!

Closes #64
  • Loading branch information
erseco authored Oct 19, 2024
1 parent ad2817e commit 3d3a5db
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions .github/workflows/check-moodle-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,38 @@ jobs:
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: |
CURRENT_VERSION=$(git tag | sort -V | tail -n 1)
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
- name: Compare Versions
id: version_compare
uses: madhead/[email protected]
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: |
# 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
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."

0 comments on commit 3d3a5db

Please sign in to comment.