|
| 1 | +name: Setup environment |
| 2 | + |
| 3 | +inputs: |
| 4 | + cargo-cache-key: |
| 5 | + description: The key to cache cargo dependencies. Skips cargo caching if not provided. |
| 6 | + required: false |
| 7 | + toolchain: |
| 8 | + description: Rust toolchain to install. Comma-separated string of [`build`, `format`, `lint`, `test`]. |
| 9 | + required: false |
| 10 | + components: |
| 11 | + description: Cargo components to install. Comma-separated string of [`audit`, `hack`, `release`, `semver-checks`]. |
| 12 | + required: false |
| 13 | + solana: |
| 14 | + description: Install Solana if `true`. Defaults to `false`. |
| 15 | + required: false |
| 16 | + |
| 17 | +runs: |
| 18 | + using: 'composite' |
| 19 | + steps: |
| 20 | + - name: Set Environment Variables |
| 21 | + shell: bash |
| 22 | + run: | |
| 23 | + source make |
| 24 | + echo "RUST_TOOLCHAIN_BUILD=${RUST_TOOLCHAIN_BUILD}" >> $GITHUB_ENV |
| 25 | + echo "RUST_TOOLCHAIN_FORMAT=${RUST_TOOLCHAIN_FORMAT}" >> $GITHUB_ENV |
| 26 | + echo "RUST_TOOLCHAIN_LINT=${RUST_TOOLCHAIN_LINT}" >> $GITHUB_ENV |
| 27 | + echo "RUST_TOOLCHAIN_TEST=${RUST_TOOLCHAIN_TEST}" >> $GITHUB_ENV |
| 28 | + echo "SOLANA_CLI_VERSION=${SOLANA_CLI_VERSION}" >> $GITHUB_ENV |
| 29 | +
|
| 30 | + - name: Install Rust 'build' Toolchain |
| 31 | + if: ${{ contains(inputs.toolchain, 'build') }} |
| 32 | + uses: dtolnay/rust-toolchain@master |
| 33 | + with: |
| 34 | + toolchain: ${{ env.RUST_TOOLCHAIN_BUILD }} |
| 35 | + |
| 36 | + - name: Install Rust 'format' Toolchain |
| 37 | + if: ${{ contains(inputs.toolchain, 'format') }} |
| 38 | + uses: dtolnay/rust-toolchain@master |
| 39 | + with: |
| 40 | + toolchain: ${{ env.RUST_TOOLCHAIN_FORMAT }} |
| 41 | + components: rustfmt |
| 42 | + |
| 43 | + - name: Install Rust 'lint' Toolchain |
| 44 | + if: ${{ contains(inputs.toolchain, 'lint') }} |
| 45 | + uses: dtolnay/rust-toolchain@master |
| 46 | + with: |
| 47 | + toolchain: ${{ env.RUST_TOOLCHAIN_LINT }} |
| 48 | + components: clippy |
| 49 | + |
| 50 | + - name: Install Rust 'test' Toolchain |
| 51 | + if: ${{ contains(inputs.toolchain, 'test') }} |
| 52 | + uses: dtolnay/rust-toolchain@master |
| 53 | + with: |
| 54 | + toolchain: ${{ env.RUST_TOOLCHAIN_TEST }} |
| 55 | + |
| 56 | + - name: Install Solana |
| 57 | + if: ${{ inputs.solana == 'true' }} |
| 58 | + uses: solana-program/actions/install-solana@v1 |
| 59 | + with: |
| 60 | + version: ${{ env.SOLANA_VERSION }} |
| 61 | + cache: true |
| 62 | + |
| 63 | + - name: Install 'cargo-audit' |
| 64 | + if: ${{ contains(inputs.components, 'audit') }} |
| 65 | + uses: taiki-e/cache-cargo-install-action@v2 |
| 66 | + with: |
| 67 | + tool: cargo-audit |
| 68 | + |
| 69 | + - name: Install 'cargo-hack' |
| 70 | + if: ${{ contains(inputs.components, 'hack') }} |
| 71 | + uses: taiki-e/cache-cargo-install-action@v2 |
| 72 | + with: |
| 73 | + tool: cargo-hack |
| 74 | + |
| 75 | + - name: Install 'cargo-release' |
| 76 | + if: ${{ contains(inputs.components, 'release') }} |
| 77 | + uses: taiki-e/cache-cargo-install-action@v2 |
| 78 | + with: |
| 79 | + |
| 80 | + |
| 81 | + - name: Install 'cargo-semver-checks' |
| 82 | + if: ${{ contains(inputs.components, 'semver-checks') }} |
| 83 | + uses: taiki-e/cache-cargo-install-action@v2 |
| 84 | + with: |
| 85 | + |
| 86 | + |
| 87 | + - name: Install 'cargo-miri' |
| 88 | + if: ${{ contains(inputs.toolchain, 'lint') }} |
| 89 | + uses: dtolnay/rust-toolchain@master |
| 90 | + with: |
| 91 | + toolchain: ${{ env.TOOLCHAIN_LINT }} |
| 92 | + components: miri |
| 93 | + |
| 94 | + - name: Install 'cargo-spellcheck' |
| 95 | + if: ${{ contains(inputs.components, 'spellcheck') }} |
| 96 | + uses: taiki-e/install-action@v2 |
| 97 | + with: |
| 98 | + tool: cargo-spellcheck |
| 99 | + |
| 100 | + - name: Cache Cargo Dependencies |
| 101 | + if: ${{ inputs.cargo-cache-key }} |
| 102 | + uses: actions/cache@v4 |
| 103 | + with: |
| 104 | + path: | |
| 105 | + ~/.cargo/bin/ |
| 106 | + ~/.cargo/registry/index/ |
| 107 | + ~/.cargo/registry/cache/ |
| 108 | + ~/.cargo/git/db/ |
| 109 | + target/ |
| 110 | + key: ${{ runner.os }}-${{ inputs.cargo-cache-key }}-${{ hashFiles('**/Cargo.lock') }} |
0 commit comments