Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify Rust publish scripts #26

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
name: Publish Rust Client
name: Publish Rust

on:
workflow_dispatch:
inputs:
lib_type:
description: Library Type
required: true
type: choice
options:
- client
- program
level:
description: Level
required: true
Expand Down Expand Up @@ -34,7 +41,7 @@ on:

jobs:
test_rust:
name: Test Rust client
name: Test Rust
runs-on: ubuntu-latest
steps:
- name: Git Checkout
Expand All @@ -43,25 +50,41 @@ jobs:
- name: Setup Environment
uses: ./.github/actions/setup
with:
cargo-cache-key: cargo-rust-client
cargo-cache-key: ${{ inputs.lib_type == 'client' && 'cargo-rust-client' || 'cargo-programs' }}
clippy: true
rustfmt: true
solana: true

- name: Format Rust Client
run: pnpm clients:rust:format
- name: Format
run: |
if [ "${{ inputs.lib_type }}" == "client" ]; then
pnpm clients:rust:format
else
pnpm programs:format
fi

- name: Lint Rust Client
run: pnpm clients:rust:lint
- name: Lint
run: |
if [ "${{ inputs.lib_type }}" == "client" ]; then
pnpm clients:rust:lint
else
pnpm programs:lint
fi

- name: Build Programs
- name: Build Program
if: ${{ inputs.lib_type == 'client' }}
run: pnpm programs:build

- name: Test Rust Client
run: pnpm clients:rust:test
- name: Test
run: |
if [ "${{ inputs.lib_type }}" == "client" ]; then
pnpm clients:rust:test
else
pnpm programs:test
fi

publish_rust:
name: Publish Rust Client
name: Publish Rust
runs-on: ubuntu-latest
needs: test_rust
permissions:
Expand All @@ -73,8 +96,8 @@ jobs:
- name: Setup Environment
uses: ./.github/actions/setup
with:
cargo-cache-key: cargo-publish-rust-client
cargo-cache-fallback-key: cargo-rust-client
cargo-cache-key: ${{ inputs.lib_type == 'client' && 'cargo-publish-rust-client' || 'cargo-publish-program' }}
cargo-cache-fallback-key: ${{ inputs.lib_type == 'client' && 'cargo-rust-client' || 'cargo-programs' }}
clippy: true
rustfmt: true

Expand All @@ -95,7 +118,7 @@ jobs:
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"

- name: Publish Rust Client
- name: Publish Rust
id: publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
Expand All @@ -112,7 +135,11 @@ jobs:
OPTIONS=""
fi

pnpm clients:rust:publish $LEVEL $OPTIONS
if [ "${{ inputs.lib_type }}" == "client" ]; then
pnpm clients:rust:publish $LEVEL $OPTIONS
else
pnpm programs:publish $LEVEL $OPTIONS
fi

- name: Push Commit and Tag
if: github.event.inputs.dry_run != 'true'
Expand All @@ -122,4 +149,4 @@ jobs:
if: github.event.inputs.create_release == 'true' && github.event.inputs.dry_run != 'true'
uses: ncipollo/release-action@v1
with:
tag: rust@v${{ steps.publish.outputs.new_version }}
tag: ${{ inputs.lib_type == 'client' && 'rust' || 'program' }}@v${{ steps.publish.outputs.new_version }}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"programs:clean": "zx ./scripts/program/clean.mjs",
"programs:format": "zx ./scripts/program/format.mjs",
"programs:lint": "zx ./scripts/program/lint.mjs",
"programs:publish": "zx ./scripts/publish-rust.mjs program",
"solana:check": "zx ./scripts/check-solana-version.mjs",
"solana:link": "zx ./scripts/link-solana-version.mjs",
"generate": "pnpm generate:clients",
Expand All @@ -16,11 +17,11 @@
"validator:stop": "zx ./scripts/stop-validator.mjs",
"clients:js:format": "zx ./scripts/client/format-js.mjs",
"clients:js:lint": "zx ./scripts/client/lint-js.mjs",
"clients:js:publish": "zx ./scripts/client/publish-js.mjs",
"clients:js:publish": "zx ./scripts/publish-js.mjs",
"clients:js:test": "zx ./scripts/client/test-js.mjs",
"clients:rust:format": "zx ./scripts/client/format-rust.mjs",
"clients:rust:lint": "zx ./scripts/client/lint-rust.mjs",
"clients:rust:publish": "zx ./scripts/client/publish-rust.mjs",
"clients:rust:publish": "zx ./scripts/publish-rust.mjs client",
"clients:rust:test": "zx ./scripts/client/test-rust.mjs",
"template:upgrade": "zx ./scripts/upgrade-template.mjs"
},
Expand Down
40 changes: 0 additions & 40 deletions scripts/client/publish-rust.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/client/publish-js.mjs → scripts/publish-js.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env zx
import 'zx/globals';
import { cliArguments, workingDirectory } from '../utils.mjs';
import { cliArguments, workingDirectory } from './utils.mjs';

const [level, tag = 'latest'] = cliArguments();
if (!level) {
Expand Down
80 changes: 80 additions & 0 deletions scripts/publish-rust.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env zx
import 'zx/globals';
import { getCargo, workingDirectory } from './utils.mjs';

class Publisher {
libType;

constructor() {
const lib = process.argv[3];
if (!lib) {
throw new Error('A library type must be provided.');
}
if (lib !== 'client' && lib !== 'program') {
throw new Error('Invalid library type. Allowed values are "client" or "program".');
}
this.libType = lib;
}

path() {
if (this.libType === 'client') {
return 'clients/rust';
} else {
return 'program';
}
}

message() {
if (this.libType === 'client') {
return 'Rust client';
} else {
return 'Program';
}
}

tagPrefix() {
if (this.libType === 'client') {
return 'rust';
} else {
return 'program';
}
}
}

const publisher = new Publisher();
const dryRun = argv['dry-run'] ?? false;
const [level] = process.argv.slice(4);
if (!level) {
throw new Error('A version level — e.g. "path" — must be provided.');
}

// Go to the directory and install the dependencies.
cd(path.join(workingDirectory, publisher.path()));

// Publish the new version.
const releaseArgs = dryRun
? []
: ['--no-push', '--no-tag', '--no-confirm', '--execute'];
await $`cargo release ${level} ${releaseArgs}`;

// Stop here if this is a dry run.
if (dryRun) {
process.exit(0);
}

// Get the new version.
const newVersion = getCargo(publisher.path()).package.version;

// Expose the new version to CI if needed.
if (process.env.CI) {
await $`echo "new_version=${newVersion}" >> $GITHUB_OUTPUT`;
}

// Soft reset the last commit so we can create our own commit and tag.
await $`git reset --soft HEAD~1`;

// Commit the new version.
await $`git commit -am "Publish ${publisher.message()} v${newVersion}"`;

// Tag the new version.
await $`git tag -a ${publisher.tagPrefix()}@v${newVersion} -m "${publisher.message()} v${newVersion}"`;
Loading