-
Notifications
You must be signed in to change notification settings - Fork 0
441 lines (364 loc) · 16.2 KB
/
Copy pathcheck-package-versions.yml
File metadata and controls
441 lines (364 loc) · 16.2 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
name: Check Package Versions
on:
schedule:
- cron: '0 6 * * *' # Daily at 6 AM UTC
workflow_dispatch:
inputs:
package:
description: 'Specific package to check (leave empty for all)'
required: false
type: string
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
jobs:
collect-updates:
runs-on: ubuntu-latest
outputs:
updates: ${{ steps.collect.outputs.updates }}
has_updates: ${{ steps.collect.outputs.has_updates }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y jq rpm
- name: Collect all package updates
id: collect
env:
GH_TOKEN: ${{ github.token }}
INPUT_PACKAGE: ${{ inputs.package }}
run: |
# Source shared package configuration
source ./scripts/packages/config.sh
# Use check-upstream-versions.sh script to get updates
UPDATES_JSON="[]"
# Get list of packages to check
if [[ -n "$INPUT_PACKAGE" ]]; then
PACKAGES_TO_CHECK="$INPUT_PACKAGE"
else
PACKAGES_TO_CHECK="${!PACKAGE_REPOS[@]}"
fi
echo "Checking packages for upstream updates..."
echo ""
for pkg in $PACKAGES_TO_CHECK; do
echo "Checking $pkg..."
# Get spec version (version only, strip release)
SPEC_VER=$(./scripts/packages/get-spec-version.sh "$pkg" 2>/dev/null | sed 's/-[^-]*$//')
if [[ -z "$SPEC_VER" ]]; then
echo " Could not get spec version"
continue
fi
# Get upstream version
UPSTREAM_VER=$(./scripts/packages/get-upstream-version.sh "$pkg" 2>/dev/null)
if [[ -z "$UPSTREAM_VER" ]]; then
echo " Could not get upstream version"
continue
fi
echo " Spec: $SPEC_VER, Upstream: $UPSTREAM_VER"
# Compare versions
if [[ "$SPEC_VER" != "$UPSTREAM_VER" ]]; then
echo " -> Needs update!"
UPDATES_JSON=$(echo "$UPDATES_JSON" | jq -c \
--arg pkg "$pkg" \
--arg repo "${PACKAGE_REPOS[$pkg]}" \
--arg old "$SPEC_VER" \
--arg new "$UPSTREAM_VER" \
--arg deps "${PACKAGE_DEPS[$pkg]:-}" \
'. += [{"package": $pkg, "repo": $repo, "old_version": $old, "new_version": $new, "dependencies": $deps}]')
fi
done
echo ""
echo "Updates found:"
echo "$UPDATES_JSON" | jq .
if [[ "$UPDATES_JSON" == "[]" ]]; then
echo "has_updates=false" >> $GITHUB_OUTPUT
echo "updates=[]" >> $GITHUB_OUTPUT
else
echo "has_updates=true" >> $GITHUB_OUTPUT
echo "updates=$(echo "$UPDATES_JSON" | jq -c .)" >> $GITHUB_OUTPUT
fi
group-updates:
needs: collect-updates
if: needs.collect-updates.outputs.has_updates == 'true'
runs-on: ubuntu-latest
outputs:
groups: ${{ steps.group.outputs.groups }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Group updates by dependency chain
id: group
run: |
UPDATES='${{ needs.collect-updates.outputs.updates }}'
# Source shared package configuration
source ./scripts/packages/config.sh
# Use PACKAGE_DEPS from shared config
# Get list of packages that need updates
UPDATED_PKGS=$(echo "$UPDATES" | jq -r '.[].package')
# Function to get all ancestors (dependencies) of a package
get_ancestors() {
local pkg=$1
local ancestors=""
for dep in ${PACKAGE_DEPS[$pkg]:-}; do
ancestors="$ancestors $dep"
ancestors="$ancestors $(get_ancestors $dep)"
done
echo "$ancestors"
}
# Function to get all descendants (dependents) of a package
get_descendants() {
local pkg=$1
local descendants=""
for p in "${!PACKAGE_DEPS[@]}"; do
if [[ " ${PACKAGE_DEPS[$p]} " == *" $pkg "* ]]; then
descendants="$descendants $p"
descendants="$descendants $(get_descendants $p)"
fi
done
echo "$descendants"
}
# Build groups - packages that share dependencies go together
declare -A VISITED
GROUPS_JSON="[]"
GROUP_ID=0
for pkg in $UPDATED_PKGS; do
if [[ -n "${VISITED[$pkg]}" ]]; then
continue
fi
# Start a new group with this package
GROUP_PKGS="$pkg"
VISITED[$pkg]=1
# Add all updated packages that are ancestors or descendants
ancestors=$(get_ancestors "$pkg")
descendants=$(get_descendants "$pkg")
related="$ancestors $descendants"
for other in $UPDATED_PKGS; do
if [[ -z "${VISITED[$other]}" ]]; then
# Check if other is related to this package
if [[ " $related " == *" $other "* ]]; then
GROUP_PKGS="$GROUP_PKGS $other"
VISITED[$other]=1
# Also add relatives of this newly added package
other_ancestors=$(get_ancestors "$other")
other_descendants=$(get_descendants "$other")
for another in $UPDATED_PKGS; do
if [[ -z "${VISITED[$another]}" ]]; then
if [[ " $other_ancestors $other_descendants " == *" $another "* ]]; then
GROUP_PKGS="$GROUP_PKGS $another"
VISITED[$another]=1
fi
fi
done
fi
fi
done
# Deduplicate and sort
GROUP_PKGS=$(echo "$GROUP_PKGS" | tr ' ' '\n' | sort -u | tr '\n' ' ' | xargs)
if [[ -n "$GROUP_PKGS" ]]; then
# Build group JSON with package details
GROUP_UPDATES="[]"
for gpkg in $GROUP_PKGS; do
PKG_DATA=$(echo "$UPDATES" | jq -c --arg pkg "$gpkg" '.[] | select(.package == $pkg)')
if [[ -n "$PKG_DATA" ]]; then
GROUP_UPDATES=$(echo "$GROUP_UPDATES" | jq -c --argjson data "$PKG_DATA" '. += [$data]')
fi
done
GROUP_ID=$((GROUP_ID + 1))
GROUPS_JSON=$(echo "$GROUPS_JSON" | jq -c \
--argjson id "$GROUP_ID" \
--argjson packages "$GROUP_UPDATES" \
'. += [{"id": $id, "packages": $packages}]')
fi
done
echo "Grouped updates:"
echo "$GROUPS_JSON" | jq .
echo "groups=$(echo "$GROUPS_JSON" | jq -c .)" >> $GITHUB_OUTPUT
create-prs:
needs: group-updates
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 1
matrix:
group: ${{ fromJson(needs.group-updates.outputs.groups) }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y jq rpm
- name: Generate group info
id: info
run: |
PACKAGES='${{ toJson(matrix.group.packages) }}'
# Get package info for branch name
PKG_COUNT=$(echo "$PACKAGES" | jq 'length')
# Create summary for PR title and branch name
if [[ "$PKG_COUNT" -eq 1 ]]; then
PKG_NAME=$(echo "$PACKAGES" | jq -r '.[0].package')
NEW_VERSION=$(echo "$PACKAGES" | jq -r '.[0].new_version')
TITLE="pkg(${PKG_NAME}): update to ${NEW_VERSION}"
BRANCH="pkg-update/${PKG_NAME}-v${NEW_VERSION}"
else
# For multiple packages, use first package name and combine versions
FIRST_PKG=$(echo "$PACKAGES" | jq -r '.[0].package')
VERSIONS=$(echo "$PACKAGES" | jq -r '.[].new_version' | sort | tr '\n' '-' | sed 's/-$//')
TITLE="pkg: update $FIRST_PKG and $((PKG_COUNT - 1)) related packages"
BRANCH="pkg-update/${FIRST_PKG}-group-v${VERSIONS}"
fi
echo "title=$TITLE" >> $GITHUB_OUTPUT
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
echo "pkg_count=$PKG_COUNT" >> $GITHUB_OUTPUT
- name: Check for existing branch
id: existing-pr
run: |
BRANCH="${{ steps.info.outputs.branch }}"
# Check if branch already exists (locally or remotely)
if git ls-remote --heads origin "$BRANCH" | grep -q .; then
echo "Branch '$BRANCH' already exists - skipping PR creation"
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "Branch '$BRANCH' does not exist - will create PR"
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Update spec files
if: steps.existing-pr.outputs.exists != 'true'
run: |
PACKAGES='${{ toJson(matrix.group.packages) }}'
DATE=$(date "+%a %b %d %Y")
# Use process substitution to avoid subshell issues
while read -r pkg_data; do
PKG=$(echo "$pkg_data" | jq -r '.package')
OLD_VERSION=$(echo "$pkg_data" | jq -r '.old_version')
NEW_VERSION=$(echo "$pkg_data" | jq -r '.new_version')
SPEC_FILE="packages/$PKG/$PKG.spec"
echo "Updating $PKG: $OLD_VERSION -> $NEW_VERSION"
# Update Version field
sed -i "s/^Version:.*$/Version: $NEW_VERSION/" "$SPEC_FILE"
# Update Release back to 1
sed -i "s/^Release:.*$/Release: 1%{?dist}/" "$SPEC_FILE"
# Add changelog entry
CHANGELOG_ENTRY="* $DATE Hypercube <hypercube@binarypie.dev> - $NEW_VERSION-1\n- Update to $NEW_VERSION"
sed -i "/%changelog/a\\$CHANGELOG_ENTRY" "$SPEC_FILE"
done < <(echo "$PACKAGES" | jq -c '.[]')
- name: Generate PR body
if: steps.existing-pr.outputs.exists != 'true'
id: body
run: |
PACKAGES='${{ toJson(matrix.group.packages) }}'
{
echo "body<<EOF"
echo "## Package Updates"
echo ""
# Use process substitution to avoid subshell issues with while loop
while read -r pkg_data; do
PKG=$(echo "$pkg_data" | jq -r '.package')
REPO=$(echo "$pkg_data" | jq -r '.repo')
OLD=$(echo "$pkg_data" | jq -r '.old_version')
NEW=$(echo "$pkg_data" | jq -r '.new_version')
echo "### $PKG"
echo "- **Version:** \`$OLD\` -> \`$NEW\`"
echo "- **Release:** https://github.com/$REPO/releases/tag/v$NEW"
echo ""
done < <(echo "$PACKAGES" | jq -c '.[]')
echo "---"
echo "*This PR was automatically created by the package version checker.*"
echo "*Packages are grouped by dependency chain to ensure correct build order.*"
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Create Pull Request
if: steps.existing-pr.outputs.exists != 'true'
id: create-pr
uses: peter-evans/create-pull-request@v8
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "${{ steps.info.outputs.title }}"
title: "${{ steps.info.outputs.title }}"
body: ${{ steps.body.outputs.body }}
branch: "${{ steps.info.outputs.branch }}"
delete-branch: true
labels: |
dependencies
package-update
author: "Claude <claude@anthropic.com>"
committer: "Claude <claude@anthropic.com>"
- name: Fetch upstream build files
if: steps.existing-pr.outputs.exists != 'true' && steps.create-pr.outputs.pull-request-number
id: upstream
run: |
PACKAGES='${{ toJson(matrix.group.packages) }}'
mkdir -p .upstream-build-files
# Define build file patterns for different project types
declare -A BUILD_FILES=(
# Rust projects
[eza]="Cargo.toml"
[starship]="Cargo.toml"
[wifitui]="Cargo.toml"
# Go projects
[lazygit]="go.mod"
# Python projects
[uwsm]="pyproject.toml"
# Default for Hyprland ecosystem is CMakeLists.txt
)
UPSTREAM_CONTENT=""
while read -r pkg_data; do
PKG=$(echo "$pkg_data" | jq -r '.package')
REPO=$(echo "$pkg_data" | jq -r '.repo')
VERSION=$(echo "$pkg_data" | jq -r '.new_version')
# Determine which build file to fetch
BUILD_FILE="${BUILD_FILES[$PKG]:-CMakeLists.txt}"
echo "Fetching $BUILD_FILE for $PKG v$VERSION from $REPO..."
# Try to fetch the build file
URL="https://raw.githubusercontent.com/${REPO}/v${VERSION}/${BUILD_FILE}"
CONTENT=$(curl -sL "$URL" 2>/dev/null)
if [[ -z "$CONTENT" || "$CONTENT" == "404"* ]]; then
# Try without 'v' prefix
URL="https://raw.githubusercontent.com/${REPO}/${VERSION}/${BUILD_FILE}"
CONTENT=$(curl -sL "$URL" 2>/dev/null)
fi
if [[ -n "$CONTENT" && "$CONTENT" != "404"* ]]; then
# Save to file for Claude to read
echo "$CONTENT" > ".upstream-build-files/${PKG}-${BUILD_FILE//\//-}"
UPSTREAM_CONTENT="${UPSTREAM_CONTENT}
=== ${PKG} (${BUILD_FILE}) ===
${CONTENT}
"
echo " ✓ Fetched successfully"
else
echo " ✗ Could not fetch $BUILD_FILE"
UPSTREAM_CONTENT="${UPSTREAM_CONTENT}
=== ${PKG} (${BUILD_FILE}) ===
[Could not fetch - manual verification required]
"
fi
done < <(echo "$PACKAGES" | jq -c '.[]')
# Save all content to a file for the prompt
echo "$UPSTREAM_CONTENT" > .upstream-build-files/all-content.txt
- name: Analyze and update specs with Claude
if: steps.existing-pr.outputs.exists != 'true' && steps.create-pr.outputs.pull-request-number
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
prompt: |
I need you to analyze and update RPM spec files for package version upgrades.
The following packages were updated (version bumps already applied to spec files):
${{ toJson(matrix.group.packages) }}
The upstream build configuration files have been pre-fetched and saved to `.upstream-build-files/`.
Read the file `.upstream-build-files/all-content.txt` to see all the upstream build files.
For each package, please:
1. Read the upstream build configuration from `.upstream-build-files/all-content.txt`
2. Compare the dependencies in the upstream build files against the current spec file's BuildRequires and Requires sections.
3. Check if any shared library soname versions have changed (e.g., libfoo.so.3 -> libfoo.so.4) by looking at:
- CMake's set_target_properties for SOVERSION
- The %files section of the spec for current soname expectations
4. Update the spec file if needed:
- Add/remove/update BuildRequires for new build dependencies
- Add/remove/update Requires for new runtime dependencies
- Update soname versions in %files section if the library major version changed
- Update any hardcoded paths or version references
5. If you make changes, update the changelog entry to mention what changed beyond just the version bump.
The spec files are located at: packages/<package-name>/<package-name>.spec
Focus on correctness - it's better to flag something for manual review than to make an incorrect change.
If you're uncertain about a change, add a comment in the PR explaining what might need manual verification.
claude_args: "--max-turns 10"