Skip to content

Sync Moodle Tags

Sync Moodle Tags #801

name: Sync Moodle Tags
on:
schedule:
- cron: '0 0 * * *' # Daily at midnight
workflow_dispatch: # Allows manually triggering
jobs:
sync-tags:
runs-on: ubuntu-latest
permissions:
contents: write # Needed to create and push tags
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get Moodle tags
id: get-moodle-tags
run: |
echo "Fetching Moodle tags from GitHub API..."
MOODLE_TAGS=$(curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/moodle/moodle/tags" | jq -r '.[].name')
# Convert newlines to spaces for proper shell iteration
MOODLE_TAGS_FORMATTED=$(echo "$MOODLE_TAGS" | tr '\n' ' ')
echo "moodle_tags=$MOODLE_TAGS_FORMATTED" >> $GITHUB_ENV
- name: Get existing tags
id: get-existing-tags
run: |
git fetch --tags
EXISTING_TAGS=$(git tag -l)
# Convert newlines to spaces
EXISTING_TAGS_FORMATTED=$(echo "$EXISTING_TAGS" | tr '\n' ' ')
echo "existing_tags=$EXISTING_TAGS_FORMATTED" >> $GITHUB_ENV
- name: Process missing tags
env:
GH_PAT: ${{ secrets.GH_PAT }}
run: |
# Convert existing tags to a pattern for quick matching
EXISTING_TAGS_PATTERN=" ${{ env.existing_tags }} "
# Counter for processed tags
PROCESSED=0
# Process each Moodle tag
for tag in ${{ env.moodle_tags }}; do
# Only process version tags starting with 'v'
if [[ ! "$tag" =~ ^v ]]; then
continue
fi
# Check if tag exists
if [[ "$EXISTING_TAGS_PATTERN" == *" $tag "* ]]; then
echo "Tag $tag already exists, skipping"
continue
fi
# Create and push tag (only need to do this once)
echo "Creating new tag: $tag"
git tag "$tag"
git push origin "$tag"
# Trigger build workflow
echo "Triggering build for tag $tag"
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/'"$tag"'",
"inputs": {
"moodle_version": "'"$tag"'"
}
}'
# Count processed tag
PROCESSED=$((PROCESSED+1))
done
echo "Process completed. Created $PROCESSED new tags."
echo "The buildx workflow will be automatically triggered for these tags."
- name: Summary
run: |
echo "# Moodle Tags Synchronization" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- Moodle tags found: $(echo "${{ env.moodle_tags }}" | wc -w)" >> $GITHUB_STEP_SUMMARY
echo "- Existing tags: $(echo "${{ env.existing_tags }}" | wc -w)" >> $GITHUB_STEP_SUMMARY
echo "- New tags created: $(git tag -l | wc -w) - $(echo "${{ env.existing_tags }}" | wc -w)" >> $GITHUB_STEP_SUMMARY