Skip to content

Commit

Permalink
Update repo from latest create-solana-program (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva authored Jul 29, 2024
1 parent afc2280 commit a7ca79e
Show file tree
Hide file tree
Showing 33 changed files with 1,194 additions and 258 deletions.
103 changes: 103 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Setup environment

inputs:
cargo-cache-key:
description: The key to cache cargo dependencies. Skips cargo caching if not provided.
required: false
cargo-cache-fallback-key:
description: The fallback key to use when caching cargo dependencies. Default to not using a fallback key.
required: false
cargo-cache-local-key:
description: The key to cache local cargo dependencies. Skips local cargo caching if not provided.
required: false
clippy:
description: Install Clippy if `true`. Defaults to `false`.
required: false
rustfmt:
description: Install Rustfmt if `true`. Defaults to `false`.
required: false
solana:
description: Install Solana if `true`. Defaults to `false`.
required: false

runs:
using: 'composite'
steps:
- name: Setup pnpm
uses: pnpm/action-setup@v3

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'pnpm'

- name: Install Dependencies
run: pnpm install --frozen-lockfile
shell: bash

- name: Set Environment Variables
shell: bash
run: pnpm zx ./scripts/ci/set-env.mjs

- name: Install Rustfmt
if: ${{ inputs.rustfmt == 'true' }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.TOOLCHAIN_FORMAT }}
components: rustfmt

- name: Install Clippy
if: ${{ inputs.clippy == 'true' }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.TOOLCHAIN_LINT }}
components: clippy

- name: Install Solana
if: ${{ inputs.solana == 'true' }}
uses: metaplex-foundation/actions/install-solana@v1
with:
version: ${{ env.SOLANA_VERSION }}
cache: true

- name: Cache Cargo Dependencies
if: ${{ inputs.cargo-cache-key && !inputs.cargo-cache-fallback-key }}
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-${{ inputs.cargo-cache-key }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-${{ inputs.cargo-cache-key }}

- name: Cache Cargo Dependencies With Fallback
if: ${{ inputs.cargo-cache-key && inputs.cargo-cache-fallback-key }}
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-${{ inputs.cargo-cache-key }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ inputs.cargo-cache-key }}
${{ runner.os }}-${{ inputs.cargo-cache-fallback-key }}-${{ hashFiles('**/Cargo.lock') }}
${{ runner.os }}-${{ inputs.cargo-cache-fallback-key }}
- name: Cache Local Cargo Dependencies
if: ${{ inputs.cargo-cache-local-key }}
uses: actions/cache@v4
with:
path: |
.cargo/bin/
.cargo/registry/index/
.cargo/registry/cache/
.cargo/git/db/
key: ${{ runner.os }}-${{ inputs.cargo-cache-local-key }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-${{ inputs.cargo-cache-local-key }}
98 changes: 98 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Main

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
format_and_lint_client_js:
name: Format & Lint Client JS
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup

- name: Format Client JS
run: pnpm clients:js:format

- name: Lint Client JS
run: pnpm clients:js:lint

format_and_lint_client_rust:
if: false # Disabled until we have a Rust client
name: Format & Lint Client Rust
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup
with:
clippy: true
rustfmt: true

- name: Format Client Rust
run: pnpm clients:rust:format

- name: Lint Client Rust
run: pnpm clients:rust:lint

generate_clients:
name: Check Client Generation
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup
with:
rustfmt: true

- name: Generate Clients
run: pnpm generate:clients

- name: Check Working Directory
run: |
git status --porcelain
test -z "$(git status --porcelain)"
test_client_js:
name: Test Client JS
runs-on: ubuntu-latest
needs: format_and_lint_client_js
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup
with:
solana: true

- name: Test Client JS
run: pnpm clients:js:test

test_client_rust:
if: false # Disabled until we have a Rust client
name: Test Client Rust
runs-on: ubuntu-latest
needs: format_and_lint_client_rust
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup
with:
cargo-cache-key: cargo-rust-client
solana: true

- name: Test Client Rust
run: pnpm clients:rust:test
95 changes: 95 additions & 0 deletions .github/workflows/publish-js-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
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:
solana: true

- name: Format JS Client
run: pnpm clients:js:format

- name: Lint JS Client
run: pnpm clients:js:lint

- 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: ${{ secrets.NPM_TOKEN }}
if: ${{ env.token == '' }}
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: ${{ secrets.NPM_TOKEN }}

- 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 ${{ inputs.level }} ${{ inputs.tag }}

- 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: js@v${{ steps.publish.outputs.new_version }}
Loading

0 comments on commit a7ca79e

Please sign in to comment.