Skip to content
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
125 changes: 125 additions & 0 deletions .github/workflows/publish-program.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: Publish Program

on:
workflow_dispatch:
inputs:
level:
description: Level
required: true
default: patch
type: choice
options:
- patch
- minor
- major
- rc
- beta
- alpha
- release
- version
version:
description: Version
required: false
type: string
dry_run:
description: Dry run
required: true
default: true
type: boolean
create_release:
description: Create a GitHub release
required: true
type: boolean
default: true

jobs:
test_rust:
name: Test Program
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup
with:
cargo-cache-key: cargo-program
clippy: true
rustfmt: true
solana: true

- name: Format Program
run: pnpm programs:format

- name: Lint Program
run: pnpm programs:lint

- name: Build Program
run: pnpm programs:build

- name: Test Program
run: pnpm programs:test

publish_rust:
name: Publish Program
runs-on: ubuntu-latest
needs: test_rust
permissions:
contents: write
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup
with:
cargo-cache-key: cargo-publish-program
cargo-cache-fallback-key: cargo-program
clippy: true
rustfmt: true

- name: Install Cargo Release
run: which cargo-release || cargo install cargo-release

- name: Ensure CARGO_REGISTRY_TOKEN variable is set
env:
token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
if: ${{ env.token == '' }}
run: |
echo "The CARGO_REGISTRY_TOKEN secret variable is not set"
echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"."
exit 1

- 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 Program
id: publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
if [ "${{ inputs.level }}" == "version" ]; then
LEVEL=${{ inputs.version }}
else
LEVEL=${{ inputs.level }}
fi

if [ "${{ inputs.dry_run }}" == "true" ]; then
OPTIONS="--dry-run"
else
OPTIONS=""
fi

pnpm programs:publish $LEVEL $OPTIONS

- name: Push Commit and Tag
if: github.event.inputs.dry_run != 'true'
run: git push origin --follow-tags

- name: Create GitHub release
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 }}
1 change: 1 addition & 0 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/program/publish.mjs",
"solana:check": "zx ./scripts/check-solana-version.mjs",
"solana:link": "zx ./scripts/link-solana-version.mjs",
"generate": "pnpm generate:clients",
Expand Down
40 changes: 40 additions & 0 deletions scripts/program/publish.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env zx
import 'zx/globals';
import { cliArguments, getCargo, workingDirectory } from '../utils.mjs';

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

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

// 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(path.join('program')).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 Program v${newVersion}"`;

// Tag the new version.
await $`git tag -a rust@v${newVersion} -m "Program v${newVersion}"`;