Skip to content

Commit

Permalink
feat: optimize actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mindrunner committed Jan 31, 2024
1 parent 51d75df commit 045e31a
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 34 deletions.
40 changes: 40 additions & 0 deletions .github/actions/anchor-install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 'Install Anchor with cached modules'
description: 'Run cargo install anchor-cli with cached modules'

runs:
using: 'composite'
steps:
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

- name: Cache cargo registry
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache cargo index
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-git-
- name: Cache cargo build
uses: actions/cache@v2
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-target-
- name: Install Anchor
run: cargo install anchor-cli --version ${{ inputs.anchor-version }}
shell: bash
12 changes: 12 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 'Build'
description: 'Build the project'

runs:
using: 'composite'
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: ./actions/npm-install
- uses: ./actions/anchor-install
- run: anchor build
shell: bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ runs:
using: 'composite'
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
uses: actions/install-node@v4
with:
node-version: lts/*

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-install@v2
id: pnpm-install
with:
run_install: false
Expand Down
19 changes: 19 additions & 0 deletions .github/actions/publish/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: 'Publish'
description: 'Publish the project'

runs:
using: 'composite'
steps:
- name: Install Dependencies
run: cd sdk && pnpm install
shell: bash
- name: Build SDK
run: pnpm run build:sdk
shell: bash
- name: Publish SDK
run: |
pnpm publish --access public \
${{ contains(github.ref_name, 'alpha') && '--tag alpha' || contains(github.ref_name, 'beta') && '--tag beta' || '' }}
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
21 changes: 10 additions & 11 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: 'Solana Anchor build'
uses: metadaoproject/setup-anchor@v2
with:
anchor-version: '0.29.0'
solana-cli-version: '1.17.15'
node-version: '20.10.0'
- uses: ./.github/actions/install
- run: anchor build
- run: anchor run build_sdk
- run: pnpm run test
- uses: ./.github/actions/build

test:
needs: build
runs-on: ubuntu-latest
steps:
- uses: ./.github/actions/build
- name: Run Tests
run: pnpm run test
shell: bash
22 changes: 1 addition & 21 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,4 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install
- name: 'Solana Anchor build'
uses: metadaoproject/setup-anchor@v2
with:
anchor-version: '0.29.0'
solana-cli-version: '1.17.15'
node-version: '20.10.0'
- uses: ./.github/actions/install
- run: anchor build
- run: anchor run build_sdk
- name: Install Dependencies
run: cd sdk && pnpm install
- name: Build SDK
run: pnpm run build:sdk
- name: Publish SDK
run: |
pnpm publish --access public \
${{ contains(github.ref_name, 'alpha') && '--tag alpha' || contains(github.ref_name, 'beta') && '--tag beta' || '' }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: ./.github/actions/publish

0 comments on commit 045e31a

Please sign in to comment.