Repository navigation
128 lines (111 loc) · 5.07 KB
/
Copy pathupdate-bb.yml
File metadata and controls
128 lines (111 loc) · 5.07 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
name: Update bb
on:
schedule:
# Daily at 07:30 UTC (offset from update-gws to avoid stampede)
- cron: '30 7 * * *'
workflow_dispatch:
concurrency:
group: update-bb
cancel-in-progress: true
jobs:
update:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- name: Checkout repository
id: checkout
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v14
- name: Check for new release
id: check
env:
GH_TOKEN: ${{ github.token }}
run: |
# Current version from nix file
current=$(grep 'version = ' pkgs/bb/default.nix | head -1 | sed 's/.*"\(.*\)".*/\1/')
echo "current=$current" >> "$GITHUB_OUTPUT"
# Latest release from buildbuddy-io/bazel (the release repo for the bb CLI).
# Tag format is the bare semver, e.g. "5.0.355" — no leading "v".
latest=$(gh api repos/buildbuddy-io/bazel/releases/latest --jq '.tag_name')
echo "latest=$latest" >> "$GITHUB_OUTPUT"
if [ "$current" = "$latest" ]; then
echo "up_to_date=true" >> "$GITHUB_OUTPUT"
echo "Already on $current"
else
echo "up_to_date=false" >> "$GITHUB_OUTPUT"
echo "Update available: $current -> $latest"
fi
- name: Compute hashes
if: steps.check.outputs.up_to_date == 'false'
id: hashes
run: |
version="${{ steps.check.outputs.latest }}"
base="https://github.com/buildbuddy-io/bazel/releases/download/${version}"
# Naked binaries (not tarballs) per OS/arch.
for pair in \
"bazel-${version}-linux-arm64:aarch64_linux" \
"bazel-${version}-linux-x86_64:x86_64_linux" \
"bazel-${version}-darwin-arm64:aarch64_darwin" \
"bazel-${version}-darwin-x86_64:x86_64_darwin"; do
asset="${pair%%:*}"
key="${pair##*:}"
hash=$(nix-prefetch-url "${base}/${asset}" 2>/dev/null)
sri=$(nix hash convert --hash-algo sha256 --to sri "$hash")
echo "${key}=${sri}" >> "$GITHUB_OUTPUT"
echo "$asset -> $sri"
done
- name: Update default.nix
if: steps.check.outputs.up_to_date == 'false'
run: |
file="pkgs/bb/default.nix"
version="${{ steps.check.outputs.latest }}"
# Update version
sed -i "s/version = \"${{ steps.check.outputs.current }}\"/version = \"${version}\"/" "$file"
# Update hashes — match the URL line, then replace the hash on the
# following `hash = "sha256-..."` line. Each platform's URL contains
# its arch suffix, which we use as the discriminator.
sed -i '/bazel-[^"]*-linux-arm64";$/,/hash =/{s|hash = "sha256-[^"]*"|hash = "${{ steps.hashes.outputs.aarch64_linux }}"|;}' "$file"
sed -i '/bazel-[^"]*-linux-x86_64";$/,/hash =/{s|hash = "sha256-[^"]*"|hash = "${{ steps.hashes.outputs.x86_64_linux }}"|;}' "$file"
sed -i '/bazel-[^"]*-darwin-arm64";$/,/hash =/{s|hash = "sha256-[^"]*"|hash = "${{ steps.hashes.outputs.aarch64_darwin }}"|;}' "$file"
sed -i '/bazel-[^"]*-darwin-x86_64";$/,/hash =/{s|hash = "sha256-[^"]*"|hash = "${{ steps.hashes.outputs.x86_64_darwin }}"|;}' "$file"
echo "Updated $file to ${version}"
git diff "$file"
- name: Create PR
if: steps.check.outputs.up_to_date == 'false'
env:
GH_TOKEN: ${{ secrets.UPDATE_TOKEN }}
run: |
version="${{ steps.check.outputs.latest }}"
branch="auto/update-bb"
git checkout -B "$branch"
git add -A
git -c user.name="github-actions[bot]" \
-c user.email="41898282+github-actions[bot]@users.noreply.github.com" \
commit -m "chore(deps): update bb to ${version}"
git push -u origin "$branch" --force
# gh pr view matches merged/closed PRs too — only skip if truly open
pr_state=$(gh pr view "$branch" --json state -q '.state' 2>/dev/null || echo "NONE")
if [ "$pr_state" = "OPEN" ]; then
echo "PR already open for $branch, force-pushed update"
else
pr_url=$(gh pr create \
--title "chore(deps): update bb to ${version}" \
--body "Automated update of \`bb\` (BuildBuddy CLI) to \`${version}\`." \
--label "dependencies,automated" \
--head "$branch")
pr_number=$(gh pr view "$branch" --json number -q '.number')
gh pr merge "$pr_number" --auto --squash
fi
- name: Report workflow status
if: always() && steps.checkout.outcome == 'success'
env:
GH_TOKEN: ${{ github.token }}
run: |
python3 .github/scripts/report-workflow-failure.py \
--workflow "${{ github.workflow }}" \
--status "${{ job.status }}" \
--run-url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"