Skip to content

Commit 5b3095b

Browse files
authored
CI: Add publish job for all crates (#214)
#### Problem The auto-publish job only works with the rust client, but we need to publish the interface crate. #### Summary of changes Update the publish job for all Rust crates, add a publish script, all copied from token-2022. Remove the old scripts.
1 parent c92638c commit 5b3095b

File tree

5 files changed

+223
-163
lines changed

5 files changed

+223
-163
lines changed

.github/workflows/publish-rust-client.yml

Lines changed: 0 additions & 122 deletions
This file was deleted.

.github/workflows/publish-rust.yml

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
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+
level:
16+
description: Level
17+
required: true
18+
default: patch
19+
type: choice
20+
options:
21+
- patch
22+
- minor
23+
- major
24+
- rc
25+
- beta
26+
- alpha
27+
- release
28+
- version
29+
version:
30+
description: Version (used with level "version")
31+
required: false
32+
type: string
33+
dry_run:
34+
description: Dry run
35+
required: true
36+
default: true
37+
type: boolean
38+
create_release:
39+
description: Create a GitHub release
40+
required: true
41+
type: boolean
42+
default: true
43+
44+
jobs:
45+
test:
46+
name: Test Rust Crate
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: Git Checkout
50+
uses: actions/checkout@v4
51+
52+
- name: Setup Environment
53+
uses: ./.github/actions/setup
54+
with:
55+
clippy: true
56+
rustfmt: true
57+
solana: true
58+
cargo-cache-key: cargo-test-publish-${{ inputs.package_path }}
59+
cargo-cache-fallback-key: cargo-test-publish
60+
61+
- name: Format
62+
run: pnpm zx ./scripts/rust/format.mjs "${{ inputs.package_path }}"
63+
64+
- name: Lint
65+
run: pnpm zx ./scripts/rust/lint.mjs "${{ inputs.package_path }}"
66+
67+
- name: Build
68+
run: pnpm programs:build
69+
70+
- name: Test
71+
run: pnpm zx ./scripts/rust/test.mjs "${{ inputs.package_path }}"
72+
73+
semver:
74+
name: Check Semver
75+
runs-on: ubuntu-latest
76+
steps:
77+
- name: Git checkout
78+
uses: actions/checkout@v4
79+
80+
- name: Setup Environment
81+
uses: ./.github/actions/setup
82+
with:
83+
cargo-cache-key: cargo-publish-semver-${{ inputs.package_path }}
84+
cargo-cache-fallback-key: cargo-publish-semver
85+
86+
- name: Install cargo-semver-checks
87+
uses: taiki-e/install-action@v2
88+
with:
89+
90+
91+
- name: Set Git Author (required for cargo-release)
92+
run: |
93+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
94+
git config --global user.name "github-actions[bot]"
95+
96+
- name: Set Version
97+
run: |
98+
if [ "${{ inputs.level }}" == "version" ]; then
99+
LEVEL=${{ inputs.version }}
100+
else
101+
LEVEL=${{ inputs.level }}
102+
fi
103+
cargo release $LEVEL --manifest-path "${{ inputs.package_path }}/Cargo.toml" --no-tag --no-publish --no-push --no-confirm --execute
104+
105+
- name: Check semver
106+
run: pnpm rust:semver --manifest-path "${{ inputs.package_path }}/Cargo.toml"
107+
108+
publish:
109+
name: Publish Rust Crate
110+
runs-on: ubuntu-latest
111+
needs: [test, semver]
112+
permissions:
113+
contents: write
114+
steps:
115+
- name: Git Checkout
116+
uses: actions/checkout@v4
117+
with:
118+
token: ${{ secrets.ANZA_TEAM_PAT }}
119+
fetch-depth: 0 # get the whole history for git-cliff
120+
121+
- name: Setup Environment
122+
uses: ./.github/actions/setup
123+
with:
124+
cli: true
125+
cargo-cache-key: cargo-publish-${{ inputs.package_path }}
126+
cargo-cache-fallback-key: cargo-publish
127+
128+
- name: Install cargo-release
129+
uses: taiki-e/install-action@v2
130+
with:
131+
132+
133+
- name: Ensure CARGO_REGISTRY_TOKEN variable is set
134+
env:
135+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
136+
if: ${{ env.CARGO_REGISTRY_TOKEN == '' }}
137+
run: |
138+
echo "The CARGO_REGISTRY_TOKEN secret variable is not set"
139+
echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"."
140+
exit 1
141+
142+
- name: Set Git Author
143+
run: |
144+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
145+
git config --global user.name "github-actions[bot]"
146+
147+
- name: Publish Crate
148+
id: publish
149+
env:
150+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
151+
run: |
152+
if [ "${{ inputs.level }}" == "version" ]; then
153+
LEVEL=${{ inputs.version }}
154+
else
155+
LEVEL=${{ inputs.level }}
156+
fi
157+
158+
if [ "${{ inputs.dry_run }}" == "true" ]; then
159+
OPTIONS="--dry-run"
160+
else
161+
OPTIONS=""
162+
fi
163+
164+
pnpm rust:publish "${{ inputs.package_path }}" $LEVEL $OPTIONS
165+
166+
- name: Generate a changelog
167+
if: github.event.inputs.create_release == 'true'
168+
uses: orhun/git-cliff-action@v4
169+
with:
170+
config: "scripts/cliff.toml"
171+
args: ${{ steps.publish.outputs.old_git_tag }}..HEAD --include-path "${{ inputs.package_path }}/**" --github-repo ${{ github.repository }}
172+
env:
173+
OUTPUT: TEMP_CHANGELOG.md
174+
GITHUB_REPO: ${{ github.repository }}
175+
176+
- name: Create GitHub release
177+
if: github.event.inputs.create_release == 'true' && github.event.inputs.dry_run != 'true'
178+
uses: ncipollo/release-action@v1
179+
with:
180+
tag: ${{ steps.publish.outputs.new_git_tag }}
181+
bodyFile: TEMP_CHANGELOG.md

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
"clients:js:test": "zx ./scripts/client/test-js.mjs",
2424
"clients:rust:format": "zx ./scripts/client/format-rust.mjs",
2525
"clients:rust:lint": "zx ./scripts/client/lint-rust.mjs",
26-
"clients:rust:publish": "zx ./scripts/client/publish-rust.mjs",
2726
"clients:rust:test": "zx ./scripts/client/test-rust.mjs",
2827
"template:upgrade": "zx ./scripts/upgrade-template.mjs",
2928
"rust:spellcheck": "cargo spellcheck --code 1",
3029
"rust:audit": "zx ./scripts/rust/audit.mjs",
30+
"rust:publish": "zx ./scripts/rust/publish.mjs",
3131
"rust:semver": "cargo semver-checks"
3232
},
3333
"devDependencies": {

scripts/client/publish-rust.mjs

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)