-
Notifications
You must be signed in to change notification settings - Fork 3
64 lines (55 loc) · 2.23 KB
/
update-badges.yml
File metadata and controls
64 lines (55 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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