Skip to content

Commit a7041d4

Browse files
committed
isolate release credentials and process daemon publishing
1 parent b451fe3 commit a7041d4

7 files changed

Lines changed: 163 additions & 127 deletions

File tree

‎.github/CODEOWNERS‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ packages/plugin/src/gui/ @Hona
88

99
# CI and releases. Release jobs that hold secrets run only .github/workflows/release.yml and .github/release/,
1010
# which makes this path the release security boundary.
11-
/.github/ @anomalyco/releasers
11+
/.github/ @thdxr
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
umask 077
4+
cert="$RUNNER_TEMP/cert.p12"
5+
trap 'rm -f "$cert"' EXIT
6+
keychain_password=$(openssl rand -base64 32)
7+
printf '%s' "$APPLE_SIGNING_CERTIFICATE" | base64 --decode > "$cert"
8+
unset APPLE_SIGNING_CERTIFICATE
9+
security create-keychain -p "$keychain_password" build.keychain
10+
security set-keychain-settings -lut 21600 build.keychain
11+
security unlock-keychain -p "$keychain_password" build.keychain
12+
security import "$cert" -k build.keychain -P "" -T /usr/bin/codesign -T /usr/bin/security -T /usr/bin/productsign
13+
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$keychain_password" build.keychain > /dev/null
14+
security list-keychains -d user -s build.keychain $(security list-keychains -d user | tr -d '"')
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
. "$(dirname "$0")/lib.sh"
3+
4+
version=${GITHUB_REF_NAME#process-daemon-v}
5+
[[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+([+-][0-9A-Za-z.-]+)?$ ]] || die 'Invalid daemon version'
6+
registry=https://registry.npmjs.org
7+
# Validate every package before the first write. Publish the dispatcher last.
8+
packages=(pty-darwin-{arm64,x64} pty-linux-{arm64,x64}-{gnu,musl} pty-win32-{arm64,x64} pty)
9+
for package in "${packages[@]}"; do
10+
file="$1/opencode-$package-$version.tgz"
11+
tar -xOzf "$file" package/package.json | jq -es --arg name "@opencode/$package" --arg version "$version" '
12+
length == 1 and (.[0] | .name == $name and .version == $version and
13+
((.publishConfig // {}) | del(.access) == {}))' >/dev/null || die "Unexpected manifest for $package"
14+
done
15+
for package in "${packages[@]}"; do
16+
if ! npm view --registry="$registry" "@opencode/$package@$version" version >/dev/null 2>&1; then
17+
npm publish --registry="$registry" --ignore-scripts --access public --provenance "$1/opencode-$package-$version.tgz"
18+
fi
19+
done

‎.github/release/tag-release.sh‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
. "$(dirname "$0")/lib.sh"
66

77
tag="v$OPENCODE_VERSION"
8+
if ! dry_run; then
9+
umask 077
10+
ssh_dir=$(mktemp -d)
11+
trap 'rm -rf "$ssh_dir"' EXIT
12+
printf '%s\n' "$RELEASE_TAG_KEY" > "$ssh_dir/key"
13+
unset RELEASE_TAG_KEY
14+
echo 'github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl' > "$ssh_dir/known_hosts"
15+
export GIT_SSH_COMMAND="ssh -i $ssh_dir/key -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$ssh_dir/known_hosts"
16+
git remote set-url origin git@github.com:anomalyco/opencode.git
17+
fi
818
# @opencode/pty is versioned separately, by process-daemon-v<version> tags.
919
git ls-files -z -- '*package.json' bun.lock ':!packages/process-daemon/**' | xargs -0 sed -i -E "s/\"version\": \"[^\"]+\"/\"version\": \"$OPENCODE_VERSION\"/g"
1020

@@ -37,5 +47,5 @@ if [ -n "$existing" ]; then
3747
echo "sha=$existing" >> "$GITHUB_OUTPUT"
3848
exit 0
3949
fi
40-
git push -q origin "HEAD:refs/tags/$tag"
50+
if ! dry_run; then git push -q origin "HEAD:refs/tags/$tag"; fi
4151
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"

‎.github/release/with-secrets.sh‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
# Fetch only this command's named secrets; keep credentials out of its environment.
3+
. "$(dirname "$0")/lib.sh"
4+
set +x
5+
while [[ $# -gt 0 && $1 != -- ]]; do
6+
name=${1%%=*} id=${1#*=}
7+
[[ $name =~ ^[A-Z][A-Z0-9_]*$ && $id != "$1" && -n $id ]] || die 'Expected NAME=secret-id'
8+
if ! dry_run; then
9+
value=$(aws secretsmanager get-secret-value --region us-east-1 --secret-id "$id" --query SecretString --output text)
10+
[[ -n $value && $value != None ]] || die "Empty secret: $id"
11+
while IFS= read -r line; do
12+
[[ -z $line ]] || printf '::add-mask::%s\n' "${line//%/%25}"
13+
done <<< "$value"
14+
export "$name=$value"
15+
fi
16+
shift
17+
done
18+
[[ ${1:-} == -- && $# -gt 1 ]] || die 'Expected -- command'
19+
shift
20+
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN value
21+
exec "$@"

‎.github/workflows/release-process-daemon.yml‎

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,11 @@ jobs:
246246
path: packages/process-daemon/dist/*.tar.gz
247247
if-no-files-found: error
248248

249-
release:
249+
package:
250250
needs: [checks, build, build-windows]
251251
runs-on: ubuntu-22.04
252-
permissions:
253-
contents: write
254-
id-token: write
255-
attestations: write
252+
outputs:
253+
digest: ${{ steps.upload.outputs.digest }}
256254
env:
257255
PROTOCOL_VERSION: ${{ needs.checks.outputs.protocol }}
258256
steps:
@@ -261,8 +259,6 @@ jobs:
261259
with:
262260
node-version: "24"
263261
registry-url: https://registry.npmjs.org
264-
- name: Install npm with trusted publishing support
265-
run: npm install --global npm@^11.5.1
266262
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
267263
with:
268264
path: packages/process-daemon/dist
@@ -297,35 +293,68 @@ jobs:
297293
npm pack --pack-destination "$temporary" dist/npm/opencode-pty-linux-x64-gnu dist/npm/opencode-pty >/dev/null
298294
npm install --prefix "$temporary" --ignore-scripts --no-package-lock --no-audit --no-fund "$temporary"/*.tgz
299295
test "$("$temporary/node_modules/.bin/opencode-pty" --version)" = "opencode-pty $(node -p 'require("./npm/package.json").version') (protocol $PROTOCOL_VERSION)"
296+
- name: Stage release files
297+
run: |
298+
mkdir -p "$RUNNER_TEMP/bundle/github" "$RUNNER_TEMP/bundle/npm"
299+
cp dist/*.tar.gz dist/release-manifest.json dist/SHA256SUMS "$RUNNER_TEMP/bundle/github/"
300+
for package in dist/npm/*; do
301+
npm pack --ignore-scripts --pack-destination "$RUNNER_TEMP/bundle/npm" "$(realpath "$package")"
302+
done
303+
# The upload action owns the outer SHA256SUMS; include the release checksums in it.
304+
mv "$RUNNER_TEMP/bundle/github/SHA256SUMS" "$RUNNER_TEMP/bundle/github/checksums.txt"
305+
- id: upload
306+
uses: ./.github/release/upload
307+
with:
308+
name: process-daemon-bundle
309+
path: ${{ runner.temp }}/bundle
310+
311+
release:
312+
needs: [checks, package]
313+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/process-daemon-v')
314+
runs-on: ubuntu-24.04
315+
environment: process-daemon-release
316+
permissions:
317+
contents: write
318+
id-token: write
319+
attestations: write
320+
defaults:
321+
run:
322+
working-directory: .
323+
env:
324+
PROTOCOL_VERSION: ${{ needs.checks.outputs.protocol }}
325+
steps:
326+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
327+
with:
328+
sparse-checkout: /.github/release/
329+
sparse-checkout-cone-mode: false
330+
persist-credentials: false
331+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0; caching opt-in
332+
with:
333+
node-version: '24.11.0'
334+
- uses: ./.github/release/download
335+
with:
336+
pattern: process-daemon-bundle
337+
digests: process-daemon-bundle=${{ needs.package.outputs.digest }}
338+
require-digests: 'true'
300339
- uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
301-
if: startsWith(github.ref, 'refs/tags/process-daemon-v')
302340
with:
303-
subject-checksums: packages/process-daemon/dist/SHA256SUMS
341+
subject-path: |
342+
${{ runner.temp }}/in/process-daemon-bundle/github/*.tar.gz
343+
${{ runner.temp }}/in/process-daemon-bundle/github/release-manifest.json
304344
# The monorepo's Latest release drives OpenCode's own update paths, so this release must never become
305345
# Latest. It is drafted first because immutable releases lock assets once published.
306346
- name: Publish release
307-
if: startsWith(github.ref, 'refs/tags/process-daemon-v')
308347
env:
309348
GH_TOKEN: ${{ github.token }}
310349
run: |
350+
cd "$RUNNER_TEMP/in/process-daemon-bundle/github"
351+
mv checksums.txt SHA256SUMS
311352
version="${GITHUB_REF_NAME#process-daemon-v}"
312353
gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1 ||
313354
gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --draft --verify-tag --latest=false \
314355
--title "process-daemon v$version" \
315356
--notes "opencode-pty $version (protocol $PROTOCOL_VERSION) from packages/process-daemon, published to npm as @opencode/pty@$version."
316-
gh release upload "$GITHUB_REF_NAME" dist/*.tar.gz dist/SHA256SUMS dist/release-manifest.json --clobber --repo "$GITHUB_REPOSITORY"
357+
gh release upload "$GITHUB_REF_NAME" ./*.tar.gz SHA256SUMS release-manifest.json --clobber --repo "$GITHUB_REPOSITORY"
317358
gh release edit "$GITHUB_REF_NAME" --draft=false --latest=false --repo "$GITHUB_REPOSITORY"
318359
- name: Publish npm packages
319-
if: startsWith(github.ref, 'refs/tags/process-daemon-v')
320-
run: |
321-
version="${GITHUB_REF_NAME#process-daemon-v}"
322-
for package in dist/npm/opencode-pty-*; do
323-
name="$(node -p 'require(process.argv[1]).name' "$(realpath "$package/package.json")")"
324-
if ! npm view "$name@$version" version >/dev/null 2>&1; then
325-
npm publish "$package" --access public --provenance
326-
fi
327-
done
328-
name="@opencode/pty"
329-
if ! npm view "$name@$version" version >/dev/null 2>&1; then
330-
npm publish dist/npm/opencode-pty --access public --provenance
331-
fi
360+
run: bash .github/release/publish-process-daemon.sh "$RUNNER_TEMP/in/process-daemon-bundle/npm"

0 commit comments

Comments
 (0)