Skip to content

Sync version from latest tag #51

Sync version from latest tag

Sync version from latest tag #51

# .github/workflows/sync-version-from-tags.yml
name: Sync version from latest tag
on:
schedule:
- cron: "0 0 * * 1-5" # nightly at 00:00 UTC on weekdays
workflow_dispatch:
permissions:
contents: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.BOT_PAT }}
- name: Find current repo tag and latest xsuite tag
id: tag
shell: bash
run: |
XS_REPO="https://github.com/xsuite/xsuite.git"
git fetch --tags origin
CURRENT_TAG="$(git tag --sort=-v:refname | grep -E '^v?[0-9]+(\.[0-9]+)*$' | head -n1)"
LATEST_XSUITE_TAG="$(
git ls-remote --tags --sort='v:refname' "$XS_REPO" \
| awk -F/ '{print $3}' \
| grep -v '\^{}' \
| grep -E '^v?[0-9]+(\.[0-9]+)*$' \
| tail -n1
)"
echo "current=$CURRENT_TAG" >> "$GITHUB_OUTPUT"
echo "latest=$LATEST_XSUITE_TAG" >> "$GITHUB_OUTPUT"
if [ "$CURRENT_TAG" = "$LATEST_XSUITE_TAG" ] || [ -z "$LATEST_XSUITE_TAG" ]; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Update YAML versions
if: steps.tag.outputs.changed == 'true'
run: |
VERSION="${{ steps.tag.outputs.latest }}"
VERSION="${VERSION#v}" # remove leading v
# Update the version in the YAML files using sed
sed -i -E "s|xsuite\[full_env\]==[0-9]+(\.[0-9]+)*|xsuite[full_env]==${VERSION}|g" envs/full.yaml
sed -i -E "s|xsuite==[0-9]+(\.[0-9]+)*|xsuite==${VERSION}|g" envs/lite.yaml
echo "${{ steps.tag.outputs.latest }}" > .github/last-processed-tag
- name: Commit changes
if: steps.tag.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add envs/full.yaml envs/lite.yaml .github/last-processed-tag
git commit -m "SYNC: Bump Xsuite to ${{ steps.tag.outputs.latest }}"
- name: Create trigger tag
if: steps.tag.outputs.changed == 'true'
run: |
NEW_TAG="${{ steps.tag.outputs.latest }}"
git tag "$NEW_TAG"
git push origin HEAD
git push origin "$NEW_TAG"