Repository navigation
262 lines (229 loc) · 9.12 KB
/
Copy pathcli-binaries.yml
File metadata and controls
262 lines (229 loc) · 9.12 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
# THREAT[TM-INF-027]: build only the immutable SHA exported by tag validation.
# Prebuilt CLI binaries — dispatched by release.yml after GitHub Release is created.
# GITHUB_TOKEN-created releases don't trigger `release: published` (anti-recursion).
# The Release workflow dispatches this workflow explicitly, same pattern as everruns/everruns.
name: Publish CLI Binaries
on:
workflow_dispatch:
inputs:
tag:
description: 'Release tag (e.g., v0.1.13)'
required: true
type: string
permissions:
contents: read
jobs:
validate-tag:
name: Validate release tag
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
tag: ${{ steps.validate.outputs.tag }}
sha: ${{ steps.source.outputs.sha }}
steps:
- name: Validate workflow input
id: validate
env:
INPUT_TAG: ${{ inputs.tag }}
run: |
if [[ ! "$INPUT_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: tag must match vMAJOR.MINOR.PATCH (for example, v0.1.13)." >&2
exit 1
fi
echo "tag=$INPUT_TAG" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ steps.validate.outputs.tag }}
fetch-depth: 0
- name: Verify tag source
id: source
env:
RELEASE_TAG: ${{ steps.validate.outputs.tag }}
run: |
TAG="$RELEASE_TAG"
git fetch --force origin main:refs/remotes/origin/main "refs/tags/$TAG:refs/tags/$TAG"
TAG_SHA=$(git rev-list -n 1 "$TAG")
# Validate and build this exact commit even if the tag later moves.
git checkout --detach "$TAG_SHA"
VERSION="${TAG#v}"
CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
if [ "$VERSION" != "$CARGO_VERSION" ]; then
echo "Error: tag $TAG does not match Cargo.toml version $CARGO_VERSION" >&2
exit 1
fi
if [ "$TAG_SHA" != "$GITHUB_SHA" ]; then
echo "Error: workflow ref $GITHUB_SHA does not match tag $TAG at $TAG_SHA" >&2
exit 1
fi
if ! git merge-base --is-ancestor "$TAG_SHA" origin/main; then
echo "Error: release tag $TAG ($TAG_SHA) is not reachable from origin/main" >&2
exit 1
fi
echo "Release tag $TAG verified at $TAG_SHA and reachable from origin/main"
echo "sha=$TAG_SHA" >> "$GITHUB_OUTPUT"
build:
name: Build CLI (${{ matrix.target }})
runs-on: ${{ matrix.runner }}
needs: validate-tag
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-apple-darwin
runner: macos-latest
archive: bashkit-aarch64-apple-darwin.tar.gz
- target: x86_64-apple-darwin
runner: macos-latest
archive: bashkit-x86_64-apple-darwin.tar.gz
- target: x86_64-unknown-linux-gnu
runner: ubuntu-latest
archive: bashkit-x86_64-unknown-linux-gnu.tar.gz
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.validate-tag.outputs.sha }}
persist-credentials: false
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@e081816240890017053eacbb1bdf337761dc5582 # 1.95.0
with:
targets: ${{ matrix.target }}
- name: Cache Rust
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
with:
shared-key: "cli-${{ matrix.target }}"
- name: Build CLI binary
run: cargo build --release --target ${{ matrix.target }} -p bashkit-cli --no-default-features
- name: Package binary
run: |
cd target/${{ matrix.target }}/release
tar czf "$GITHUB_WORKSPACE/${{ matrix.archive }}" bashkit
cd "$GITHUB_WORKSPACE"
shasum -a 256 "${{ matrix.archive }}" > "${{ matrix.archive }}.sha256"
- name: Upload to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: ${{ needs.validate-tag.outputs.tag }}
run: |
gh release upload "$RELEASE_TAG" \
"${{ matrix.archive }}" \
"${{ matrix.archive }}.sha256" \
--clobber
update-homebrew:
name: Update Homebrew formula
needs: [validate-tag, build]
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Download SHA256 checksums from release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: ${{ needs.validate-tag.outputs.tag }}
run: |
TAG="$RELEASE_TAG"
for target in aarch64-apple-darwin x86_64-apple-darwin x86_64-unknown-linux-gnu; do
gh release download "$TAG" \
--repo "${{ github.repository }}" \
--pattern "bashkit-${target}.tar.gz.sha256"
done
- name: Generate Homebrew formula
env:
RELEASE_TAG: ${{ needs.validate-tag.outputs.tag }}
run: |
TAG="$RELEASE_TAG"
# Validate checksum files exist and are non-empty
for f in bashkit-aarch64-apple-darwin.tar.gz.sha256 \
bashkit-x86_64-apple-darwin.tar.gz.sha256 \
bashkit-x86_64-unknown-linux-gnu.tar.gz.sha256; do
if [[ ! -s "$f" ]]; then
echo "Error: checksum file '$f' is missing or empty." >&2
exit 1
fi
done
SHA_ARM64=$(awk '{print $1}' bashkit-aarch64-apple-darwin.tar.gz.sha256)
SHA_X86_64_MACOS=$(awk '{print $1}' bashkit-x86_64-apple-darwin.tar.gz.sha256)
SHA_LINUX=$(awk '{print $1}' bashkit-x86_64-unknown-linux-gnu.tar.gz.sha256)
for var in SHA_ARM64 SHA_X86_64_MACOS SHA_LINUX; do
if [[ -z "${!var}" ]]; then
echo "Error: extracted $var is empty." >&2
exit 1
fi
done
BASE_URL="${{ github.server_url }}/${{ github.repository }}/releases/download/${TAG}"
cat > bashkit.rb <<FORMULA
# typed: false
# frozen_string_literal: true
class Bashkit < Formula
desc "Virtual bash interpreter with sandboxed execution"
homepage "${{ github.server_url }}/${{ github.repository }}"
license "Apache-2.0"
on_macos do
if Hardware::CPU.arm?
url "${BASE_URL}/bashkit-aarch64-apple-darwin.tar.gz"
sha256 "${SHA_ARM64}"
else
url "${BASE_URL}/bashkit-x86_64-apple-darwin.tar.gz"
sha256 "${SHA_X86_64_MACOS}"
end
end
on_linux do
depends_on arch: :x86_64
url "${BASE_URL}/bashkit-x86_64-unknown-linux-gnu.tar.gz"
sha256 "${SHA_LINUX}"
end
def install
bin.install "bashkit"
end
test do
assert_match version.to_s, shell_output("#{bin}/bashkit --version")
end
end
FORMULA
# Remove leading whitespace from heredoc
sed -i 's/^ //' bashkit.rb
echo "Generated formula:"
cat bashkit.rb
- name: Install Doppler CLI
uses: dopplerhq/cli-action@4819d808ab99e5cde19a0637a16536a4038fad73 # v4
- name: Push formula to homebrew-tap
env:
DOPPLER_TOKEN: ${{ secrets.DOPPLER_TOKEN }}
RELEASE_TAG: ${{ needs.validate-tag.outputs.tag }}
run: |
TAG="$RELEASE_TAG"
VERSION="${TAG#v}"
# Fetch the homebrew-tap PAT from Doppler. This token is a
# fine-grained PAT scoped to `everruns/homebrew-tap` only
# (Contents: read+write, Metadata: read), so a leak cannot
# touch the main bashkit repo.
# Register the mask before the value can reach any log line: an
# `set -x` or error trace between fetch and mask would print it.
GH_PAT=$(doppler secrets get HOMEBREW_TAP_GITHUB_TOKEN --plain)
echo "::add-mask::$GH_PAT"
export GH_PAT
# Use askpass to avoid embedding token in clone/push URLs or logs
ASKPASS_SCRIPT=$(mktemp)
cat > "$ASKPASS_SCRIPT" <<'EOF'
#!/usr/bin/env sh
case "$1" in
*Username*) echo "x-access-token" ;;
*Password*) echo "$GH_PAT" ;;
esac
EOF
chmod 700 "$ASKPASS_SCRIPT"
export GIT_ASKPASS="$ASKPASS_SCRIPT"
export GIT_TERMINAL_PROMPT=0
trap 'rm -f "$ASKPASS_SCRIPT"; unset GH_PAT' EXIT
# Clone the tap repo
git clone "https://github.com/everruns/homebrew-tap.git" tap
cp bashkit.rb tap/Formula/bashkit.rb
cd tap
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/bashkit.rb
git diff --cached --quiet && echo "No changes to commit" && exit 0
git commit -m "bashkit ${VERSION}"
git push origin main