Skip to content

Commit bb33c8f

Browse files
authored
CI: Update rust publish script to work for all packages (#81)
#### Problem The publish script only works with the rust client, but we have many rust packages in the repo that need to be deployed. #### Summary of changes Update the publish script to take in a folder, and update the workflow to align with the SPL version, which also generates a changelog.
1 parent 6ae9247 commit bb33c8f

File tree

5 files changed

+134
-42
lines changed

5 files changed

+134
-42
lines changed
Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
name: Publish Rust Client
1+
name: Publish Rust Crate
22

33
on:
44
workflow_dispatch:
55
inputs:
6+
package_path:
7+
description: Path to directory with package to release
8+
required: true
9+
type: string
610
level:
711
description: Level
812
required: true
@@ -18,7 +22,7 @@ on:
1822
- release
1923
- version
2024
version:
21-
description: Version
25+
description: Version (used with level "version")
2226
required: false
2327
type: string
2428
dry_run:
@@ -33,8 +37,8 @@ on:
3337
default: true
3438

3539
jobs:
36-
test_rust:
37-
name: Test Rust client
40+
test:
41+
name: Test Rust Crate
3842
runs-on: ubuntu-latest
3943
steps:
4044
- name: Git Checkout
@@ -43,37 +47,47 @@ jobs:
4347
- name: Setup Environment
4448
uses: ./.github/actions/setup
4549
with:
46-
cargo-cache-key: cargo-rust-client
4750
clippy: true
4851
rustfmt: true
4952
solana: true
53+
cli: true
54+
purge: true
55+
cargo-cache-key: cargo-test-publish-${{ inputs.package_path }}
56+
cargo-cache-fallback-key: cargo-test-publish
57+
58+
- name: Format
59+
run: pnpm zx ./scripts/rust/format.mjs "${{ inputs.package_path }}"
5060

51-
- name: Format Rust Client
52-
run: pnpm clients:rust:format
61+
- name: Lint
62+
run: pnpm zx ./scripts/rust/lint.mjs "${{ inputs.package_path }}"
5363

54-
- name: Lint Rust Client
55-
run: pnpm clients:rust:lint
64+
- name: Build Token-2022
65+
run: pnpm programs:build
5666

57-
- name: Test Rust Client
58-
run: pnpm clients:rust:test
67+
- name: Build ElGamal Registry
68+
run: pnpm confidential-transfer:elgamal-registry:build
5969

60-
publish_rust:
61-
name: Publish Rust Client
70+
- name: Test
71+
run: pnpm zx ./scripts/rust/test.mjs "${{ inputs.package_path }}"
72+
73+
publish:
74+
name: Publish Rust Crate
6275
runs-on: ubuntu-latest
63-
needs: test_rust
76+
needs: test
6477
permissions:
6578
contents: write
6679
steps:
6780
- name: Git Checkout
6881
uses: actions/checkout@v4
82+
with:
83+
fetch-depth: 0 # get the whole history for git-cliff
6984

7085
- name: Setup Environment
7186
uses: ./.github/actions/setup
7287
with:
73-
cargo-cache-key: cargo-publish-rust-client
74-
cargo-cache-fallback-key: cargo-rust-client
75-
clippy: true
76-
rustfmt: true
88+
cli: true
89+
cargo-cache-key: cargo-publish-${{ inputs.package_path }}
90+
cargo-cache-fallback-key: cargo-publish
7791

7892
- name: Install Cargo Release
7993
run: which cargo-release || cargo install cargo-release
@@ -92,7 +106,7 @@ jobs:
92106
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
93107
git config --global user.name "github-actions[bot]"
94108
95-
- name: Publish Rust Client
109+
- name: Publish Crate
96110
id: publish
97111
env:
98112
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
@@ -109,14 +123,25 @@ jobs:
109123
OPTIONS=""
110124
fi
111125
112-
pnpm clients:rust:publish $LEVEL $OPTIONS
126+
pnpm rust:publish "${{ inputs.package_path }}" $LEVEL $OPTIONS
113127
114-
- name: Push Commit and Tag
115-
if: github.event.inputs.dry_run != 'true'
116-
run: git push origin --follow-tags
128+
- name: Generate a changelog
129+
if: github.event.inputs.create_release == 'true'
130+
uses: orhun/git-cliff-action@v3
131+
with:
132+
config: "scripts/cliff.toml"
133+
args: |
134+
"${{ steps.publish.outputs.old_git_tag }}"..master
135+
--include-path "${{ inputs.package_path }}/**"
136+
--github-repo "${{ github.repository }}"
137+
env:
138+
OUTPUT: TEMP_CHANGELOG.md
139+
GITHUB_REPO: ${{ github.repository }}
117140

118141
- name: Create GitHub release
119142
if: github.event.inputs.create_release == 'true' && github.event.inputs.dry_run != 'true'
120143
uses: ncipollo/release-action@v1
121144
with:
122-
tag: rust@v${{ steps.publish.outputs.new_version }}
145+
tag: ${{ steps.publish.outputs.new_git_tag }}
146+
bodyFile: TEMP_CHANGELOG.md
147+
name: ${{ steps.publish.outputs.release_title }}

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@ lint = "nightly-2024-08-08"
4040

4141
[workspace.metadata.spellcheck]
4242
config = "scripts/spellcheck.toml"
43+
44+
[workspace.metadata.release]
45+
pre-release-commit-message = "Publish {{crate_name}} v{{version}}"
46+
tag-message = "Publish {{crate_name}} v{{version}}"
47+
consolidate-commits = false

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"template:upgrade": "zx ./scripts/upgrade-template.mjs",
4545
"rust:spellcheck": "cargo spellcheck --code 1",
4646
"rust:audit": "zx ./scripts/rust/audit.mjs",
47-
"rust:semver": "cargo semver-checks"
47+
"rust:semver": "cargo semver-checks",
48+
"rust:publish": "zx ./scripts/rust/publish.mjs"
4849
},
4950
"devDependencies": {
5051
"@codama/renderers-js": "^1.0.0",

scripts/cliff.toml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# git-cliff configuration file
2+
# https://git-cliff.org/docs/configuration
3+
#
4+
# Lines starting with "#" are comments.
5+
# Configuration options are organized into tables and keys.
6+
# See documentation for more information on available options.
7+
8+
[changelog]
9+
header = """
10+
## What's new
11+
"""
12+
# template for the changelog body
13+
# https://tera.netlify.app/docs
14+
body = """
15+
{% for group, commits in commits | group_by(attribute="group") %}\
16+
{% for commit in commits %}
17+
- {{ commit.message | upper_first | split(pat="\n") | first | trim }}\
18+
{% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif %}\
19+
{% endfor %}\
20+
{% endfor %}
21+
"""
22+
# remove the leading and trailing whitespace from the template
23+
trim = true
24+
footer = """
25+
"""
26+
postprocessors = [ ]
27+
[git]
28+
# parse the commits based on https://www.conventionalcommits.org
29+
conventional_commits = true
30+
# filter out the commits that are not conventional
31+
filter_unconventional = false
32+
# process each line of a commit as an individual commit
33+
split_commits = false
34+
# regex for preprocessing the commit messages
35+
commit_preprocessors = []
36+
# regex for parsing and grouping commits
37+
commit_parsers = [
38+
{ message = "^build\\(deps\\)", skip = true },
39+
{ message = "^build\\(deps-dev\\)", skip = true },
40+
{ message = "^ci", skip = true },
41+
{ body = ".*", group = "Changes" },
42+
]
43+
# protect breaking changes from being skipped due to matching a skipping commit_parser
44+
protect_breaking_commits = false
45+
# filter out the commits that are not matched by commit parsers
46+
filter_commits = false
47+
# glob pattern for matching git tags
48+
tag_pattern = "v[0-9]*"
49+
# regex for skipping tags
50+
skip_tags = ""
51+
# regex for ignoring tags
52+
ignore_tags = ""
53+
# sort the tags topologically
54+
topo_order = false
55+
# sort the commits inside sections by oldest/newest order
56+
sort_commits = "newest"
57+
# limit the number of commits included in the changelog.
58+
# limit_commits = 42

scripts/rust/publish.mjs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@ import 'zx/globals';
33
import { cliArguments, getCargo, workingDirectory } from '../utils.mjs';
44

55
const dryRun = argv['dry-run'] ?? false;
6-
const [level] = cliArguments();
6+
const [folder, level] = cliArguments();
7+
if (!folder) {
8+
throw new Error('A path to a directory with a Rust package — e.g. "clients/cli" — must be provided.');
9+
}
710
if (!level) {
8-
throw new Error('A version level — e.g. "path" — must be provided.');
11+
throw new Error('A version level — e.g. "patch" — must be provided.');
912
}
1013

11-
// Go to the client directory and install the dependencies.
12-
cd(path.join(workingDirectory, 'clients', 'rust'));
14+
cd(path.join(workingDirectory, folder));
15+
16+
const packageToml = getCargo(folder).package;
17+
const oldVersion = packageToml.version;
18+
const packageName = packageToml.name;
19+
const tagName = packageName.replace('spl-', '');
1320

14-
// Publish the new version.
21+
// Publish the new version, commit the repo change, tag it, and push it all.
1522
const releaseArgs = dryRun
1623
? []
17-
: ['--no-push', '--no-tag', '--no-confirm', '--execute'];
24+
: ['--tag-name', `${tagName}-v{{version}}`, '--no-confirm', '--execute'];
1825
await $`cargo release ${level} ${releaseArgs}`;
1926

2027
// Stop here if this is a dry run.
@@ -23,18 +30,14 @@ if (dryRun) {
2330
}
2431

2532
// Get the new version.
26-
const newVersion = getCargo(path.join('clients', 'rust')).package.version;
33+
const newVersion = getCargo(folder).package.version;
34+
const newGitTag = `${tagName}-v${newVersion}`;
35+
const oldGitTag = `${tagName}-v${oldVersion}`;
36+
const releaseTitle = `SPL ${tagName} - v${newVersion}`;
2737

2838
// Expose the new version to CI if needed.
2939
if (process.env.CI) {
30-
await $`echo "new_version=${newVersion}" >> $GITHUB_OUTPUT`;
40+
await $`echo "new_git_tag=${newGitTag}" >> $GITHUB_OUTPUT`;
41+
await $`echo "old_git_tag=${oldGitTag}" >> $GITHUB_OUTPUT`;
42+
await $`echo "release_title=${releaseTitle}" >> $GITHUB_OUTPUT`;
3143
}
32-
33-
// Soft reset the last commit so we can create our own commit and tag.
34-
await $`git reset --soft HEAD~1`;
35-
36-
// Commit the new version.
37-
await $`git commit -am "Publish Rust client v${newVersion}"`;
38-
39-
// Tag the new version.
40-
await $`git tag -a rust@v${newVersion} -m "Rust client v${newVersion}"`;

0 commit comments

Comments
 (0)