Debian Codegraph @

.github/workflows/check-fmt-release.yml

raw
1 name: Check for new fmt release
2
3 on:
4 schedule:
5 # Run daily at 06:00 UTC
6 - cron: '0 6 * * *'
7 workflow_dispatch:
8
9 permissions:
10 contents: read
11 issues: write
12
13 jobs:
14 check-fmt:
15 runs-on: ubuntu-latest
16 steps:
17 - name: Get latest fmt release
18 id: latest
19 env:
20 GH_TOKEN: ${{ github.token }}
21 run: |
22 latest=$(curl -fsSL \
23 -H "Authorization: Bearer ${GH_TOKEN}" \
24 -H "Accept: application/vnd.github+json" \
25 https://api.github.com/repos/fmtlib/fmt/releases/latest | jq -r .tag_name)
26 if [ -z "$latest" ] || [ "$latest" = "null" ]; then
27 echo "::error::Failed to fetch latest fmt release tag"
28 exit 1
29 fi
30 echo "latest=$latest" >> "$GITHUB_OUTPUT"
31 echo "Latest fmt release: $latest"
32
33 - name: Check for existing issue
34 id: existing
35 env:
36 GH_TOKEN: ${{ github.token }}
37 LATEST: ${{ steps.latest.outputs.latest }}
38 REPO: ${{ github.repository }}
39 run: |
40 title="New fmt release available: ${LATEST}"
41 # Search both open and closed issues so we do not reopen / duplicate
42 # an already-acknowledged release notification.
43 query=$(jq -rn --arg repo "$REPO" --arg title "$title" \
44 '"repo:\($repo) is:issue in:title \"\($title)\""')
45 count=$(curl -fsSL -G \
46 -H "Authorization: Bearer ${GH_TOKEN}" \
47 -H "Accept: application/vnd.github+json" \
48 --data-urlencode "q=${query}" \
49 https://api.github.com/search/issues | jq -r '.total_count')
50 echo "Matching issues found: $count"
51 echo "count=$count" >> "$GITHUB_OUTPUT"
52 echo "title=$title" >> "$GITHUB_OUTPUT"
53
54 - name: Create issue for new fmt release
55 if: steps.existing.outputs.count == '0'
56 env:
57 GH_TOKEN: ${{ github.token }}
58 LATEST: ${{ steps.latest.outputs.latest }}
59 REPO: ${{ github.repository }}
60 TITLE: ${{ steps.existing.outputs.title }}
61 run: |
62 body=$(cat <<EOF
63 A new release of [fmtlib/fmt](https://github.com/fmtlib/fmt) has been published.
64
65 - Latest version: \`${LATEST}\`
66 - Release notes: https://github.com/fmtlib/fmt/releases/tag/${LATEST}
67
68 Please consider updating the bundled fmt version in this repository.
69
70 _This issue was created automatically by the \`check-fmt-release\` workflow. Close it once the update has been handled (or acknowledged) — it will not be reopened for the same version._
71 EOF
72 )
73 curl -fsSL -X POST \
74 -H "Authorization: Bearer ${GH_TOKEN}" \
75 -H "Accept: application/vnd.github+json" \
76 "https://api.github.com/repos/${REPO}/issues" \
77 -d "$(jq -n --arg title "$TITLE" --arg body "$body" \
78 '{title:$title, body:$body, labels:["dependencies"]}')"
79 echo "Opened issue: $TITLE"
80
81 - name: No action needed
82 if: steps.existing.outputs.count != '0'
83 run: echo "An issue for fmt ${{ steps.latest.outputs.latest }} already exists; nothing to do."