From 045e31a32c7b3ad333b7d0af8efd8f6fe2964a6a Mon Sep 17 00:00:00 2001 From: lukas Date: Wed, 31 Jan 2024 13:53:28 +0100 Subject: [PATCH] feat: optimize actions --- .github/actions/anchor-install/action.yml | 40 +++++++++++++++++++ .github/actions/build/action.yml | 12 ++++++ .../{install => npm-install}/action.yml | 4 +- .github/actions/publish/action.yml | 19 +++++++++ .github/workflows/build.yaml | 21 +++++----- .github/workflows/publish.yaml | 22 +--------- 6 files changed, 84 insertions(+), 34 deletions(-) create mode 100644 .github/actions/anchor-install/action.yml create mode 100644 .github/actions/build/action.yml rename .github/actions/{install => npm-install}/action.yml (91%) create mode 100644 .github/actions/publish/action.yml diff --git a/.github/actions/anchor-install/action.yml b/.github/actions/anchor-install/action.yml new file mode 100644 index 0000000..00b346f --- /dev/null +++ b/.github/actions/anchor-install/action.yml @@ -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 \ No newline at end of file diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml new file mode 100644 index 0000000..ca26fcd --- /dev/null +++ b/.github/actions/build/action.yml @@ -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 \ No newline at end of file diff --git a/.github/actions/install/action.yml b/.github/actions/npm-install/action.yml similarity index 91% rename from .github/actions/install/action.yml rename to .github/actions/npm-install/action.yml index ff84082..11f8e46 100644 --- a/.github/actions/install/action.yml +++ b/.github/actions/npm-install/action.yml @@ -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 diff --git a/.github/actions/publish/action.yml b/.github/actions/publish/action.yml new file mode 100644 index 0000000..edd762b --- /dev/null +++ b/.github/actions/publish/action.yml @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8a23675..50a2d53 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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 diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 546f472..f649885 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -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 \ No newline at end of file