-
Notifications
You must be signed in to change notification settings - Fork 0
51 lines (42 loc) · 1.27 KB
/
update-versions-json.yml
File metadata and controls
51 lines (42 loc) · 1.27 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
name: Update Versions JSON
on:
push:
branches:
- main
jobs:
update-versions:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Generate versions.json
run: |
version_dirs=()
while IFS= read -r dir; do
version_dirs+=("${dir#./}")
done < <(find . -maxdepth 1 -type d -regex './v[0-9]+\.[0-9]+\.[0-9]+' | sort -Vr)
# Start JSON array
json="[\n"
# Add static entries
json+=" \"latest\",\n \"stable\""
# Add dynamic versions
for v in "${version_dirs[@]}"; do
json+=",\n \"$v\""
done
json+="\n]"
echo -e "$json" > versions.json
echo "versions.json will look like:"
cat versions.json
- name: Commit and push versions.json
run: |
git config --global user.name 'github-actions'
git config --global user.email 'github-actions@github.com'
git add versions.json
if ! git diff --cached --quiet; then
git commit -m "Update versions.json"
git push origin main
else
echo "No changes to commit."
fi