|
| 1 | +name: Lint and Test Code |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - bin/** |
| 9 | + - examples/** |
| 10 | + - src/** |
| 11 | + - Cargo.* |
| 12 | + - rust-toolchain.toml |
| 13 | + - .github/workflows/ci-code.yaml |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read # Default token to read |
| 17 | + |
| 18 | +jobs: |
| 19 | + setup-cargo-make: |
| 20 | + name: setup-cargo-make |
| 21 | + runs-on: ubuntu-latest |
| 22 | + outputs: |
| 23 | + cargo_make_version: ${{ steps.get-version.outputs.cargo_make_version }} |
| 24 | + cache-key: ${{ steps.cache-cargo-make.outputs.cache-primary-key }} |
| 25 | + steps: |
| 26 | + - name: Fetch latest cargo-make version |
| 27 | + id: get-version |
| 28 | + run: | |
| 29 | + VERSION=$(curl -s \ |
| 30 | + -H "User-Agent: github.com/edera-dev/styrolite (contact: support@edera.dev>)" \ |
| 31 | + https://crates.io/api/v1/crates/cargo-make | jq -r '.crate.max_stable_version') |
| 32 | + echo "cargo_make_version=$VERSION" >> $GITHUB_OUTPUT |
| 33 | +
|
| 34 | + - name: Cache cargo-make binary |
| 35 | + id: cache-cargo-make |
| 36 | + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 |
| 37 | + with: |
| 38 | + path: ~/.cargo/bin/cargo-make |
| 39 | + key: ${{ runner.os }}-cargo-make-${{ steps.get-version.outputs.cargo_make_version }} |
| 40 | + |
| 41 | + - name: Install cargo-make if missing or outdated |
| 42 | + if: steps.cache-cargo-make.outputs.cache-hit != 'true' |
| 43 | + run: | |
| 44 | + cargo install cargo-make --version "${CARGO_MAKE_VERSION}" --force |
| 45 | + env: |
| 46 | + CARGO_MAKE_VERSION: ${{ steps.get-version.outputs.cargo_make_version }} |
| 47 | + |
| 48 | + - name: Verify cargo-make |
| 49 | + run: cargo make --version |
| 50 | + |
| 51 | + rustfmt: |
| 52 | + name: rustfmt |
| 53 | + runs-on: ubuntu-latest |
| 54 | + needs: setup-cargo-make |
| 55 | + steps: |
| 56 | + - name: harden runner |
| 57 | + uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 |
| 58 | + with: |
| 59 | + egress-policy: audit |
| 60 | + |
| 61 | + - name: checkout repository |
| 62 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 63 | + with: |
| 64 | + submodules: recursive |
| 65 | + persist-credentials: false |
| 66 | + |
| 67 | + - name: Restore cached cargo-make |
| 68 | + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 |
| 69 | + with: |
| 70 | + path: ~/.cargo/bin/cargo-make |
| 71 | + key: ${{ runner.os }}-cargo-make-${{ needs.setup-cargo-make.outputs.cargo_make_version }} |
| 72 | + |
| 73 | + - name: 'cargo fmt' |
| 74 | + run: cargo make format-check |
| 75 | + |
| 76 | + shfmt: |
| 77 | + name: shfmt |
| 78 | + runs-on: ubuntu-latest |
| 79 | + needs: setup-cargo-make |
| 80 | + steps: |
| 81 | + - name: harden runner |
| 82 | + uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 |
| 83 | + with: |
| 84 | + egress-policy: audit |
| 85 | + |
| 86 | + - name: checkout repository |
| 87 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 88 | + with: |
| 89 | + submodules: recursive |
| 90 | + persist-credentials: false |
| 91 | + |
| 92 | + - name: Restore cached cargo-make |
| 93 | + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 |
| 94 | + with: |
| 95 | + path: ~/.cargo/bin/cargo-make |
| 96 | + key: ${{ runner.os }}-cargo-make-${{ needs.setup-cargo-make.outputs.cargo_make_version }} |
| 97 | + |
| 98 | + - name: shfmt |
| 99 | + run: | |
| 100 | + GOBIN=/usr/local/bin go install mvdan.cc/sh/v3/cmd/shfmt@latest |
| 101 | + if ! cargo make shfmt; then |
| 102 | + echo "" |
| 103 | + echo "Please run \`cargo make shfmt-write\`" |
| 104 | + exit 1 |
| 105 | + fi |
| 106 | +
|
| 107 | + shellcheck: |
| 108 | + name: shellcheck |
| 109 | + runs-on: ubuntu-latest |
| 110 | + needs: setup-cargo-make |
| 111 | + steps: |
| 112 | + - name: harden runner |
| 113 | + uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 |
| 114 | + with: |
| 115 | + egress-policy: audit |
| 116 | + |
| 117 | + - name: checkout repository |
| 118 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 119 | + with: |
| 120 | + submodules: recursive |
| 121 | + persist-credentials: false |
| 122 | + |
| 123 | + - name: Restore cached cargo-make |
| 124 | + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 |
| 125 | + with: |
| 126 | + path: ~/.cargo/bin/cargo-make |
| 127 | + key: ${{ runner.os }}-cargo-make-${{ needs.setup-cargo-make.outputs.cargo_make_version }} |
| 128 | + |
| 129 | + - name: shellcheck |
| 130 | + run: cargo make shellcheck |
| 131 | + |
| 132 | + full-build: |
| 133 | + runs-on: ubuntu-latest |
| 134 | + needs: setup-cargo-make |
| 135 | + strategy: |
| 136 | + fail-fast: false |
| 137 | + matrix: |
| 138 | + arch: |
| 139 | + - x86_64 |
| 140 | + env: |
| 141 | + TARGET_ARCH: "${{ matrix.arch }}" |
| 142 | + name: 'Full build linux-${{ matrix.arch }}' |
| 143 | + steps: |
| 144 | + - name: harden runner |
| 145 | + uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 |
| 146 | + with: |
| 147 | + egress-policy: audit |
| 148 | + |
| 149 | + - name: checkout repository |
| 150 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 151 | + with: |
| 152 | + submodules: recursive |
| 153 | + persist-credentials: false |
| 154 | + |
| 155 | + - name: Restore cached cargo-make |
| 156 | + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 |
| 157 | + with: |
| 158 | + path: ~/.cargo/bin/cargo-make |
| 159 | + key: ${{ runner.os }}-cargo-make-${{ needs.setup-cargo-make.outputs.cargo_make_version }} |
| 160 | + |
| 161 | + - name: cargo build |
| 162 | + run: cargo make build |
| 163 | + |
| 164 | + full-test: |
| 165 | + runs-on: ubuntu-latest |
| 166 | + needs: setup-cargo-make |
| 167 | + strategy: |
| 168 | + fail-fast: false |
| 169 | + matrix: |
| 170 | + arch: |
| 171 | + - x86_64 |
| 172 | + env: |
| 173 | + TARGET_ARCH: "${{ matrix.arch }}" |
| 174 | + name: 'Full test linux-${{ matrix.arch }}' |
| 175 | + steps: |
| 176 | + - name: harden runner |
| 177 | + uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 |
| 178 | + with: |
| 179 | + egress-policy: audit |
| 180 | + |
| 181 | + - name: checkout repository |
| 182 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 183 | + with: |
| 184 | + submodules: recursive |
| 185 | + persist-credentials: false |
| 186 | + |
| 187 | + - name: Restore cached cargo-make |
| 188 | + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 |
| 189 | + with: |
| 190 | + path: ~/.cargo/bin/cargo-make |
| 191 | + key: ${{ runner.os }}-cargo-make-${{ needs.setup-cargo-make.outputs.cargo_make_version }} |
| 192 | + |
| 193 | + - name: 'cargo test' |
| 194 | + run: cargo make test |
| 195 | + |
| 196 | + full-clippy: |
| 197 | + runs-on: ubuntu-latest |
| 198 | + needs: setup-cargo-make |
| 199 | + strategy: |
| 200 | + matrix: |
| 201 | + arch: |
| 202 | + - x86_64 |
| 203 | + env: |
| 204 | + TARGET_ARCH: "${{ matrix.arch }}" |
| 205 | + name: 'Full clippy linux-${{ matrix.arch }}' |
| 206 | + steps: |
| 207 | + - name: harden runner |
| 208 | + uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 |
| 209 | + with: |
| 210 | + egress-policy: audit |
| 211 | + |
| 212 | + - name: checkout repository |
| 213 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 214 | + with: |
| 215 | + submodules: recursive |
| 216 | + persist-credentials: false |
| 217 | + |
| 218 | + - name: Restore cached cargo-make |
| 219 | + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 |
| 220 | + with: |
| 221 | + path: ~/.cargo/bin/cargo-make |
| 222 | + key: ${{ runner.os }}-cargo-make-${{ needs.setup-cargo-make.outputs.cargo_make_version }} |
| 223 | + |
| 224 | + - name: 'cargo clippy' |
| 225 | + run: cargo make clippy |
0 commit comments