Skip to content

Commit ec9c0f9

Browse files
committed
feat: backport CI release process
1 parent 1ebbe58 commit ec9c0f9

43 files changed

Lines changed: 941 additions & 134 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/scripts/publish-npmjs.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env bash
2+
3+
set -xeuo pipefail
4+
5+
publish() {
6+
local dir="$1"
7+
pushd "$dir" >/dev/null
8+
9+
local name version
10+
name="$(node -p "require('./package.json').name")"
11+
version="$(node -p "require('./package.json').version")"
12+
13+
# We still build the package even if we don't publish it, as yarn workspace will
14+
# use the local version of each package, and if it's unbuilt then any subsequent
15+
# build will error out due to missing files.
16+
yarn --frozen-lockfile
17+
local dirname
18+
dirname="$(basename "$dir")"
19+
if [[ "$dirname" == spl-* ]]; then
20+
yarn build:npm
21+
else
22+
yarn build
23+
fi
24+
25+
if npm view "${name}@${version}" version >/dev/null 2>&1; then
26+
echo "The package $dir is already up to date, skipping"
27+
popd >/dev/null
28+
return 0
29+
fi
30+
31+
local publish_args=()
32+
# If version looks like X.Y.Z-<something> (e.g. 1.0.0-rc.2), publish under dist-tag "next"
33+
if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+-.+ ]]; then
34+
publish_args+=(--tag next)
35+
fi
36+
37+
if [[ "${DRY_RUN:-false}" == "true" ]]; then
38+
echo "Publishing $dir (${name}@${version}) as a dry-run"
39+
npm publish "${publish_args[@]}" --dry-run
40+
else
41+
echo "Publishing $dir (${name}@${version})"
42+
npm publish "${publish_args[@]}" --provenance --access public
43+
fi
44+
45+
popd >/dev/null
46+
}
47+
48+
base="ts/packages"
49+
50+
publish "$base/borsh"
51+
publish "$base/anchor-errors"
52+
publish "$base/anchor"
53+
#publish "$base/spl-associated-token-account"
54+
#publish "$base/spl-binary-option"
55+
#publish "$base/spl-binary-oracle-pair"
56+
#publish "$base/spl-feature-proposal"
57+
#publish "$base/spl-governance"
58+
#publish "$base/spl-memo"
59+
#publish "$base/spl-name-service"
60+
#publish "$base/spl-record"
61+
#publish "$base/spl-stake-pool"
62+
#publish "$base/spl-stateless-asks"
63+
publish "$base/spl-token"
64+
#publish "$base/spl-token-lending"
65+
#publish "$base/spl-token-swap"

