Skip to content

Commit 2f189b1

Browse files
authored
CI: Add automated publish job (#34)
#### Problem It's time to publish spl-token that uses all of the component crates to make downstream users happy, but there's no publish job on the repo. #### Summary of changes This PR is as bit of a grab-bag of changes, but they're all to make the automated publish job work. The changes contained are: * move semver check job to only run during publish * update publish script to be generic, copying from the libraries repo * update testing script to be generic for rust packages by not running `cargo test-sbf` and instead doing it by hand, like in token-2022 * rename testing script to `test.mjs` * remove `test-sbf` feature from spl-token tests * update solana tools / toolchain versions
1 parent c4689b1 commit 2f189b1

12 files changed

+179
-178
lines changed

Diff for: .github/workflows/main.yml

+7-22
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,6 @@ jobs:
8181
- name: Run cargo-audit
8282
run: pnpm rust:audit
8383

84-
semver_rust:
85-
name: Check semver Rust
86-
runs-on: ubuntu-latest
87-
steps:
88-
- name: Git Checkout
89-
uses: actions/checkout@v4
90-
91-
- name: Setup Environment
92-
uses: ./.github/actions/setup
93-
with:
94-
cargo-cache-key: cargo-semver
95-
96-
- name: Install cargo-audit
97-
uses: taiki-e/install-action@v2
98-
with:
99-
tool: cargo-semver-checks
100-
101-
- name: Run semver checks
102-
run: pnpm rust:semver
103-
10484
spellcheck_rust:
10585
name: Spellcheck Rust
10686
runs-on: ubuntu-latest
@@ -214,7 +194,7 @@ jobs:
214194
test_program:
215195
name: Test Program
216196
runs-on: ubuntu-latest
217-
needs: format_and_lint_program
197+
needs: build_program
218198
steps:
219199
- name: Git Checkout
220200
uses: actions/checkout@v4
@@ -223,7 +203,12 @@ jobs:
223203
uses: ./.github/actions/setup
224204
with:
225205
cargo-cache-key: cargo-test-program
226-
solana: true
206+
207+
- name: Restore Program Builds
208+
uses: actions/cache/restore@v4
209+
with:
210+
path: ./**/*.so
211+
key: ${{ runner.os }}-builds-${{ github.sha }}
227212

228213
- name: Test
229214
run: pnpm programs:test

Diff for: .github/workflows/publish-rust-client.yml

-122
This file was deleted.

Diff for: .github/workflows/publish-rust.yml

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: Publish Rust Crate
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
package_path:
7+
description: Path to directory with package to release
8+
required: true
9+
default: 'clients/rust'
10+
type: choice
11+
options:
12+
- clients/rust
13+
- interface
14+
- program
15+
- p-token
16+
level:
17+
description: Level
18+
required: true
19+
default: patch
20+
type: choice
21+
options:
22+
- patch
23+
- minor
24+
- major
25+
dry_run:
26+
description: Dry run
27+
required: true
28+
default: true
29+
type: boolean
30+
create_release:
31+
description: Create a GitHub release
32+
required: true
33+
type: boolean
34+
default: true
35+
36+
jobs:
37+
test:
38+
name: Test Rust Crate
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Git Checkout
42+
uses: actions/checkout@v4
43+
44+
- name: Setup Environment
45+
uses: ./.github/actions/setup
46+
with:
47+
clippy: true
48+
rustfmt: true
49+
solana: true
50+
cargo-cache-key: cargo-test-publish-${{ inputs.package_path }}
51+
cargo-cache-fallback-key: cargo-test-publish
52+
53+
- name: Install cargo-audit
54+
uses: taiki-e/install-action@v2
55+
with:
56+
tool: cargo-semver-checks
57+
58+
- name: Format
59+
run: pnpm zx ./scripts/rust/format.mjs "${{ inputs.package_path }}"
60+
61+
- name: Lint
62+
run: pnpm zx ./scripts/rust/lint.mjs "${{ inputs.package_path }}"
63+
64+
- name: Build programs
65+
run: pnpm programs:build
66+
67+
- name: Test
68+
run: pnpm zx ./scripts/rust/test.mjs "${{ inputs.package_path }}"
69+
70+
- name: Check semver
71+
run: pnpm rust:semver ${{ inputs.package_path }} --release-type ${{ inputs.level }}
72+
73+
publish:
74+
name: Publish Rust Crate
75+
runs-on: ubuntu-latest
76+
needs: test
77+
permissions:
78+
contents: write
79+
steps:
80+
- name: Git Checkout
81+
uses: actions/checkout@v4
82+
with:
83+
token: ${{ secrets.ANZA_TEAM_PAT }}
84+
fetch-depth: 0 # get the whole history for git-cliff
85+
86+
- name: Setup Environment
87+
uses: ./.github/actions/setup
88+
with:
89+
cargo-cache-key: cargo-publish-${{ inputs.package_path }}
90+
cargo-cache-fallback-key: cargo-publish
91+
92+
- name: Install Cargo Release
93+
run: which cargo-release || cargo install cargo-release
94+
95+
- name: Ensure CARGO_REGISTRY_TOKEN variable is set
96+
env:
97+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
98+
if: ${{ env.CARGO_REGISTRY_TOKEN == '' }}
99+
run: |
100+
echo "The CARGO_REGISTRY_TOKEN secret variable is not set"
101+
echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"."
102+
exit 1
103+
104+
- name: Set Git Author
105+
run: |
106+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
107+
git config --global user.name "github-actions[bot]"
108+
109+
- name: Publish Crate
110+
id: publish
111+
env:
112+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
113+
run: |
114+
if [ "${{ inputs.dry_run }}" == "true" ]; then
115+
OPTIONS="--dry-run"
116+
else
117+
OPTIONS=""
118+
fi
119+
120+
pnpm rust:publish "${{ inputs.package_path }}" "${{ inputs.level }}" $OPTIONS
121+
122+
- name: Generate a changelog
123+
if: github.event.inputs.create_release == 'true'
124+
uses: orhun/git-cliff-action@v3
125+
with:
126+
config: "scripts/cliff.toml"
127+
args: |
128+
"${{ steps.publish.outputs.old_git_tag }}"..main
129+
--include-path "${{ inputs.package_path }}/**"
130+
--github-repo "${{ github.repository }}"
131+
env:
132+
OUTPUT: TEMP_CHANGELOG.md
133+
GITHUB_REPO: ${{ github.repository }}
134+
135+
- name: Create GitHub release
136+
if: github.event.inputs.create_release == 'true' && github.event.inputs.dry_run != 'true'
137+
uses: ncipollo/release-action@v1
138+
with:
139+
tag: ${{ steps.publish.outputs.new_git_tag }}
140+
bodyFile: TEMP_CHANGELOG.md

Diff for: Cargo.toml

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ check-cfg = [
1010
]
1111

1212
[workspace.metadata.cli]
13-
solana = "2.1.0"
13+
solana = "2.2.0"
1414

1515
# Specify Rust toolchains for rustfmt, clippy, and build.
1616
# Any unprovided toolchains default to stable.
1717
[workspace.metadata.toolchains]
18-
format = "nightly-2024-08-08"
19-
lint = "nightly-2024-08-08"
18+
format = "nightly-2024-11-22"
19+
lint = "nightly-2024-11-22"
2020

2121
[workspace.metadata.spellcheck]
2222
config = "scripts/spellcheck.toml"
23+
24+
[workspace.metadata.release]
25+
pre-release-commit-message = "Publish {{crate_name}} v{{version}}"
26+
tag-message = "Publish {{crate_name}} v{{version}}"
27+
consolidate-commits = false

Diff for: package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"programs:build": "zx ./scripts/rust/build-sbf.mjs program",
55
"programs:format": "zx ./scripts/rust/format.mjs program",
66
"programs:lint": "zx ./scripts/rust/lint.mjs program",
7-
"programs:test": "zx ./scripts/rust/test-sbf.mjs program",
7+
"programs:test": "zx ./scripts/rust/test.mjs program",
88
"solana:check": "zx ./scripts/check-solana-version.mjs",
99
"solana:link": "zx ./scripts/link-solana-version.mjs",
1010
"generate": "pnpm generate:clients",
@@ -18,11 +18,11 @@
1818
"clients:js:test": "zx ./scripts/js/test.mjs",
1919
"clients:rust:format": "zx ./scripts/rust/format.mjs clients/rust",
2020
"clients:rust:lint": "zx ./scripts/rust/lint.mjs clients/rust",
21-
"clients:rust:publish": "zx ./scripts/rust/publish.mjs clients/rust",
22-
"clients:rust:test": "zx ./scripts/rust/test-sbf.mjs clients/rust",
21+
"clients:rust:test": "zx ./scripts/rust/test.mjs clients/rust",
2322
"template:upgrade": "zx ./scripts/upgrade-template.mjs",
2423
"rust:spellcheck": "cargo spellcheck --code 1",
2524
"rust:audit": "zx ./scripts/rust/audit.mjs",
25+
"rust:publish": "zx ./scripts/rust/publish.mjs",
2626
"rust:semver": "cargo semver-checks"
2727
},
2828
"devDependencies": {

Diff for: program/tests/assert_instruction_count.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(feature = "test-sbf")]
2-
31
mod setup;
42

53
use {

Diff for: program/tests/close_account.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(feature = "test-sbf")]
2-
31
mod setup;
42

53
use {

Diff for: program/tests/processor.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(feature = "test-sbf")]
2-
31
//! Program state processor tests
42
53
use {

Diff for: program/tests/setup.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(feature = "test-sbf")]
2-
31
use {
42
solana_sdk::{
53
account::Account as SolanaAccount, program_pack::Pack, pubkey::Pubkey, rent::Rent,

Diff for: rust-toolchain.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[toolchain]
2-
channel = "1.81.0"
2+
channel = "1.84.1"

0 commit comments

Comments
 (0)