|
| 1 | +# ******************************************************************************** |
| 2 | +# Copyright (c) 2024 Contributors to the Eclipse Foundation |
| 3 | +# |
| 4 | +# See the NOTICE file(s) distributed with this work for additional |
| 5 | +# information regarding copyright ownership. |
| 6 | +# |
| 7 | +# This program and the accompanying materials are made available under the |
| 8 | +# terms of the Apache License Version 2.0 which is available at |
| 9 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# SPDX-License-Identifier: Apache-2.0 |
| 12 | +# *******************************************************************************/ |
| 13 | + |
| 14 | +# Comprehensive combination of checks, linting, feature-checks, testing to be run on merge and on PR |
| 15 | +# Upload test results for potential re-use in publication workflow, returns the corresponding download URL as an output on workflow_call |
| 16 | + |
| 17 | +name: Cargo |
| 18 | + |
| 19 | +on: |
| 20 | + push: |
| 21 | + branches: |
| 22 | + - main |
| 23 | + pull_request: |
| 24 | + paths: |
| 25 | + - "src/**" |
| 26 | + - "Cargo.*" |
| 27 | + - "deny.toml" |
| 28 | + workflow_call: |
| 29 | + inputs: |
| 30 | + package: |
| 31 | + description: "Which rust package to check" |
| 32 | + required: false |
| 33 | + default: '"*"' # for some reason, this default is ignored, so we have to repeat the pattern below |
| 34 | + type: string |
| 35 | + outputs: |
| 36 | + test_results_url: |
| 37 | + description: "URL of the test results artifact" |
| 38 | + value: ${{ jobs.nextest.outputs.test_results_url }} |
| 39 | + doctest_results_url: |
| 40 | + description: "URL of the doctest results artifact" |
| 41 | + value: ${{ jobs.doctest.outputs.test_results_url }} |
| 42 | + |
| 43 | +concurrency: |
| 44 | + group: ${{ github.ref }}-${{ github.workflow }} |
| 45 | + cancel-in-progress: true |
| 46 | + |
| 47 | +env: |
| 48 | + RUST_TOOLCHAIN: ${{ vars.RUST_TOOLCHAIN || 'stable' }} |
| 49 | + RUSTFLAGS: -Dwarnings |
| 50 | + CARGO_TERM_COLOR: always |
| 51 | + |
| 52 | +jobs: |
| 53 | + deny: |
| 54 | + runs-on: ubuntu-latest |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v4 |
| 57 | + - uses: dtolnay/rust-toolchain@master |
| 58 | + with: |
| 59 | + toolchain: ${{ env.RUST_TOOLCHAIN }} |
| 60 | + - uses: taiki-e/install-action@cargo-deny |
| 61 | + - name: Run cargo deny check |
| 62 | + run: | |
| 63 | + cargo deny check |
| 64 | +
|
| 65 | + check: |
| 66 | + runs-on: ubuntu-latest |
| 67 | + steps: |
| 68 | + - uses: actions/checkout@v4 |
| 69 | + - uses: dtolnay/rust-toolchain@master |
| 70 | + with: |
| 71 | + toolchain: ${{ env.RUST_TOOLCHAIN }} |
| 72 | + - name: Run cargo check |
| 73 | + run: | |
| 74 | + cargo check --package ${{ inputs.package || '"*"' }} --all --tests |
| 75 | +
|
| 76 | + fmt: |
| 77 | + runs-on: ubuntu-latest |
| 78 | + steps: |
| 79 | + - uses: actions/checkout@v4 |
| 80 | + - uses: dtolnay/rust-toolchain@master |
| 81 | + with: |
| 82 | + toolchain: ${{ env.RUST_TOOLCHAIN }} |
| 83 | + components: rustfmt |
| 84 | + - name: Run cargo fmt |
| 85 | + run: | |
| 86 | + cargo fmt --package ${{ inputs.package || '"*"' }} --all -- --check |
| 87 | +
|
| 88 | + clippy: |
| 89 | + runs-on: ubuntu-latest |
| 90 | + steps: |
| 91 | + - uses: actions/checkout@v4 |
| 92 | + - uses: dtolnay/rust-toolchain@master |
| 93 | + with: |
| 94 | + toolchain: ${{ env.RUST_TOOLCHAIN }} |
| 95 | + components: clippy |
| 96 | + - name: Run cargo clippy |
| 97 | + run: | |
| 98 | + cargo clippy --version |
| 99 | + cargo clippy --tests --examples |
| 100 | +
|
| 101 | + docu: |
| 102 | + runs-on: ubuntu-latest |
| 103 | + env: |
| 104 | + RUSTDOCFLAGS: -Dwarnings |
| 105 | + steps: |
| 106 | + - uses: actions/checkout@v4 |
| 107 | + - uses: dtolnay/rust-toolchain@master |
| 108 | + with: |
| 109 | + toolchain: ${{ env.RUST_TOOLCHAIN }} |
| 110 | + - name: Run rustdoc |
| 111 | + run: | |
| 112 | + cargo doc --package ${{ inputs.package || '"*"' }} --no-deps --all-features |
| 113 | +
|
| 114 | + feature-check: |
| 115 | + # Comprehensive check on dependencies for all feature flag combinations, excluding development dependencies |
| 116 | + needs: check |
| 117 | + # do not run for package 'up-subscription' - the cargo hack module does not properly support --package="*" at the moment, so different approach than the other instances |
| 118 | + if: inputs.package != 'up-subscription' |
| 119 | + runs-on: ubuntu-latest |
| 120 | + steps: |
| 121 | + - uses: actions/checkout@v4 |
| 122 | + - uses: dtolnay/rust-toolchain@master |
| 123 | + with: |
| 124 | + toolchain: ${{ env.RUST_TOOLCHAIN }} |
| 125 | + - uses: Swatinem/rust-cache@v2 |
| 126 | + - uses: taiki-e/install-action@cargo-hack |
| 127 | + - name: Run cargo hack powerset |
| 128 | + run: | |
| 129 | + cargo hack check --feature-powerset --no-dev-deps |
| 130 | +
|
| 131 | + nextest: |
| 132 | + # Subset of feature-combos, on only one OS - more complete testing in test-featurematrix.yaml |
| 133 | + outputs: |
| 134 | + test_results_url: ${{ steps.test_results.outputs.artifact-url }} |
| 135 | + runs-on: ubuntu-latest |
| 136 | + env: |
| 137 | + NEXTEST_EXPERIMENTAL_LIBTEST_JSON: 1 |
| 138 | + strategy: |
| 139 | + matrix: |
| 140 | + feature-flags: ["", "--no-default-features", "--all-features"] |
| 141 | + steps: |
| 142 | + - uses: actions/checkout@v4 |
| 143 | + - uses: dtolnay/rust-toolchain@master |
| 144 | + with: |
| 145 | + toolchain: ${{ env.RUST_TOOLCHAIN }} |
| 146 | + - uses: Swatinem/rust-cache@v2 |
| 147 | + # Using nextest because it's faster than built-in test |
| 148 | + - uses: taiki-e/install-action@nextest |
| 149 | + - name: Run cargo nextest |
| 150 | + run: | |
| 151 | + cargo nextest run --package ${{ inputs.package || '"*"' }} --message-format libtest-json-plus ${{ matrix.feature-flags }} > testresults${{ matrix.feature-flags }}.json |
| 152 | + - name: Upload all-features test results artifact |
| 153 | + id: test_results |
| 154 | + if: matrix.feature-flags == '--all-features' |
| 155 | + uses: actions/upload-artifact@v4 |
| 156 | + with: |
| 157 | + name: test-results |
| 158 | + path: testresults--all-features.json |
| 159 | + |
| 160 | + doctest: |
| 161 | + # Run doctests separately, as nextest doesn't yet (https://github.com/nextest-rs/nextest/issues/16) |
| 162 | + outputs: |
| 163 | + test_results_url: ${{ steps.doctest_results.outputs.artifact-url }} |
| 164 | + runs-on: ubuntu-latest |
| 165 | + env: |
| 166 | + RUSTDOCFLAGS: -Dwarnings |
| 167 | + steps: |
| 168 | + - uses: actions/checkout@v4 |
| 169 | + - uses: dtolnay/rust-toolchain@master |
| 170 | + with: |
| 171 | + toolchain: ${{ env.RUST_TOOLCHAIN }} |
| 172 | + - name: Run doc tests |
| 173 | + run: | |
| 174 | + RUSTC_BOOTSTRAP=1 cargo test --package ${{ inputs.package || '"*"' }} --doc --all-features -- -Z unstable-options --format json --report-time > doctestresults--all-features.json |
| 175 | + - name: Upload doctest results artifact |
| 176 | + id: doctest_results |
| 177 | + uses: actions/upload-artifact@v4 |
| 178 | + with: |
| 179 | + name: doctest-results |
| 180 | + path: doctestresults--all-features.json |
0 commit comments