Skip to content

Commit 6cbe95b

Browse files
committed
refactor: move version check/update logic to scripts
- scripts/check-versions.sh: detects current and latest versions - scripts/update-versions.sh: applies version updates to Dockerfiles - Simplified update-versions.yml workflow
1 parent 7d7fc7d commit 6cbe95b

File tree

3 files changed

+222
-174
lines changed

3 files changed

+222
-174
lines changed

.github/workflows/update-versions.yml

Lines changed: 33 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -31,127 +31,29 @@ jobs:
3131
check-updates:
3232
runs-on: ubuntu-latest
3333
outputs:
34-
rust_current: ${{ steps.current.outputs.rust }}
35-
rust_latest: ${{ steps.latest.outputs.rust }}
36-
llvm_current: ${{ steps.current.outputs.llvm }}
37-
llvm_latest: ${{ steps.latest.outputs.llvm }}
38-
llvm_major: ${{ steps.latest.outputs.llvm_major }}
39-
git_current: ${{ steps.current.outputs.git }}
40-
git_latest: ${{ steps.latest.outputs.git }}
41-
sevenzip_current: ${{ steps.current.outputs.sevenzip }}
42-
sevenzip_latest: ${{ steps.latest.outputs.sevenzip }}
43-
has_update: ${{ steps.compare.outputs.has_update }}
44-
update_summary: ${{ steps.compare.outputs.summary }}
34+
rust_current: ${{ steps.check.outputs.rust_current }}
35+
rust_latest: ${{ steps.check.outputs.rust_latest }}
36+
llvm_current: ${{ steps.check.outputs.llvm_current }}
37+
llvm_latest: ${{ steps.check.outputs.llvm_latest }}
38+
llvm_major: ${{ steps.check.outputs.llvm_major }}
39+
git_current: ${{ steps.check.outputs.git_current }}
40+
git_latest: ${{ steps.check.outputs.git_latest }}
41+
sevenzip_current: ${{ steps.check.outputs.sevenzip_current }}
42+
sevenzip_latest: ${{ steps.check.outputs.sevenzip_latest }}
43+
has_update: ${{ steps.check.outputs.has_update }}
44+
summary: ${{ steps.check.outputs.summary }}
4545
steps:
4646
- uses: actions/checkout@v4
4747

