Skip to content

Commit 5ff847e

Browse files
authored
publish: Update JS job for multiple packages (#89)
* publish: Update JS job for multiple packages #### Problem The repo now contains multiple JS packages, but the publish job only works with one of them. #### Summary of changes Update the publish script to get things in line with Rust: * take in a package path to test * change testing to work for any JS package * publish to either `@solana-program` or `@solana` * generate a changelog * Address feedback
1 parent 5d39f2d commit 5ff847e

File tree

4 files changed

+100
-27
lines changed

4 files changed

+100
-27
lines changed

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

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ name: Publish JS Client
33
on:
44
workflow_dispatch:
55
inputs:
6+
package_path:
7+
description: Path to directory with package to release
8+
required: true
9+
default: 'clients/js'
10+
type: choice
11+
options:
12+
- clients/js
13+
- clients/js-legacy
614
level:
715
description: Version level
816
required: true
@@ -28,8 +36,8 @@ on:
2836
default: true
2937

3038
jobs:
31-
test_js:
32-
name: Test JS client
39+
test:
40+
name: Test JS package
3341
runs-on: ubuntu-latest
3442
steps:
3543
- name: Git Checkout
@@ -39,42 +47,74 @@ jobs:
3947
uses: ./.github/actions/setup
4048
with:
4149
solana: true
50+
cargo-cache-key: cargo-js-test-publish-${{ inputs.package_path }}
51+
cargo-cache-fallback-key: cargo-js-test-publish
52+
53+
- name: Format
54+
run: pnpm zx ./scripts/js/format.mjs "${{ inputs.package_path }}"
55+
56+
- name: Lint
57+
run: pnpm zx ./scripts/js/lint.mjs "${{ inputs.package_path }}"
4258

43-
- name: Format JS Client
44-
run: pnpm clients:js:format
59+
- name: Build Token-2022
60+
run: pnpm programs:build
4561

46-
- name: Lint JS Client
47-
run: pnpm clients:js:lint
62+
- name: Build ElGamal Registry
63+
run: pnpm confidential-transfer:elgamal-registry:build
4864

49-
- name: Test JS Client
50-
run: pnpm clients:js:test
65+
- name: Test
66+
run: pnpm zx ./scripts/js/test.mjs "${{ inputs.package_path }}"
5167

52-
publish_js:
53-
name: Publish JS client
68+
publish:
69+
name: Publish JS package
5470
runs-on: ubuntu-latest
55-
needs: test_js
71+
needs: test
5672
permissions:
5773
contents: write
5874
steps:
5975
- name: Git Checkout
6076
uses: actions/checkout@v4
77+
with:
78+
token: ${{ secrets.ANZA_TEAM_PAT }}
79+
fetch-depth: 0 # get the whole history for git-cliff
6180

6281
- name: Setup Environment
6382
uses: ./.github/actions/setup
6483

65-
- name: Ensure NPM_TOKEN variable is set
84+
- name: Ensure SOLANA_NPM_TOKEN variable is set
6685
env:
67-
token: ${{ secrets.NPM_TOKEN }}
86+
token: ${{ secrets.SOLANA_NPM_TOKEN }}
6887
if: ${{ env.token == '' }}
6988
run: |
70-
echo "The NPM_TOKEN secret variable is not set"
89+
echo "The SOLANA_NPM_TOKEN secret variable is not set"
90+
echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"."
91+
exit 1
92+
93+
- name: Ensure SOLANA_PROGRAM_NPM_TOKEN variable is set
94+
env:
95+
token: ${{ secrets.SOLANA_PROGRAM_NPM_TOKEN }}
96+
if: ${{ env.token == '' }}
97+
run: |
98+
echo "The SOLANA_PROGRAM_NPM_TOKEN secret variable is not set"
7199
echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"."
72100
exit 1
73101
74102
- name: NPM Authentication
75-
run: pnpm config set '//registry.npmjs.org/:_authToken' "${NODE_AUTH_TOKEN}"
76103
env:
77-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
104+
SOLANA_NPM_TOKEN: ${{ secrets.SOLANA_NPM_TOKEN }}
105+
SOLANA_PROGRAM_NPM_TOKEN: ${{ secrets.SOLANA_PROGRAM_NPM_TOKEN }}
106+
shell: bash
107+
run: |
108+
cd "${{ inputs.package_path }}"
109+
org="$(jq '.name|split("/")|.[0]' package.json)"
110+
if [[ $org == "\"@solana-program\"" ]] then
111+
pnpm config set '//registry.npmjs.org/:_authToken' "${SOLANA_PROGRAM_NPM_TOKEN}"
112+
elif [[ $org == "\"@solana\"" ]] then
113+
pnpm config set '//registry.npmjs.org/:_authToken' "${SOLANA_NPM_TOKEN}"
114+
else
115+
echo "Unknown organization: $org"
116+
exit 1
117+
fi
78118
79119
- name: Set Git Author
80120
run: |
@@ -83,13 +123,27 @@ jobs:
83123
84124
- name: Publish JS Client
85125
id: publish
86-
run: pnpm clients:js:publish ${{ inputs.level }} ${{ inputs.tag }}
126+
run: pnpm js:publish "${{ inputs.package_path }}" ${{ inputs.level }} ${{ inputs.tag }}
87127

88128
- name: Push Commit and Tag
89129
run: git push origin --follow-tags
90130

131+
- name: Generate a changelog
132+
if: github.event.inputs.create_release == 'true'
133+
uses: orhun/git-cliff-action@v3
134+
with:
135+
config: "scripts/cliff.toml"
136+
args: |
137+
"${{ steps.publish.outputs.old_git_tag }}"..main
138+
--include-path "${{ inputs.package_path }}/**"
139+
--github-repo "${{ github.repository }}"
140+
env:
141+
OUTPUT: TEMP_CHANGELOG.md
142+
GITHUB_REPO: ${{ github.repository }}
143+
91144
- name: Create GitHub release
92145
if: github.event.inputs.create_release == 'true'
93146
uses: ncipollo/release-action@v1
94147
with:
95-
tag: js@v${{ steps.publish.outputs.new_version }}
148+
tag: ${{ steps.publish.outputs.new_git_tag }}
149+
bodyFile: TEMP_CHANGELOG.md

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"validator:stop": "zx ./scripts/stop-validator.mjs",
1616
"clients:js:format": "zx ./scripts/js/format.mjs clients/js",
1717
"clients:js:lint": "zx ./scripts/js/lint.mjs clients/js",
18-
"clients:js:publish": "zx ./scripts/js/publish.mjs",
1918
"clients:js:test": "zx ./scripts/js/test.mjs clients/js",
2019
"clients:js-legacy:format": "zx ./scripts/js/format.mjs clients/js-legacy",
2120
"clients:js-legacy:lint": "zx ./scripts/js/lint.mjs clients/js-legacy",
@@ -45,7 +44,8 @@
4544
"rust:spellcheck": "cargo spellcheck --code 1",
4645
"rust:audit": "zx ./scripts/rust/audit.mjs",
4746
"rust:semver": "cargo semver-checks",
48-
"rust:publish": "zx ./scripts/rust/publish.mjs"
47+
"rust:publish": "zx ./scripts/rust/publish.mjs",
48+
"js:publish": "zx ./scripts/js/publish.mjs"
4949
},
5050
"devDependencies": {
5151
"@codama/renderers-js": "^1.2.0",

scripts/js/publish.mjs

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

5-
const [level, tag = 'latest'] = cliArguments();
5+
const [folder, level, tag = 'latest'] = cliArguments();
6+
if (!folder) {
7+
throw new Error('A path to a directory with a JS package — e.g. "clients/js" — must be provided.');
8+
}
69
if (!level) {
7-
throw new Error('A version level — e.g. "path" — must be provided.');
10+
throw new Error('A version level — e.g. "patch" — must be provided.');
811
}
912

1013
// Go to the client directory and install the dependencies.
11-
cd(path.join(workingDirectory, 'clients', 'js'));
14+
cd(path.join(workingDirectory, folder));
1215
await $`pnpm install`;
1316

17+
const tagName = path.basename(folder);
18+
const packageJson = getPackageJson(folder);
19+
const oldVersion = packageJson.version;
20+
const oldGitTag = `${tagName}@v${oldVersion}`;
21+
1422
// Update the version.
1523
const versionArgs = [
1624
'--no-git-tag-version',
1725
...(level.startsWith('pre') ? [`--preid ${tag}`] : []),
1826
];
1927
let { stdout } = await $`pnpm version ${level} ${versionArgs}`;
2028
const newVersion = stdout.slice(1).trim();
29+
const newGitTag = `${tagName}@v${newVersion}`;
2130

2231
// Expose the new version to CI if needed.
2332
if (process.env.CI) {
24-
await $`echo "new_version=${newVersion}" >> $GITHUB_OUTPUT`;
33+
await $`echo "new_git_tag=${newGitTag}" >> $GITHUB_OUTPUT`;
34+
await $`echo "old_git_tag=${oldGitTag}" >> $GITHUB_OUTPUT`;
2535
}
2636

2737
// Publish the package.
2838
// This will also build the package before publishing (see prepublishOnly script).
2939
await $`pnpm publish --no-git-checks --tag ${tag}`;
3040

3141
// Commit the new version.
32-
await $`git commit -am "Publish JS client v${newVersion}"`;
42+
await $`git commit -am "Publish ${tagName} v${newVersion}"`;
3343

3444
// Tag the new version.
35-
await $`git tag -a js@v${newVersion} -m "JS client v${newVersion}"`;
45+
await $`git tag -a ${newGitTag} -m "${tagName} v${newVersion}"`;

scripts/utils.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,12 @@ export async function getInstalledSolanaVersion() {
125125
return '';
126126
}
127127
}
128+
129+
export function getPackageJson(folder) {
130+
return JSON.parse(
131+
fs.readFileSync(
132+
path.join(workingDirectory, folder ? folder : '.', 'package.json'),
133+
'utf8'
134+
)
135+
);
136+
}

0 commit comments

Comments
 (0)