Skip to content

Commit 8143a09

Browse files
committed
make publish-rust script work for program
1 parent a74bd7c commit 8143a09

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"programs:clean": "zx ./scripts/program/clean.mjs",
88
"programs:format": "zx ./scripts/program/format.mjs",
99
"programs:lint": "zx ./scripts/program/lint.mjs",
10+
"programs:publish": "zx ./scripts/publish-rust.mjs program",
1011
"solana:check": "zx ./scripts/check-solana-version.mjs",
1112
"solana:link": "zx ./scripts/link-solana-version.mjs",
1213
"generate": "pnpm generate:clients",
@@ -20,7 +21,7 @@
2021
"clients:js:test": "zx ./scripts/client/test-js.mjs",
2122
"clients:rust:format": "zx ./scripts/client/format-rust.mjs",
2223
"clients:rust:lint": "zx ./scripts/client/lint-rust.mjs",
23-
"clients:rust:publish": "zx ./scripts/publish-rust.mjs",
24+
"clients:rust:publish": "zx ./scripts/publish-rust.mjs client",
2425
"clients:rust:test": "zx ./scripts/client/test-rust.mjs",
2526
"template:upgrade": "zx ./scripts/upgrade-template.mjs"
2627
},

scripts/publish-rust.mjs

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,55 @@
11
#!/usr/bin/env zx
22
import 'zx/globals';
3-
import { cliArguments, getCargo, workingDirectory } from './utils.mjs';
3+
import { getCargo, workingDirectory } from './utils.mjs';
44

5+
class Publisher {
6+
libType;
7+
8+
constructor() {
9+
const lib = process.argv[3];
10+
if (!lib) {
11+
throw new Error('A library type must be provided.');
12+
}
13+
if (lib !== 'client' && lib !== 'program') {
14+
throw new Error('Invalid library type. Allowed values are "client" or "program".');
15+
}
16+
this.libType = lib;
17+
}
18+
19+
path() {
20+
if (this.libType === 'client') {
21+
return 'clients/rust';
22+
} else {
23+
return 'program';
24+
}
25+
}
26+
27+
message() {
28+
if (this.libType === 'client') {
29+
return 'Rust client';
30+
} else {
31+
return 'Program';
32+
}
33+
}
34+
35+
tagPrefix() {
36+
if (this.libType === 'client') {
37+
return 'rust';
38+
} else {
39+
return 'program';
40+
}
41+
}
42+
}
43+
44+
const publisher = new Publisher();
545
const dryRun = argv['dry-run'] ?? false;
6-
const [level] = cliArguments();
46+
const [level] = process.argv.slice(4);
747
if (!level) {
848
throw new Error('A version level — e.g. "path" — must be provided.');
949
}
1050

11-
// Go to the client directory and install the dependencies.
12-
cd(path.join(workingDirectory, 'clients', 'rust'));
51+
// Go to the directory and install the dependencies.
52+
cd(path.join(workingDirectory, publisher.path()));
1353

1454
// Publish the new version.
1555
const releaseArgs = dryRun
@@ -23,7 +63,7 @@ if (dryRun) {
2363
}
2464

2565
// Get the new version.
26-
const newVersion = getCargo(path.join('clients', 'rust')).package.version;
66+
const newVersion = getCargo(publisher.path()).package.version;
2767

2868
// Expose the new version to CI if needed.
2969
if (process.env.CI) {
@@ -34,7 +74,7 @@ if (process.env.CI) {
3474
await $`git reset --soft HEAD~1`;
3575

3676
// Commit the new version.
37-
await $`git commit -am "Publish Rust client v${newVersion}"`;
77+
await $`git commit -am "Publish ${publisher.message()} v${newVersion}"`;
3878

3979
// Tag the new version.
40-
await $`git tag -a rust@v${newVersion} -m "Rust client v${newVersion}"`;
80+
await $`git tag -a ${publisher.tagPrefix()}@v${newVersion} -m "${publisher.message()} v${newVersion}"`;

0 commit comments

Comments
 (0)