48-
- name: Get current versions from Dockerfiles
49-
id: current
50-
run: |
51-
# Get from linux/Dockerfile
52-
RUST=$(grep -oP 'RUST_VERSION=\K[0-9.]+' linux/Dockerfile | head -1)
53-
LLVM_MAJOR=$(grep -oP 'LLVM_VERSION=\K[0-9]+' linux/Dockerfile | head -1)
54-
55-
# Get from windows/Dockerfile (full LLVM version)
56-
LLVM=$(grep -oP 'LLVM_VERSION=\K[0-9.]+' windows/Dockerfile | head -1)
57-
GIT=$(grep -oP 'GIT_VERSION=\K[0-9.]+' windows/Dockerfile | head -1)
58-
ZIP=$(grep -oP '7ZIP_VERSION=\K[0-9]+' windows/Dockerfile | head -1)
59-
60-
echo "rust=$RUST" >> $GITHUB_OUTPUT
61-
echo "llvm=$LLVM" >> $GITHUB_OUTPUT
62-
echo "llvm_major=$LLVM_MAJOR" >> $GITHUB_OUTPUT
63-
echo "git=$GIT" >> $GITHUB_OUTPUT
64-
echo "sevenzip=$ZIP" >> $GITHUB_OUTPUT
65-
66-
echo "Current versions:"
67-
echo " Rust: $RUST"
68-
echo " LLVM: $LLVM (major: $LLVM_MAJOR)"
69-
echo " Git: $GIT"
70-
echo " 7-Zip: $ZIP"
71-
72-
- name: Get latest versions
73-
id: latest
48+
- name: Check for updates
49+
id: check
7450
env:
7551
GH_TOKEN: ${{ github.token }}
76-
run: |
77-
# Rust - from official manifest
78-
if [ -n "${{ inputs.rust_version }}" ]; then
79-
RUST="${{ inputs.rust_version }}"
80-
else
81-
RUST=$(curl -s https://static.rust-lang.org/dist/channel-rust-stable.toml | grep -oP 'cargo-\K[0-9]+\.[0-9]+\.[0-9]+' | head -1)
82-
fi
83-
echo "rust=$RUST" >> $GITHUB_OUTPUT
84-
echo "Latest Rust: $RUST"
85-
86-
# LLVM - from ghaith/llvm-package-windows releases
87-
if [ -n "${{ inputs.llvm_version }}" ]; then
88-
LLVM="${{ inputs.llvm_version }}"
89-
else
90-
LLVM=$(gh api repos/ghaith/llvm-package-windows/releases/latest --jq '.tag_name' | sed 's/^v//')
91-
fi
92-
LLVM_MAJOR=$(echo "$LLVM" | grep -oP '^\d+')
93-
echo "llvm=$LLVM" >> $GITHUB_OUTPUT
94-
echo "llvm_major=$LLVM_MAJOR" >> $GITHUB_OUTPUT
95-
echo "Latest LLVM: $LLVM (major: $LLVM_MAJOR)"
96-
97-
# Git for Windows - from GitHub releases
98-
if [ -n "${{ inputs.git_version }}" ]; then
99-
GIT="${{ inputs.git_version }}"
100-
else
101-
GIT=$(gh api repos/git-for-windows/git/releases/latest --jq '.tag_name' | grep -oP '[0-9]+\.[0-9]+\.[0-9]+')
102-
fi
103-
echo "git=$GIT" >> $GITHUB_OUTPUT
104-
echo "Latest Git: $GIT"
105-
106-
# 7-Zip - scrape from download page (version code like 2600 for 26.00)
107-
if [ -n "${{ inputs.sevenzip_version }}" ]; then
108-
ZIP="${{ inputs.sevenzip_version }}"
109-
else
110-
ZIP=$(curl -s https://www.7-zip.org/download.html | grep -oP '7z\K[0-9]{4}(?=-x64\.exe)' | head -1)
111-
fi
112-
echo "sevenzip=$ZIP" >> $GITHUB_OUTPUT
113-
echo "Latest 7-Zip: $ZIP"
114-
115-
- name: Compare versions
116-
id: compare
117-
run: |
118-
UPDATES=""
119-
HAS_UPDATE=false
120-
121-
# Only Rust and LLVM updates trigger a rebuild
122-
if [ "${{ steps.current.outputs.rust }}" != "${{ steps.latest.outputs.rust }}" ]; then
123-
UPDATES="${UPDATES}- Rust: ${{ steps.current.outputs.rust }} → ${{ steps.latest.outputs.rust }}\n"
124-
HAS_UPDATE=true
125-
fi
126-
127-
if [ "${{ steps.current.outputs.llvm }}" != "${{ steps.latest.outputs.llvm }}" ]; then
128-
UPDATES="${UPDATES}- LLVM: ${{ steps.current.outputs.llvm }} → ${{ steps.latest.outputs.llvm }}\n"
129-
HAS_UPDATE=true
130-
fi
131-
132-
# Git and 7-Zip are updated opportunistically (only if we're already rebuilding)
133-
if [ "$HAS_UPDATE" = true ]; then
134-
if [ "${{ steps.current.outputs.git }}" != "${{ steps.latest.outputs.git }}" ]; then
135-
UPDATES="${UPDATES}- Git: ${{ steps.current.outputs.git }} → ${{ steps.latest.outputs.git }}\n"
136-
fi
137-
138-
if [ "${{ steps.current.outputs.sevenzip }}" != "${{ steps.latest.outputs.sevenzip }}" ]; then
139-
UPDATES="${UPDATES}- 7-Zip: ${{ steps.current.outputs.sevenzip }} → ${{ steps.latest.outputs.sevenzip }}\n"
140-
fi
141-
fi
142-
143-
if [ "$HAS_UPDATE" = true ]; then
144-
echo "has_update=true" >> $GITHUB_OUTPUT
145-
echo -e "Updates available:\n$UPDATES"
146-
else
147-
echo "has_update=false" >> $GITHUB_OUTPUT
148-
echo "All versions are up to date"
149-
fi
150-
151-
# Store summary for PR body (escape newlines for GitHub Actions)
152-
echo "summary<<EOF" >> $GITHUB_OUTPUT
153-
echo -e "$UPDATES" >> $GITHUB_OUTPUT
154-
echo "EOF" >> $GITHUB_OUTPUT
52+
RUST_OVERRIDE: ${{ inputs.rust_version }}
53+
LLVM_OVERRIDE: ${{ inputs.llvm_version }}
54+
GIT_OVERRIDE: ${{ inputs.git_version }}
55+
SEVENZIP_OVERRIDE: ${{ inputs.sevenzip_version }}
56+
run: ./scripts/check-versions.sh
15557

15658
create-pr:
15759
needs: check-updates
@@ -160,65 +62,22 @@ jobs:
16062
steps:
16163
- uses: actions/checkout@v4
16264

163-
- name: Update versions in Dockerfiles
164-
run: |
165-
echo "Applying version updates..."
166-
167-
# Update Rust in both Dockerfiles
168-
if [ "${{ needs.check-updates.outputs.rust_current }}" != "${{ needs.check-updates.outputs.rust_latest }}" ]; then
169-
sed -i "s/RUST_VERSION=${{ needs.check-updates.outputs.rust_current }}/RUST_VERSION=${{ needs.check-updates.outputs.rust_latest }}/" linux/Dockerfile windows/Dockerfile
170-
echo "Updated Rust to ${{ needs.check-updates.outputs.rust_latest }}"
171-
fi
172-
173-
# Update LLVM in windows/Dockerfile (full version)
174-
if [ "${{ needs.check-updates.outputs.llvm_current }}" != "${{ needs.check-updates.outputs.llvm_latest }}" ]; then
175-
sed -i "s/LLVM_VERSION=${{ needs.check-updates.outputs.llvm_current }}/LLVM_VERSION=${{ needs.check-updates.outputs.llvm_latest }}/" windows/Dockerfile
176-
# Update major version in linux/Dockerfile
177-
OLD_MAJOR=$(echo "${{ needs.check-updates.outputs.llvm_current }}" | grep -oP '^\d+')
178-
NEW_MAJOR="${{ needs.check-updates.outputs.llvm_major }}"
179-
if [ "$OLD_MAJOR" != "$NEW_MAJOR" ]; then
180-
sed -i "s/LLVM_VERSION=$OLD_MAJOR/LLVM_VERSION=$NEW_MAJOR/" linux/Dockerfile
181-
echo "Updated Linux LLVM major to $NEW_MAJOR"
182-
fi
183-
echo "Updated Windows LLVM to ${{ needs.check-updates.outputs.llvm_latest }}"
184-
fi
185-
186-
# Update Git in windows/Dockerfile
187-
if [ "${{ needs.check-updates.outputs.git_current }}" != "${{ needs.check-updates.outputs.git_latest }}" ]; then
188-
sed -i "s/GIT_VERSION=${{ needs.check-updates.outputs.git_current }}/GIT_VERSION=${{ needs.check-updates.outputs.git_latest }}/" windows/Dockerfile
189-
echo "Updated Git to ${{ needs.check-updates.outputs.git_latest }}"
190-
fi
191-
192-
# Update 7-Zip in windows/Dockerfile
193-
if [ "${{ needs.check-updates.outputs.sevenzip_current }}" != "${{ needs.check-updates.outputs.sevenzip_latest }}" ]; then
194-
sed -i "s/7ZIP_VERSION=${{ needs.check-updates.outputs.sevenzip_current }}/7ZIP_VERSION=${{ needs.check-updates.outputs.sevenzip_latest }}/" windows/Dockerfile
195-
echo "Updated 7-Zip to ${{ needs.check-updates.outputs.sevenzip_latest }}"
196-
fi
197-
198-
echo ""
199-
echo "Updated Dockerfiles:"
200-
grep -E '(RUST_VERSION|LLVM_VERSION|GIT_VERSION|7ZIP_VERSION)=' linux/Dockerfile windows/Dockerfile
65+
- name: Update Dockerfiles
66+
env:
67+
RUST_CURRENT: ${{ needs.check-updates.outputs.rust_current }}
68+
RUST_LATEST: ${{ needs.check-updates.outputs.rust_latest }}
69+
LLVM_CURRENT: ${{ needs.check-updates.outputs.llvm_current }}
70+
LLVM_LATEST: ${{ needs.check-updates.outputs.llvm_latest }}
71+
LLVM_MAJOR: ${{ needs.check-updates.outputs.llvm_major }}
72+
GIT_CURRENT: ${{ needs.check-updates.outputs.git_current }}
73+
GIT_LATEST: ${{ needs.check-updates.outputs.git_latest }}
74+
SEVENZIP_CURRENT: ${{ needs.check-updates.outputs.sevenzip_current }}
75+
SEVENZIP_LATEST: ${{ needs.check-updates.outputs.sevenzip_latest }}
76+
run: ./scripts/update-versions.sh
20177

20278
- name: Validate URLs
20379
run: ./scripts/validate-urls.sh
20480

205-
- name: Generate branch name and tag
206-
id: meta
207-
run: |
208-
# Branch name based on what's being updated
209-
BRANCH="update-deps"
210-
211-
# Tag is based on LLVM major and Rust major.minor
212-
LLVM_MAJOR="${{ needs.check-updates.outputs.llvm_major }}"
213-
RUST="${{ needs.check-updates.outputs.rust_latest }}"
214-
RUST_MAJOR_MINOR=$(echo "$RUST" | grep -oP '^\d+\.\d+')
215-
216-
TAG="v${LLVM_MAJOR}-${RUST_MAJOR_MINOR}"
217-
218-
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
219-
echo "tag=$TAG" >> $GITHUB_OUTPUT
220-
echo "Branch: $BRANCH, Tag: $TAG"
221-
22281
- name: Create Pull Request
22382
uses: peter-evans/create-pull-request@v6
22483
with:
@@ -228,7 +87,7 @@ jobs:
22887
body: |
22988
This PR updates the following dependencies:
23089
231-
${{ needs.check-updates.outputs.update_summary }}
90+
${{ needs.check-updates.outputs.summary }}
23291
23392
## Updated versions
23493
| Component | Version |
@@ -240,11 +99,11 @@ jobs:
24099
| 7-Zip | ${{ needs.check-updates.outputs.sevenzip_latest }} |
241100
242101
## Release
243-
When merged, this will be tagged as `${{ steps.meta.outputs.tag }}`.
102+
When merged, this will be tagged as `v${{ needs.check-updates.outputs.llvm_major }}-${{ needs.check-updates.outputs.rust_latest }}`.
244103
245104
---
246105
*This PR was automatically created by the update-versions workflow.*
247-
branch: ${{ steps.meta.outputs.branch }}
106+
branch: update-deps
248107
delete-branch: true
249108
labels: |
250109
dependencies

scripts/check-versions.sh

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/bin/bash
2+
# Checks for updates to dependencies and outputs version information
3+
# Used by the update-versions workflow
4+
5+
set -e
6+
7+
# Input: optional override versions from environment
8+
# RUST_OVERRIDE, LLVM_OVERRIDE, GIT_OVERRIDE, SEVENZIP_OVERRIDE
9+
10+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
11+
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
12+
13+
# Get current versions from Dockerfiles
14+
get_current_versions() {
15+
RUST_CURRENT=$(grep -oP 'RUST_VERSION=\K[0-9.]+' "$ROOT_DIR/linux/Dockerfile" | head -1)
16+
LLVM_CURRENT=$(grep -oP 'LLVM_VERSION=\K[0-9.]+' "$ROOT_DIR/windows/Dockerfile" | head -1)
17+
LLVM_MAJOR_CURRENT=$(grep -oP 'LLVM_VERSION=\K[0-9]+' "$ROOT_DIR/linux/Dockerfile" | head -1)
18+
GIT_CURRENT=$(grep -oP 'GIT_VERSION=\K[0-9.]+' "$ROOT_DIR/windows/Dockerfile" | head -1)
19+
SEVENZIP_CURRENT=$(grep -oP '7ZIP_VERSION=\K[0-9]+' "$ROOT_DIR/windows/Dockerfile" | head -1)
20+
}
21+
22+
# Get latest versions from upstream
23+
get_latest_versions() {
24+
# Rust
25+
if [ -n "$RUST_OVERRIDE" ]; then
26+
RUST_LATEST="$RUST_OVERRIDE"
27+
else
28+
RUST_LATEST=$(curl -s https://static.rust-lang.org/dist/channel-rust-stable.toml | grep -oP 'cargo-\K[0-9]+\.[0-9]+\.[0-9]+' | head -1)
29+
fi
30+
31+
# LLVM from ghaith/llvm-package-windows
32+
if [ -n "$LLVM_OVERRIDE" ]; then
33+
LLVM_LATEST="$LLVM_OVERRIDE"
34+
else
35+
LLVM_LATEST=$(gh api repos/ghaith/llvm-package-windows/releases/latest --jq '.tag_name' | sed 's/^v//')
36+
fi
37+
LLVM_MAJOR_LATEST=$(echo "$LLVM_LATEST" | grep -oP '^\d+')
38+
39+
# Git for Windows
40+
if [ -n "$GIT_OVERRIDE" ]; then
41+
GIT_LATEST="$GIT_OVERRIDE"
42+
else
43+
GIT_LATEST=$(gh api repos/git-for-windows/git/releases/latest --jq '.tag_name' | grep -oP '[0-9]+\.[0-9]+\.[0-9]+')
44+
fi
45+
46+
# 7-Zip
47+
if [ -n "$SEVENZIP_OVERRIDE" ]; then
48+
SEVENZIP_LATEST="$SEVENZIP_OVERRIDE"
49+
else
50+
SEVENZIP_LATEST=$(curl -s https://www.7-zip.org/download.html | grep -oP '7z\K[0-9]{4}(?=-x64\.exe)' | head -1)
51+
fi
52+
}
53+
54+
# Compare and determine what needs updating
55+
check_updates() {
56+
HAS_UPDATE=false
57+
SUMMARY=""
58+
59+
# Only Rust and LLVM trigger rebuilds
60+
if [ "$RUST_CURRENT" != "$RUST_LATEST" ]; then
61+
SUMMARY="${SUMMARY}- Rust: ${RUST_CURRENT}${RUST_LATEST}\n"
62+
HAS_UPDATE=true
63+
fi
64+
65+
if [ "$LLVM_CURRENT" != "$LLVM_LATEST" ]; then
66+
SUMMARY="${SUMMARY}- LLVM: ${LLVM_CURRENT}${LLVM_LATEST}\n"
67+
HAS_UPDATE=true
68+
fi
69+
70+
# Git and 7-Zip updated opportunistically
71+
if [ "$HAS_UPDATE" = true ]; then
72+
if [ "$GIT_CURRENT" != "$GIT_LATEST" ]; then
73+
SUMMARY="${SUMMARY}- Git: ${GIT_CURRENT}${GIT_LATEST}\n"
74+
fi
75+
if [ "$SEVENZIP_CURRENT" != "$SEVENZIP_LATEST" ]; then
76+
SUMMARY="${SUMMARY}- 7-Zip: ${SEVENZIP_CURRENT}${SEVENZIP_LATEST}\n"
77+
fi
78+
fi
79+
}
80+
81+
# Output for GitHub Actions
82+
output_github_actions() {
83+
local output_file="${GITHUB_OUTPUT:-/dev/stdout}"
84+
85+
{
86+
echo "rust_current=$RUST_CURRENT"
87+
echo "rust_latest=$RUST_LATEST"
88+
echo "llvm_current=$LLVM_CURRENT"
89+
echo "llvm_latest=$LLVM_LATEST"
90+
echo "llvm_major=$LLVM_MAJOR_LATEST"
91+
echo "git_current=$GIT_CURRENT"
92+
echo "git_latest=$GIT_LATEST"
93+
echo "sevenzip_current=$SEVENZIP_CURRENT"
94+
echo "sevenzip_latest=$SEVENZIP_LATEST"
95+
echo "has_update=$HAS_UPDATE"
96+
echo "summary<<EOF"
97+
echo -e "$SUMMARY"
98+
echo "EOF"
99+
} >> "$output_file"
100+
}
101+
102+
# Print human-readable summary
103+
print_summary() {
104+
echo "Current versions:"
105+
echo " Rust: $RUST_CURRENT"
106+
echo " LLVM: $LLVM_CURRENT (major: $LLVM_MAJOR_CURRENT)"
107+
echo " Git: $GIT_CURRENT"
108+
echo " 7-Zip: $SEVENZIP_CURRENT"
109+
echo ""
110+
echo "Latest versions:"
111+
echo " Rust: $RUST_LATEST"
112+
echo " LLVM: $LLVM_LATEST (major: $LLVM_MAJOR_LATEST)"
113+
echo " Git: $GIT_LATEST"
114+
echo " 7-Zip: $SEVENZIP_LATEST"
115+
echo ""
116+
117+
if [ "$HAS_UPDATE" = true ]; then
118+
echo "Updates available:"
119+
echo -e "$SUMMARY"
120+
else
121+
echo "All versions are up to date"
122+
fi
123+
}
124+
125+
# Main
126+
get_current_versions
127+
get_latest_versions
128+
check_updates
129+
print_summary
130+
131+
if [ -n "$GITHUB_OUTPUT" ]; then
132+
output_github_actions
133+
fi

0 commit comments

Comments
 (0)