Skip to content

Commit

Permalink
Upgrade Repository Template (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec authored Aug 1, 2024
1 parent ba24ffb commit 13dcd40
Show file tree
Hide file tree
Showing 50 changed files with 2,318 additions and 1,426 deletions.
67 changes: 40 additions & 27 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@ name: Setup environment

inputs:
cargo-cache-key:
description: The key to cache cargo dependencies. Skips if not provided.
description: The key to cache cargo dependencies. Skips cargo caching if not provided.
required: false
clippy:
description: Install Clippy (true/false). Skips if not provided.
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
node:
description: The Node.js version to install. Required.
required: true
protoc:
description: Whether or not to install protoc (workaround). Skips if not provided.
clippy:
description: Install Clippy if `true`. Defaults to `false`.
required: false
rustfmt:
description: Install Rustfmt (true/false). Skips if not provided.
description: Install Rustfmt if `true`. Defaults to `false`.
required: false
solana:
description: The Solana version to install. Skips if not provided.
description: Install Solana if `true`. Defaults to `false`.
required: false

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

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

- name: Install Dependencies
run: pnpm install --frozen-lockfile
Expand All @@ -40,36 +40,36 @@ runs:
shell: bash
run: pnpm zx ./scripts/ci/set-env.mjs

- name: (Temporary Workaround) Install Protobuf Compiler
if: ${{ inputs.protoc == 'true' }}
- name: Install Protobuf Compiler (Temporary Workaround for Solana 2.0)
if: ${{ inputs.solana == 'true' || inputs.rustfmt == 'true' || inputs.clippy == 'true' }}
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
- name: Install Rustfmt
if: ${{ inputs.rustfmt == 'true' }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUSTFMT_NIGHTLY_VERSION }}
toolchain: ${{ env.TOOLCHAIN_FORMAT }}
components: rustfmt

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

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

