Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
CI: Add automated publish job
#### 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
  • Loading branch information
joncinque committed Mar 6, 2025
commit 02155207379d429f395c1d5d6b0860eb93bfbe49
29 changes: 7 additions & 22 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,6 @@ jobs:
- name: Run cargo-audit
run: pnpm rust:audit

semver_rust:
name: Check semver Rust
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup
with:
cargo-cache-key: cargo-semver

- name: Install cargo-audit
uses: taiki-e/install-action@v2
with:
tool: cargo-semver-checks

- name: Run semver checks
run: pnpm rust:semver

spellcheck_rust:
name: Spellcheck Rust
runs-on: ubuntu-latest
Expand Down Expand Up @@ -214,7 +194,7 @@ jobs:
test_program:
name: Test Program
runs-on: ubuntu-latest
needs: format_and_lint_program
needs: build_program
steps:
- name: Git Checkout
uses: actions/checkout@v4
Expand All @@ -223,7 +203,12 @@ jobs:
uses: ./.github/actions/setup
with:
cargo-cache-key: cargo-test-program
solana: true

- name: Restore Program Builds
uses: actions/cache/restore@v4
with:
path: ./**/*.so
key: ${{ runner.os }}-builds-${{ github.sha }}

- name: Test
run: pnpm programs:test
122 changes: 0 additions & 122 deletions .github/workflows/publish-rust-client.yml

This file was deleted.

140 changes: 140 additions & 0 deletions .github/workflows/publish-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
name: Publish Rust Crate

on:
workflow_dispatch:
inputs:
package_path:
description: Path to directory with package to release
required: true
default: 'clients/rust'
type: choice
options:
- clients/rust
- interface
- program
- p-token
level:
description: Level
required: true
default: patch
type: choice
options:
- patch
- minor
- major
dry_run:
description: Dry run
required: true
default: true
type: boolean
create_release:
description: Create a GitHub release
required: true
type: boolean
default: true

jobs:
test:
name: Test Rust Crate
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup
with:
clippy: true
rustfmt: true
solana: true
cargo-cache-key: cargo-test-publish-${{ inputs.package_path }}
cargo-cache-fallback-key: cargo-test-publish

- name: Install cargo-audit
uses: taiki-e/install-action@v2
with:
tool: cargo-semver-checks

- name: Format
run: pnpm zx ./scripts/rust/format.mjs "${{ inputs.package_path }}"

- name: Lint
run: pnpm zx ./scripts/rust/lint.mjs "${{ inputs.package_path }}"

- name: Build programs
run: pnpm programs:build

- name: Test
run: pnpm zx ./scripts/rust/test.mjs "${{ inputs.package_path }}"

- name: Check semver
run: pnpm rust:semver ${{ inputs.package_path }} --release-type ${{ inputs.level }}

publish:
name: Publish Rust Crate
runs-on: ubuntu-latest
needs: test
permissions:
contents: write
steps:
- name: Git Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.ANZA_TEAM_PAT }}
fetch-depth: 0 # get the whole history for git-cliff

- name: Setup Environment
uses: ./.github/actions/setup
with:
cargo-cache-key: cargo-publish-${{ inputs.package_path }}
cargo-cache-fallback-key: cargo-publish

- name: Install Cargo Release
run: which cargo-release || cargo install cargo-release

- name: Ensure CARGO_REGISTRY_TOKEN variable is set
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
if: ${{ env.CARGO_REGISTRY_TOKEN == '' }}
run: |
echo "The CARGO_REGISTRY_TOKEN secret variable is not set"
echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"."
exit 1

- name: Set Git Author
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"

- name: Publish Crate
id: publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
if [ "${{ inputs.dry_run }}" == "true" ]; then
OPTIONS="--dry-run"
else
OPTIONS=""
fi

pnpm rust:publish "${{ inputs.package_path }}" "${{ inputs.level }}" $OPTIONS

- name: Generate a changelog
if: github.event.inputs.create_release == 'true'
uses: orhun/git-cliff-action@v3
with:
config: "scripts/cliff.toml"
args: |
"${{ steps.publish.outputs.old_git_tag }}"..main
--include-path "${{ inputs.package_path }}/**"
--github-repo "${{ github.repository }}"
env:
OUTPUT: TEMP_CHANGELOG.md
GITHUB_REPO: ${{ github.repository }}

- name: Create GitHub release
if: github.event.inputs.create_release == 'true' && github.event.inputs.dry_run != 'true'
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.publish.outputs.new_git_tag }}
bodyFile: TEMP_CHANGELOG.md
11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ check-cfg = [
]

[workspace.metadata.cli]
solana = "2.1.0"
solana = "2.2.0"

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

[workspace.metadata.spellcheck]
config = "scripts/spellcheck.toml"

[workspace.metadata.release]
pre-release-commit-message = "Publish {{crate_name}} v{{version}}"
tag-message = "Publish {{crate_name}} v{{version}}"
consolidate-commits = false
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"programs:build": "zx ./scripts/rust/build-sbf.mjs program",
"programs:format": "zx ./scripts/rust/format.mjs program",
"programs:lint": "zx ./scripts/rust/lint.mjs program",
"programs:test": "zx ./scripts/rust/test-sbf.mjs program",
"programs:test": "zx ./scripts/rust/test.mjs program",
"solana:check": "zx ./scripts/check-solana-version.mjs",
"solana:link": "zx ./scripts/link-solana-version.mjs",
"generate": "pnpm generate:clients",
Expand All @@ -18,11 +18,11 @@
"clients:js:test": "zx ./scripts/js/test.mjs",
"clients:rust:format": "zx ./scripts/rust/format.mjs clients/rust",
"clients:rust:lint": "zx ./scripts/rust/lint.mjs clients/rust",
"clients:rust:publish": "zx ./scripts/rust/publish.mjs clients/rust",
"clients:rust:test": "zx ./scripts/rust/test-sbf.mjs clients/rust",
"clients:rust:test": "zx ./scripts/rust/test.mjs clients/rust",
"template:upgrade": "zx ./scripts/upgrade-template.mjs",
"rust:spellcheck": "cargo spellcheck --code 1",
"rust:audit": "zx ./scripts/rust/audit.mjs",
"rust:publish": "zx ./scripts/rust/publish.mjs",
"rust:semver": "cargo semver-checks"
},
"devDependencies": {
Expand Down
2 changes: 0 additions & 2 deletions program/tests/assert_instruction_count.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(feature = "test-sbf")]

mod setup;

use {
Expand Down
2 changes: 0 additions & 2 deletions program/tests/close_account.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(feature = "test-sbf")]

mod setup;

use {
Expand Down
2 changes: 0 additions & 2 deletions program/tests/processor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(feature = "test-sbf")]

//! Program state processor tests

use {
Expand Down
2 changes: 0 additions & 2 deletions program/tests/setup.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(feature = "test-sbf")]

use {
solana_sdk::{
account::Account as SolanaAccount, program_pack::Pack, pubkey::Pubkey, rent::Rent,
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.81.0"
channel = "1.84.1"
Loading