|
| 1 | +name: Solana CI |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + - dev |
| 9 | +jobs: |
| 10 | + solana-sbf: |
| 11 | + name: Solana Cargo SBF |
| 12 | + runs-on: ubuntu-20.04 |
| 13 | + env: |
| 14 | + RUSTFLAGS: -Dwarnings |
| 15 | + |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v3 |
| 18 | + - name: Get rust toolchain version |
| 19 | + id: toolchain |
| 20 | + run: | |
| 21 | + RUST_VERSION="$(awk '/channel =/ { print substr($3, 2, length($3)-2) }' solana/rust-toolchain)" |
| 22 | + echo "::set-output name=version::${RUST_VERSION}" |
| 23 | +
|
| 24 | + - name: Get solana version |
| 25 | + id: solana |
| 26 | + run: | |
| 27 | + SOLANA_VERSION="$(awk '/solana-program =/ { print substr($3, 3, length($3)-3) }' solana/Cargo.toml)" |
| 28 | + echo "::set-output name=version::${SOLANA_VERSION}" |
| 29 | +
|
| 30 | + - name: Cache rust toolchain |
| 31 | + uses: actions/cache@v3 |
| 32 | + env: |
| 33 | + cache-name: solana-toolchain |
| 34 | + with: |
| 35 | + path: | |
| 36 | + ~/.cargo/bin |
| 37 | + ~/.rustup |
| 38 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ steps.toolchain.outputs.version }} |
| 39 | + restore-keys: | |
| 40 | + ${{ runner.os }}-build-${{ env.cache-name }}- |
| 41 | + ${{ runner.os }}-build- |
| 42 | + ${{ runner.os }}- |
| 43 | +
|
| 44 | + - name: Install rust toolchain |
| 45 | + uses: dtolnay/rust-toolchain@55c7845fad90d0ae8b2e83715cb900e5e861e8cb |
| 46 | + with: |
| 47 | + toolchain: ${{ steps.toolchain.outputs.version }} |
| 48 | + components: "clippy,rustfmt" |
| 49 | + |
| 50 | + - name: Cache rust packages / build cache |
| 51 | + uses: actions/cache@v3 |
| 52 | + env: |
| 53 | + cache-name: solana-rust-packages |
| 54 | + with: |
| 55 | + path: | |
| 56 | + ~/.cargo/bin |
| 57 | + ~/.cargo/registry |
| 58 | + ~/.cargo/git/db |
| 59 | + solana/target |
| 60 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('solana/Cargo.lock') }} |
| 61 | + restore-keys: | |
| 62 | + ${{ runner.os }}-build-${{ env.cache-name }}- |
| 63 | + ${{ runner.os }}-build- |
| 64 | + ${{ runner.os }}- |
| 65 | +
|
| 66 | + - name: Run `cargo fmt` |
| 67 | + run: cargo fmt --check --all --manifest-path solana/Cargo.toml |
| 68 | + |
| 69 | + - name: Run `cargo check` |
| 70 | + run: cargo check --workspace --tests --manifest-path solana/Cargo.toml |
| 71 | + |
| 72 | + - name: Run `cargo clippy` |
| 73 | + run: cargo clippy --workspace --tests --manifest-path solana/Cargo.toml |
| 74 | + |
| 75 | + - name: Cache solana tools |
| 76 | + id: cache-solana |
| 77 | + uses: actions/cache@v3 |
| 78 | + env: |
| 79 | + cache-name: solana-tools |
| 80 | + with: |
| 81 | + path: | |
| 82 | + ~/.local/share/solana/install/ |
| 83 | + ~/.cache/solana/ |
| 84 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ steps.solana.outputs.version }} |
| 85 | + |
| 86 | + - if: ${{ steps.cache-solana.outputs.cache-hit != 'true' }} |
| 87 | + name: Install solana tools |
| 88 | + env: |
| 89 | + SOLANA_VERSION: ${{ steps.solana.outputs.version }} |
| 90 | + run: | |
| 91 | + sh -c "$(curl -sSfL https://release.solana.com/v${SOLANA_VERSION}/install)" |
| 92 | + ~/.local/share/solana/install/active_release/bin/sdk/sbf/scripts/install.sh |
| 93 | +
|
| 94 | + - name: cargo build-sbf && cargo test-sbf |
| 95 | + env: |
| 96 | + RUST_BACKTRACE: "1" |
| 97 | + run: | |
| 98 | + cd solana |
| 99 | + export BPF_OUT_DIR="$(pwd)/target/deploy" |
| 100 | + export PATH="${HOME}/.local/share/solana/install/active_release/bin:${PATH}" |
| 101 | +
|
| 102 | + mkdir -p "${BPF_OUT_DIR}" |
| 103 | +
|
| 104 | + BPF_PACKAGES=( |
| 105 | + programs/example-native-token-transfers/Cargo.toml |
| 106 | + programs/wormhole-governance/Cargo.toml |
| 107 | + ) |
| 108 | + for p in "${BPF_PACKAGES[@]}"; do |
| 109 | + cargo build-sbf --manifest-path "${p}" |
| 110 | + done |
| 111 | + for p in "${BPF_PACKAGES[@]}"; do |
| 112 | + cargo test-sbf --manifest-path "${p}" |
| 113 | + done |
| 114 | + anchor-test: |
| 115 | + name: Anchor Test |
| 116 | + runs-on: ubuntu-latest |
| 117 | + # Anchor Docker image: https://www.anchor-lang.com/docs/verifiable-builds#images |
| 118 | + container: backpackapp/build:v0.29.0 |
| 119 | + steps: |
| 120 | + - uses: actions/checkout@v4 |
| 121 | + - name: Set default Rust toolchain |
| 122 | + run: rustup default stable |
| 123 | + working-directory: ./solana |
| 124 | + - name: anchor test --arch sbf |
| 125 | + run: make anchor-test |
| 126 | + working-directory: ./solana |
0 commit comments