- name: Cache Cargo Dependencies
if: ${{ inputs.cargo-cache-key }}
if: ${{ inputs.cargo-cache-key && !inputs.cargo-cache-fallback-key }}
uses: actions/cache@v4
with:
path: |
Expand All @@ -81,8 +81,8 @@ runs:
key: ${{ runner.os }}-${{ inputs.cargo-cache-key }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-${{ inputs.cargo-cache-key }}

- name: Cache Cargo Dev-Dependencies
if: ${{ 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: |
Expand All @@ -91,7 +91,20 @@ runs:
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-${{ inputs.cargo-cache-key }}-tests-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-${{ inputs.cargo-cache-key }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ inputs.cargo-cache-key }}-tests
${{ runner.os }}-${{ inputs.cargo-cache-key }}
${{ 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 }}
115 changes: 54 additions & 61 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ on:
pull_request:
branches: [main]

env:
NODE_VERSION: 18
SOLANA_VERSION: 1.18.12

jobs:
format_and_lint_programs:
name: Format & Lint Programs
Expand All @@ -22,39 +18,32 @@ jobs:
uses: ./.github/actions/setup
with:
clippy: true
node: ${{ env.NODE_VERSION }}
rustfmt: true
protoc: true

- name: Format Programs
run: pnpm programs:format

- name: Lint Programs
run: pnpm programs:lint
format_and_lint_client_rust:
name: Format & Lint Client Rust

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
with:
clippy: true
node: ${{ env.NODE_VERSION }}
rustfmt: true
protoc: true

- name: Format Client Rust
run: pnpm clients:rust:format
- name: Lint Client Rust
run: pnpm clients:rust:lint
format_and_lint_client_js:
name: Format & Lint Client JS
- name: Format Client JS
run: pnpm clients:js:format

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

format_and_lint_client_rust:
name: Format & Lint Client Rust
runs-on: ubuntu-latest
steps:
- name: Git Checkout
Expand All @@ -63,13 +52,14 @@ jobs:
- name: Setup Environment
uses: ./.github/actions/setup
with:
node: ${{ env.NODE_VERSION }}
clippy: true
rustfmt: true

- name: Format Client JS
run: pnpm clients:js:format
- name: Lint Client JS
run: pnpm clients:js:lint
- name: Format Client Rust
run: pnpm clients:rust:format

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

build_programs:
name: Build programs
Expand All @@ -83,9 +73,7 @@ jobs:
uses: ./.github/actions/setup
with:
cargo-cache-key: cargo-programs
protoc: true
node: ${{ env.NODE_VERSION }}
solana: ${{ env.SOLANA_VERSION }}
solana: true

- name: Build Programs
run: pnpm programs:build
Expand All @@ -97,14 +85,14 @@ jobs:
path: ./target/deploy/*.so
if-no-files-found: error

- name: Cache Program Builds
- name: Save Program Builds For Client Jobs
uses: actions/cache/save@v4
with:
path: ./**/*.so
key: ${{ runner.os }}-builds-${{ github.sha }}

test_programs:
name: Test Progams
name: Test Programs
runs-on: ubuntu-latest
needs: format_and_lint_programs
steps:
Expand All @@ -114,14 +102,13 @@ jobs:
- name: Setup Environment
uses: ./.github/actions/setup
with:
cargo-cache-key: cargo-programs
protoc: true
node: ${{ env.NODE_VERSION }}
solana: ${{ env.SOLANA_VERSION }}
cargo-cache-key: cargo-program-tests
cargo-cache-fallback-key: cargo-programs
solana: true

- name: Test Programs
run: pnpm programs:test

generate_idls:
name: Check IDL Generation
runs-on: ubuntu-latest
Expand All @@ -134,7 +121,7 @@ jobs:
uses: ./.github/actions/setup
with:
cargo-cache-key: cargo-programs
node: ${{ env.NODE_VERSION }}
cargo-cache-local-key: cargo-local

- name: Generate IDLs
run: pnpm generate:idls
Expand All @@ -143,7 +130,7 @@ jobs:
run: |
git status --porcelain
test -z "$(git status --porcelain)"
generate_clients:
name: Check Client Generation
runs-on: ubuntu-latest
Expand All @@ -155,7 +142,6 @@ jobs:
- name: Setup Environment
uses: ./.github/actions/setup
with:
node: ${{ env.NODE_VERSION }}
rustfmt: true

- name: Generate Clients
Expand All @@ -165,9 +151,9 @@ jobs:
run: |
git status --porcelain
test -z "$(git status --porcelain)"
test_client_rust:
name: Test Client Rust
test_client_js:
name: Test Client JS
runs-on: ubuntu-latest
needs: build_programs
steps:
Expand All @@ -177,16 +163,19 @@ jobs:
- name: Setup Environment
uses: ./.github/actions/setup
with:
cargo-cache-key: cargo-programs
protoc: true
node: ${{ env.NODE_VERSION }}
solana: ${{ env.SOLANA_VERSION }}
solana: true

- name: Test Client Rust
run: pnpm clients:rust:test

test_client_js:
name: Test Client JS
- name: Restore Program Builds
uses: actions/cache/restore@v4
with:
path: ./**/*.so
key: ${{ runner.os }}-builds-${{ github.sha }}

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

test_client_rust:
name: Test Client Rust
runs-on: ubuntu-latest
needs: build_programs
steps:
Expand All @@ -196,10 +185,14 @@ jobs:
- name: Setup Environment
uses: ./.github/actions/setup
with:
cargo-cache-key: cargo-programs
protoc: true
node: ${{ env.NODE_VERSION }}
solana: ${{ env.SOLANA_VERSION }}
cargo-cache-key: cargo-rust-client
solana: true

- name: Test Client JS
run: pnpm clients:js:test
- name: Restore Program Builds
uses: actions/cache/restore@v4
with:
path: ./**/*.so
key: ${{ runner.os }}-builds-${{ github.sha }}

- name: Test Client Rust
run: pnpm clients:rust:test
Loading

0 comments on commit 13dcd40

Please sign in to comment.