Skip to content

add sync

add sync #6

Workflow file for this run

name: "Update Readme"
permissions:
contents: write
# Serialize readme runs on the same ref. This workflow fires on BOTH push and
# release:published, so a release plus the commits around it can spawn several
# runs that race each other's `git push`. Queue them instead (cancel-in-progress
# false) so two readme bots never push concurrently.
concurrency:
group: update-readme-${{ github.ref }}
cancel-in-progress: false
on:
workflow_dispatch:
push:
branches:
- 'main'
paths:
- '.github/tpl/*'
- '.github/data/*'
- '.github/workflows/readme.yml'
release:
types: [ published ]
jobs:
readme:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Get latest release
id: get-latest-release
env:
GH_TOKEN: ${{ github.token }}
run: |
if tag=$(gh api "repos/${{ github.repository }}/releases/latest" --jq .tag_name 2>/dev/null); then
: "${tag:=0.0.0}"
else
tag="0.0.0"
fi
if [ "$tag" = "null" ]; then
tag="0.0.0"
fi
echo "tag_name=$tag" >> "$GITHUB_OUTPUT"
- name: Using main branch
run: |
git switch main || (git fetch --all && git checkout -b main origin/main)
echo "LATEST_MAJOR=$(echo ${{ steps.get-latest-release.outputs.tag_name }} | cut -d . -f 1)" >> $GITHUB_ENV
echo "LATEST_TAG=${{ steps.get-latest-release.outputs.tag_name }}" >> $GITHUB_ENV
latest=$(ls conf/*.conf | tail -1)
echo "LATEST_CONF=$latest" >> $GITHUB_ENV
- name: Update the readme.md
uses: anyvm-org/template-render@v0.0.4
with:
datafile: .github/data/datafile.ini
files: |
.github/tpl/README.tpl.md : README.md
- name: Commit and push changes
run: |
git add README.md
git diff --cached --quiet && exit 0
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "Update version to ${{ steps.get-latest-release.outputs.tag_name }}"
# Retry pull-rebase-push: another run (or a human) may push to main in
# the window between our pull and our push, which gets the push
# rejected ("cannot lock ref ... is at X but expected Y"). Re-fetch,
# rebase our commit on top, and try again. The `if` keeps `bash -e`
# from aborting the loop on a failed pull/push.
for attempt in 1 2 3 4 5; do
if git pull --rebase --autostash && git push; then
exit 0
fi
echo "push rejected (attempt $attempt/5): remote moved, retrying after backoff"
sleep $((attempt * 3))
done
echo "ERROR: could not push README update after 5 attempts" >&2
exit 1