chore: CI test #26
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Program tests | |
| on: pull_request | |
| env: | |
| CACHE: true | |
| NODE_VERSION: 23.7.0 | |
| SOLANA_CLI_VERSION: 2.2.6 | |
| ANCHOR_BINARY_NAME: anchor-binary-no-caching | |
| CARGO_PROFILE: release | |
| CARGO_CACHE_PATH: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| ./packages/contract/target/ | |
| jobs: | |
| setup-base: | |
| name: Setup base | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - run: sudo apt-get update && sudo apt-get install -y pkg-config build-essential libudev-dev | |
| - run: echo "ANCHOR_VERSION=$(cat ./VERSION)" >> $GITHUB_ENV | |
| setup-node: | |
| name: Setup node (v23) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 23.x | |
| cache: 'yarn' | |
| - uses: actions/cache@v4 | |
| id: yarn-cache | |
| with: | |
| path: '**/node_modules' | |
| key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }} | |
| - name: Install packages | |
| if: steps.yarn-cache.outputs.cache-hit != 'true' | |
| run: yarn install --immutable | |
| setup-solana: | |
| name: Setup solana | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| steps: | |
| - uses: actions/cache@v4 | |
| name: Cache Solana Tool Suite | |
| id: cache-solana | |
| with: | |
| path: | | |
| ~/.cache/solana/ | |
| ~/.local/share/solana/ | |
| key: ${{ runner.os }}-solana-${{ env.SOLANA_CLI_VERSION }} | |
| - name: install solana | |
| if: steps.cache-solana.outputs.cache-hit != 'true' | |
| run: sh -c "$(curl -sSfL https://release.anza.xyz/v${{ env.SOLANA_CLI_VERSION }}/install)" | |
| - name: Add solana to path | |
| run: echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH | |
| - name: Generate keypair | |
| run: solana-keygen new --outfile ~/.config/solana/id.json --force --no-bip39-passphrase | |
| - name: Initialize solana config | |
| run: solana config set --keypair ~/.config/solana/id.json && solana config set --url localhost | |
| - name: Solana Version | |
| run: solana --version | |
| setup-anchor: | |
| name: Setup anchor | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| needs: setup-base | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/cache@v4 | |
| if: ${{ env.CACHE != 'false' }} | |
| name: Cache Cargo registry + index | |
| id: cache-anchor | |
| with: | |
| path: ${{ env.CARGO_CACHE_PATH }} | |
| key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Install Anchor CLI (AVM) | |
| if: steps.cache-anchor.outputs.cache-hit != 'true' | |
| run: | | |
| cargo install --git https://github.com/coral-xyz/anchor avm --force | |
| avm install latest | |
| avm use latest | |
| working-directory: packages/contract | |
| - run: chmod +x ~/.cargo/bin/anchor | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.ANCHOR_BINARY_NAME }} | |
| path: ~/.cargo/bin/anchor | |
| basic-checks: | |
| name: Lint & format | |
| runs-on: ubuntu-latest | |
| needs: setup-node | |
| timeout-minutes: 5 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/cache@v4 | |
| with: | |
| path: '**/node_modules' | |
| key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }} | |
| - name: lint | |
| run: yarn lint | |
| - name: format | |
| run: | | |
| yarn prettier:check | |
| cd packages/contract && cargo fmt --check && cd .. | |
| test-programs: | |
| name: Test programs | |
| needs: [basic-checks, setup-anchor, setup-solana] | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/cache@v4 | |
| with: | |
| path: '**/node_modules' | |
| key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }} | |
| - name: Cache Cargo registry + index | |
| id: cache-anchor | |
| uses: actions/cache@v4 | |
| if: ${{ env.CACHE != 'false' }} | |
| with: | |
| path: ${{ env.CARGO_CACHE_PATH }} | |
| key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Cache Solana Tool Suite | |
| id: cache-solana | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/solana/ | |
| ~/.local/share/solana/ | |
| key: ${{ runner.os }}-solana-${{ env.SOLANA_CLI_VERSION }} | |
| - run: echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: ${{ env.ANCHOR_BINARY_NAME }} | |
| path: ~/.cargo/bin/ | |
| - run: | | |
| avm install latest | |
| avm use latest | |
| chmod +x ~/.cargo/bin/anchor | |
| - name: Cache test target | |
| id: cache-test-target | |
| uses: actions/cache@v4 | |
| if: ${{ env.CACHE != 'false' }} | |
| with: | |
| path: packages/contract/target | |
| key: cargo-${{ runner.os }}-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Generate keypair for wallet | |
| run: | | |
| solana-keygen new --outfile fooKey.json --force --no-bip39-passphrase | |
| solana config set --keypair fooKey.json && solana config set --url localhost | |
| - name: Generate keypair for program ID | |
| run: | | |
| solana-keygen new -o target/deploy/myepicproject-keypair.json --force --no-bip39-passphrase | |
| - name: Run local validator | |
| working-directory: ./packages/contract | |
| run: solana-test-validator -r --quiet & | |
| - name: Request token | |
| working-directory: ./packages/contract | |
| run: solana airdrop 6 | |
| - name: Build and deploy program | |
| run: yarn anchor:build && yarn anchor:deploy | |
| - name: Reset program id | |
| working-directory: ./packages/contract | |
| run: | | |
| echo "v=$(solana address -k target/deploy/myepicproject-keypair.json)" >> $GITHUB_ENV | |
| - name: Rewrite program with new id | |
| working-directory: ./packages/contract | |
| run: sed -i -e "3s/^.*/declare_id!(\"$v\");/" programs/myepicproject/src/lib.rs && sed -i -e "6s/^.*/myepicproject = \"$v\"/" Anchor.toml | |
| - name: Rebuild and Redeploy program | |
| run: yarn anchor:build && yarn anchor:deploy | |
| - name: Test program | |
| run: yarn test | |
| - name: Kill validator | |
| run: kill $(lsof -t -i:8899) |