-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script and CI for publishing JS clients (#76)
- Loading branch information
1 parent
4adf466
commit 9039243
Showing
4 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-solana-program": patch | ||
--- | ||
|
||
Add script and CI workflow for publishing JS clients |
102 changes: 102 additions & 0 deletions
102
template/clients/js/.github/workflows/publish-js-client.yml.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
name: Publish JS Client | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
level: | ||
description: Version level | ||
required: true | ||
default: patch | ||
type: choice | ||
options: | ||
- patch | ||
- minor | ||
- major | ||
- prerelease | ||
- prepatch | ||
- preminor | ||
- premajor | ||
tag: | ||
description: NPM Tag (and preid for pre-releases) | ||
required: true | ||
type: string | ||
default: latest | ||
create_release: | ||
description: Create a GitHub release | ||
required: true | ||
type: boolean | ||
default: true | ||
|
||
jobs: | ||
test_js: | ||
name: Test JS client | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Git Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Environment | ||
uses: ./.github/actions/setup | ||
with: | ||
cargo-cache-key: cargo-programs | ||
solana: true | ||
{% if programFramework === 'anchor' %} | ||
anchor: true | ||
{% endif %} | ||
|
||
- name: Format JS Client | ||
run: pnpm clients:js:format | ||
|
||
- name: Lint JS Client | ||
run: pnpm clients:js:lint | ||
|
||
- name: Build Programs | ||
run: pnpm programs:build | ||
|
||
- name: Test JS Client | ||
run: pnpm clients:js:test | ||
|
||
publish_js: | ||
name: Publish JS client | ||
runs-on: ubuntu-latest | ||
needs: test_js | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Git Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Environment | ||
uses: ./.github/actions/setup | ||
|
||
- name: Ensure NPM_TOKEN variable is set | ||
env: | ||
token: {% raw %}${{ secrets.NPM_TOKEN }}{% endraw %} | ||
if: {% raw %}${{ env.token == '' }}{% endraw %} | ||
run: | | ||
echo "The NPM_TOKEN secret variable is not set" | ||
echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"." | ||
exit 1 | ||
|
||
- name: NPM Authentication | ||
run: pnpm config set '//registry.npmjs.org/:_authToken' "${NODE_AUTH_TOKEN}" | ||
env: | ||
NODE_AUTH_TOKEN: {% raw %}${{ secrets.NPM_TOKEN }}{% endraw %} | ||
|
||
- 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 JS Client | ||
id: publish | ||
run: pnpm clients:js:publish {% raw %}${{ inputs.level }} ${{ inputs.tag }}{% endraw %} | ||
|
||
- name: Push Commit and Tag | ||
run: git push origin --follow-tags | ||
|
||
- name: Create GitHub release | ||
if: github.event.inputs.create_release == 'true' | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
tag: {% raw %}js@v${{ steps.publish.outputs.new_version }}{% endraw %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env zx | ||
import 'zx/globals'; | ||
import { cliArguments, workingDirectory } from '../utils.mjs'; | ||
|
||
const [level, tag = 'latest'] = cliArguments(); | ||
if (!level) { | ||
throw new Error('A version level — e.g. "path" — must be provided.'); | ||
} | ||
|
||
// Go to the client directory and install the dependencies. | ||
cd(path.join(workingDirectory, 'clients', 'js')); | ||
await $`pnpm install`; | ||
|
||
// Update the version. | ||
const versionArgs = [ | ||
'--no-git-tag-version', | ||
...(level.startsWith('pre') ? [`--preid ${tag}`] : []), | ||
]; | ||
let { stdout } = await $`pnpm version ${level} ${versionArgs}`; | ||
const newVersion = stdout.slice(1).trim(); | ||
|
||
// Expose the new version to CI if needed. | ||
if (process.env.CI) { | ||
await $`echo "new_version=${newVersion}" >> $GITHUB_OUTPUT`; | ||
} | ||
|
||
// Publish the package. | ||
// This will also build the package before publishing (see prepublishOnly script). | ||
await $`pnpm publish --no-git-checks --tag ${tag}`; | ||
|
||
// Commit the new version. | ||
await $`git commit -am "Publish JS client v${newVersion}"`; | ||
|
||
// Tag the new version. | ||
await $`git tag -a js@v${newVersion} -m "JS client v${newVersion}"`; |