.github/workflows/build-cli.yaml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Build CLI
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
dry_run:
7+
description: "If true, use 'dry-run' as the version string instead of the tag"
8+
required: true
9+
type: boolean
10+
dist:
11+
description: "Directory name for distribution artifacts (e.g. dist-v1.2.3 or dist-dry-run)"
12+
required: true
13+
type: string
14+
15+
jobs:
16+
build-cli:
17+
name: Build binaries${{ inputs.dry_run && ' (dry-run)' || '' }} (${{matrix.os}})
18+
runs-on: ${{ matrix.os }}
19+
permissions:
20+
contents: read
21+
id-token: write
22+
attestations: write
23+
24+
strategy:
25+
matrix:
26+
target:
27+
- aarch64-apple-darwin
28+
- x86_64-unknown-linux-gnu
29+
- x86_64-apple-darwin
30+
- x86_64-pc-windows-msvc
31+
include:
32+
- target: aarch64-apple-darwin
33+
os: macos-latest
34+
35+
- target: x86_64-unknown-linux-gnu
36+
os: ubuntu-latest
37+
38+
- target: x86_64-apple-darwin
39+
os: macos-latest
40+
41+
- target: x86_64-pc-windows-msvc
42+
os: windows-latest
43+
44+
steps:
45+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
46+
47+
- uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
48+
with:
49+
toolchain: stable
50+
target: ${{ matrix.target }}
51+
52+
- name: Install dependencies (Linux)
53+
if: runner.os == 'Linux'
54+
run: sudo apt-get update && sudo apt-get install -y libudev-dev
55+
56+
# FIXME: The global system LLVM on GitHub is very outdated, and LTO causes link errors
57+
- name: Build release binary (macOS)
58+
if: runner.os == 'macOS'
59+
env:
60+
CARGO_PROFILE_RELEASE_LTO: "off"
61+
RUSTFLAGS: -C embed-bitcode=no
62+
run: cargo build --package anchor-cli --release --locked --target ${{ matrix.target }}
63+
64+
- name: Build release binary
65+
if: runner.os != 'macOS'
66+
run: cargo build --package anchor-cli --release --locked --target ${{ matrix.target }}
67+
68+
- name: Prepare
69+
id: prepare
70+
shell: bash
71+
run: |
72+
if [[ "${{ inputs.dry_run }}" == "true" ]]; then
73+
version="dry-run"
74+
else
75+
version=$(echo $GITHUB_REF_NAME | cut -dv -f2)
76+
fi
77+
ext=""
78+
[[ "${{ matrix.os }}" == windows-latest ]] && ext=".exe"
79+
80+
mkdir ${{ inputs.dist }}
81+
mv "target/${{ matrix.target }}/release/anchor$ext" ${{ inputs.dist }}/anchor-$version-${{ matrix.target }}$ext
82+
83+
echo "version=$version" >> $GITHUB_OUTPUT
84+
85+
- name: Attest build provenance
86+
# `id-token: write` is not granted for PRs from forks
87+
if: ${{ github.event.pull_request.head.repo.fork != true }}
88+
uses: actions/attest-build-provenance@96278af6caaf10aea03fd8d33a09a777ca52d62f # v3.2.0
89+
with:
90+
subject-path: ${{ inputs.dist }}/anchor-${{ steps.prepare.outputs.version }}-${{ matrix.target }}*
91+
92+
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
93+
with:
94+
name: anchor-${{ steps.prepare.outputs.version }}-${{ matrix.target }}
95+
path: ${{ inputs.dist }}
96+
overwrite: true
97+
retention-days: 1
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Prepare Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Version to bump to without the v[...] prefix (e.g. 1.0.0-rc.5)"
8+
required: true
9+
type: string
10+
create_ts_docs_pr:
11+
description: "Create a PR to publish TS docs for this version"
12+
required: true
13+
default: true
14+
type: boolean
15+
16+
permissions:
17+
contents: write
18+
19+
jobs:
20+
prepare-release-bump:
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Force fetch upstream tags
29+
run: git fetch --tags --force
30+
31+
- uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
32+
with:
33+
toolchain: stable
34+
35+
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
36+
with:
37+
node-version: "24"
38+
registry-url: "https://registry.npmjs.org"
39+
package-manager-cache: false
40+
41+
- name: Enable corepack (yarn)
42+
run: corepack enable
43+
44+
- uses: ./.github/actions/setup-solana/
45+
env:
46+
SOLANA_VERSION: "2.3.0"
47+
48+
- name: Install cargo-release
49+
run: cargo install cargo-release --version 1.1.1 --locked
50+
51+
- name: Bump version
52+
env:
53+
VERSION: ${{ inputs.version }}
54+
run: |
55+
set -xeou pipefail
56+
57+
./setup-tests.sh
58+
./bump-version.sh "$VERSION"
59+
60+
# I would love to automatically create a PR here, but GitHub does not allow triggering CI jobs
61+
# on automatically created PRs to prevent recursion
62+
- name: Create release bump branch
63+
env:
64+
VERSION: ${{ inputs.version }}
65+
run: |
66+
set -xeou pipefail
67+
68+
BRANCH="release-bump/$VERSION"
69+
70+
git config user.name "github-actions[bot]"
71+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
72+
73+
git checkout -b "$BRANCH"
74+
git add -A
75+
git commit -m "v$VERSION"
76+
git push --set-upstream origin "$BRANCH"
77+
78+
# I would love to automatically push this to the branch, but again, GitHub does not
79+
# allow for this.
80+
prepare-ts-docs:
81+
runs-on: ubuntu-latest
82+
needs: prepare-release-bump
83+
if: ${{ inputs.create_ts_docs_pr }}
84+
85+
steps:
86+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
87+
with:
88+
fetch-depth: 0
89+
90+
- name: Force fetch upstream tags
91+
run: git fetch --tags --force
92+
93+
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
94+
with:
95+
node-version: "24"
96+
registry-url: "https://registry.npmjs.org"
97+
package-manager-cache: false
98+
99+
- name: Enable corepack (yarn)
100+
run: corepack enable
101+
102+
- name: Generate TS docs
103+
run: |
104+
set -xeou pipefail
105+
106+
cd ts/packages/borsh && yarn --frozen-lockfile && yarn build && yarn link --force && cd ../../../
107+
cd ts/packages/anchor-errors && yarn --frozen-lockfile && yarn build && yarn link --force && cd ../../../
108+
cd ts/packages/anchor && yarn --frozen-lockfile && yarn build:node && yarn link && cd ../../../
109+
110+
cd ts/packages/anchor/
111+
yarn docs
112+
113+
- name: Create TS docs PR
114+
env:
115+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116+
VERSION: ${{ inputs.version }}
117+
run: |
118+
set -xeuo pipefail
119+
120+
DOCS_DIST="docs/src/.vuepress/dist"
121+
DOCS_TMP="$RUNNER_TEMP/ts-docs"
122+
BRANCH="ts-docs/$VERSION"
123+
124+
test -d "$DOCS_DIST"
125+
mkdir -p "$DOCS_TMP"
126+
cp -a "$DOCS_DIST"/. "$DOCS_TMP"/
127+
128+
git config user.name "github-actions[bot]"
129+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
130+
131+
git switch -c "$BRANCH" origin/gh-pages
132+
133+
find . -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
134+
cp -a "$DOCS_TMP"/. .
135+
136+
git add -A
137+
if git diff --cached --quiet; then
138+
echo "No TS docs changes to publish."
139+
else
140+
git commit -m "v$VERSION"
141+
git push --set-upstream origin "$BRANCH"
142+
fi

0 commit comments

Comments
 (0)