-
Notifications
You must be signed in to change notification settings - Fork 1
190 lines (166 loc) · 7.47 KB
/
Copy pathbump-versions.yml
File metadata and controls
190 lines (166 loc) · 7.47 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
---
name: Bump Tool Versions
on:
schedule:
- cron: "17 3 * * 1" # weekly (Mon) UTC
workflow_dispatch:
permissions:
contents: write
pull-requests: write
defaults:
run:
shell: bash
jobs:
bump:
name: Bump versions.env
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Compute latest versions
id: latest
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
python - <<'PY'
import json
import os
import time
import urllib.error
import urllib.request
token = os.environ["GH_TOKEN"]
timeout_seconds = 12
max_retries = 4
def latest_tag(repo: str) -> str:
url = f"https://api.github.com/repos/{repo}/releases/latest"
headers = {
"Authorization": f"Bearer {token}",
"X-GitHub-Api-Version": "2022-11-28",
"Accept": "application/vnd.github+json",
"User-Agent": "bump-versions-workflow",
}
for attempt in range(1, max_retries + 1):
req = urllib.request.Request(url, headers=headers)
try:
with urllib.request.urlopen(req, timeout=timeout_seconds) as resp:
data = json.load(resp)
tag = data.get("tag_name")
if not tag:
raise RuntimeError(f"Missing tag_name in GitHub response for {repo}")
return tag
except urllib.error.HTTPError as exc:
retryable = exc.code in (403, 429, 500, 502, 503, 504)
if retryable and attempt < max_retries:
time.sleep(2 ** (attempt - 1))
continue
raise RuntimeError(
f"Failed to fetch latest release for {repo}: HTTP {exc.code}"
) from exc
except (urllib.error.URLError, TimeoutError) as exc:
if attempt < max_retries:
time.sleep(2 ** (attempt - 1))
continue
raise RuntimeError(
f"Failed to fetch latest release for {repo}: {exc}"
) from exc
raise RuntimeError(f"Failed to fetch latest release for {repo} after retries")
def latest_npm_version(package_name: str) -> str:
url = f"https://registry.npmjs.org/{package_name}/latest"
for attempt in range(1, max_retries + 1):
try:
with urllib.request.urlopen(url, timeout=timeout_seconds) as resp:
data = json.load(resp)
version = data.get("version")
if not version:
raise RuntimeError(f"Missing version in npm response for {package_name}")
return version
except urllib.error.HTTPError as exc:
retryable = exc.code in (429, 500, 502, 503, 504)
if retryable and attempt < max_retries:
time.sleep(2 ** (attempt - 1))
continue
raise RuntimeError(
f"Failed to fetch latest npm version for {package_name}: HTTP {exc.code}"
) from exc
except (urllib.error.URLError, TimeoutError) as exc:
if attempt < max_retries:
time.sleep(2 ** (attempt - 1))
continue
raise RuntimeError(
f"Failed to fetch latest npm version for {package_name}: {exc}"
) from exc
raise RuntimeError(f"Failed to fetch latest npm version for {package_name} after retries")
versions = {
"zola": latest_tag("getzola/zola").lstrip("v"),
"tailwind": latest_tag("tailwindlabs/tailwindcss").lstrip("v"),
"daisyui": latest_tag("saadeghi/daisyui").lstrip("v"),
"katex": latest_tag("KaTeX/KaTeX").lstrip("v"),
"fa": latest_tag("FortAwesome/Font-Awesome").lstrip("v"),
"terser": latest_npm_version("terser"),
"esbuild": latest_npm_version("esbuild"),
"pnpm": latest_npm_version("pnpm"),
"eslint": latest_npm_version("eslint"),
"stylelint": latest_npm_version("stylelint"),
}
out_path = os.environ["GITHUB_OUTPUT"]
with open(out_path, "a", encoding="utf-8") as f:
for k, v in versions.items():
f.write(f"{k}={v}\n")
PY
- name: Update versions.env
run: |
set -euo pipefail
file="versions.env"
sed -i -E "s/^ZOLA_VERSION=.*/ZOLA_VERSION=${{ steps.latest.outputs.zola }}/" "$file"
sed -i -E "s/^TAILWIND_VERSION=.*/TAILWIND_VERSION=${{ steps.latest.outputs.tailwind }}/" "$file"
sed -i -E "s/^DAISYUI_VERSION=.*/DAISYUI_VERSION=${{ steps.latest.outputs.daisyui }}/" "$file"
sed -i -E "s/^FA_VERSION=.*/FA_VERSION=${{ steps.latest.outputs.fa }}/" "$file"
sed -i -E "s/^KATEX_VERSION=.*/KATEX_VERSION=${{ steps.latest.outputs.katex }}/" "$file"
sed -i -E "s/^TERSER_VERSION=.*/TERSER_VERSION=${{ steps.latest.outputs.terser }}/" "$file"
sed -i -E "s/^ESBUILD_VERSION=.*/ESBUILD_VERSION=${{ steps.latest.outputs.esbuild }}/" "$file"
sed -i -E "s/^PNPM_VERSION=.*/PNPM_VERSION=${{ steps.latest.outputs.pnpm }}/" "$file"
sed -i -E "s/^ESLINT_VERSION=.*/ESLINT_VERSION=${{ steps.latest.outputs.eslint }}/" "$file"
sed -i -E "s/^STYLELINT_VERSION=.*/STYLELINT_VERSION=${{ steps.latest.outputs.stylelint }}/" "$file"
echo "Updated versions.env:"
cat "$file"
- name: Import GPG Key
id: import-gpg
uses: crazy-max/ghaction-import-gpg@v7
with:
gpg_private_key: ${{ secrets.BUMP_PRIVATE_GPG }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
- name: Create pull request
id: cpr
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8
with:
author: "${{ steps.import-gpg.outputs.name }} <${{ steps.import-gpg.outputs.email }}>"
committer: "${{ steps.import-gpg.outputs.name }} <${{ steps.import-gpg.outputs.email }}>"
commit-message: "chore: bump tool versions"
title: "chore: bump tool versions"
body: |
Automated weekly bump of tool versions in `versions.env`.
- Zola: ${{ steps.latest.outputs.zola }}
- Tailwind: ${{ steps.latest.outputs.tailwind }}
- DaisyUI: ${{ steps.latest.outputs.daisyui }}
- Font Awesome: ${{ steps.latest.outputs.fa }}
- KaTeX: ${{ steps.latest.outputs.katex }}
- Terser: ${{ steps.latest.outputs.terser }}
- esbuild: ${{ steps.latest.outputs.esbuild }}
- pnpm: ${{ steps.latest.outputs.pnpm }}
- ESLint: ${{ steps.latest.outputs.eslint }}
- Stylelint: ${{ steps.latest.outputs.stylelint }}
branch: chore/bump-tool-versions
delete-branch: true
labels: |
dependencies
automation
- name: Enable Auto-Merge
if: steps.cpr.outputs.pull-request-operation != 'closed'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr merge --auto --squash "${{ steps.cpr.outputs.pull-request-number }}" || true