|
| 1 | +# This workflow runs whenever a PR is opened or updated, or a commit is pushed to main. It runs |
| 2 | +# several checks: |
| 3 | +# - fmt: checks that the code is formatted according to rustfmt |
| 4 | +# - clippy: checks that the code does not contain any clippy warnings |
| 5 | +# - doc: checks that the code can be documented without errors |
| 6 | +# - hack: check combinations of feature flags |
| 7 | +# - msrv: check that the msrv specified in the crate is correct |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | +# This configuration allows maintainers of this repo to create a branch and pull request based on |
| 11 | +# the new branch. Restricting the push trigger to the main branch ensures that the PR only gets |
| 12 | +# built once. |
| 13 | +on: |
| 14 | + push: |
| 15 | + branches: [main] |
| 16 | + pull_request: |
| 17 | +# If new code is pushed to a PR branch, then cancel in progress workflows for that PR. Ensures that |
| 18 | +# we don't waste CI time, and returns results quicker https://github.com/jonhoo/rust-ci-conf/pull/5 |
| 19 | +concurrency: |
| 20 | + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} |
| 21 | + cancel-in-progress: true |
| 22 | +name: check |
| 23 | +jobs: |
| 24 | + fmt: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + name: stable / fmt |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + submodules: true |
| 31 | + - name: Install stable |
| 32 | + uses: dtolnay/rust-toolchain@stable |
| 33 | + with: |
| 34 | + components: rustfmt |
| 35 | + - name: cargo fmt --check |
| 36 | + run: cargo fmt --check |
| 37 | + clippy: |
| 38 | + runs-on: ubuntu-latest |
| 39 | + name: ${{ matrix.toolchain }} / clippy |
| 40 | + permissions: |
| 41 | + contents: read |
| 42 | + checks: write |
| 43 | + strategy: |
| 44 | + fail-fast: false |
| 45 | + matrix: |
| 46 | + # Get early warning of new lints which are regularly introduced in beta channels. |
| 47 | + toolchain: [stable, beta] |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v4 |
| 50 | + with: |
| 51 | + submodules: true |
| 52 | + - name: Install ${{ matrix.toolchain }} |
| 53 | + uses: dtolnay/rust-toolchain@master |
| 54 | + with: |
| 55 | + toolchain: ${{ matrix.toolchain }} |
| 56 | + components: clippy |
| 57 | + - name: cargo clippy |
| 58 | + uses: giraffate/clippy-action@v1 |
| 59 | + with: |
| 60 | + reporter: 'github-pr-check' |
| 61 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + semver: |
| 63 | + runs-on: ubuntu-latest |
| 64 | + name: semver |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v4 |
| 67 | + with: |
| 68 | + submodules: true |
| 69 | + - name: Install stable |
| 70 | + uses: dtolnay/rust-toolchain@stable |
| 71 | + with: |
| 72 | + components: rustfmt |
| 73 | + - name: cargo-semver-checks |
| 74 | + uses: obi1kenobi/cargo-semver-checks-action@v2 |
| 75 | + doc: |
| 76 | + # run docs generation on nightly rather than stable. This enables features like |
| 77 | + # https://doc.rust-lang.org/beta/unstable-book/language-features/doc-cfg.html which allows an |
| 78 | + # API be documented as only available in some specific platforms. |
| 79 | + runs-on: ubuntu-latest |
| 80 | + name: nightly / doc |
| 81 | + steps: |
| 82 | + - uses: actions/checkout@v4 |
| 83 | + with: |
| 84 | + submodules: true |
| 85 | + - name: Install nightly |
| 86 | + uses: dtolnay/rust-toolchain@nightly |
| 87 | + - name: Install cargo-docs-rs |
| 88 | + uses: dtolnay/install@cargo-docs-rs |
| 89 | + - name: cargo docs-rs |
| 90 | + run: cargo docs-rs |
| 91 | + hack: |
| 92 | + # cargo-hack checks combinations of feature flags to ensure that features are all additive |
| 93 | + # which is required for feature unification |
| 94 | + runs-on: ubuntu-latest |
| 95 | + name: ubuntu / stable / features |
| 96 | + steps: |
| 97 | + - uses: actions/checkout@v4 |
| 98 | + with: |
| 99 | + submodules: true |
| 100 | + - name: Install stable |
| 101 | + uses: dtolnay/rust-toolchain@stable |
| 102 | + - name: cargo install cargo-hack |
| 103 | + uses: taiki-e/install-action@cargo-hack |
| 104 | + # intentionally no target specifier; see https://github.com/jonhoo/rust-ci-conf/pull/4 |
| 105 | + # --feature-powerset runs for every combination of features |
| 106 | + - name: cargo hack |
| 107 | + run: cargo hack --feature-powerset --exclude-features nightly check |
| 108 | + msrv: |
| 109 | + # check that we can build using the minimal rust version that is specified by this crate |
| 110 | + runs-on: ubuntu-latest |
| 111 | + # we use a matrix here just because env can't be used in job names |
| 112 | + # https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability |
| 113 | + strategy: |
| 114 | + matrix: |
| 115 | + msrv: ["1.60.0"] # 2021 edition requires 1.56 |
| 116 | + name: ubuntu / ${{ matrix.msrv }} |
| 117 | + steps: |
| 118 | + - uses: actions/checkout@v4 |
| 119 | + with: |
| 120 | + submodules: true |
| 121 | + - name: Install ${{ matrix.msrv }} |
| 122 | + uses: dtolnay/rust-toolchain@master |
| 123 | + with: |
| 124 | + toolchain: ${{ matrix.msrv }} |
| 125 | + - name: cargo +${{ matrix.msrv }} check |
| 126 | + run: cargo check |
0 commit comments