0.7.503 #36
Workflow file for this run
This file contains hidden or 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: Update latest tag/release JSON | |
| on: | |
| push: | |
| tags: | |
| - '*' # any tag push updates latest_tag.json | |
| release: | |
| types: [published, edited] # update latest_release.json when you publish/edit | |
| permissions: | |
| contents: write | |
| jobs: | |
| update: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout (full history for tag dates) | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Ensure jq available | |
| run: sudo apt-get update && sudo apt-get install -y jq | |
| - name: Compute latest tag by creation date | |
| id: tag | |
| shell: bash | |
| run: | | |
| mkdir -p .badges | |
| # newest tag by *creation date* (not semver) | |
| LATEST_TAG="$(git for-each-ref --sort=-creatordate --format='%(refname:strip=2)' refs/tags | head -n1)" | |
| echo "latest_tag=$LATEST_TAG" >> "$GITHUB_OUTPUT" | |
| - name: Write latest_tag.json | |
| run: | | |
| printf '{ "latest_tag": "%s" }\n' "${{ steps.tag.outputs.latest_tag }}" > .badges/latest_tag.json | |
| - name: Fetch latest published (non-prerelease) release | |
| id: rel | |
| env: | |
| REPO: ${{ github.repository }} | |
| run: | | |
| # GitHub's "latest" endpoint returns the most recent *non-prerelease* published release | |
| DATA="$(curl -sSfL https://api.github.com/repos/${REPO}/releases/latest)" | |
| TAG_NAME="$(echo "$DATA" | jq -r '.tag_name')" | |
| # Fallback if no releases yet | |
| if [ "$TAG_NAME" = "null" ] || [ -z "$TAG_NAME" ]; then TAG_NAME=""; fi | |
| echo "latest_release=$TAG_NAME" >> "$GITHUB_OUTPUT" | |
| - name: Write latest_release.json | |
| run: | | |
| printf '{ "latest_release": "%s" }\n' "${{ steps.rel.outputs.latest_release }}" > .badges/latest_release.json | |
| - name: Commit changes (if any) | |
| run: | | |
| if ! git diff --quiet -- .badges; then | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add .badges/latest_tag.json .badges/latest_release.json | |
| git commit -m "chore(badges): refresh latest_tag/release JSON" | |
| git push | |
| else | |
| echo "No badge JSON changes." | |
| fi |