|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - '**' |
| 9 | + pull_request: {} |
| 10 | + |
| 11 | +jobs: |
| 12 | + lint: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v3 |
| 16 | + |
| 17 | + - uses: dtolnay/rust-toolchain@stable |
| 18 | + with: |
| 19 | + components: rustfmt, clippy |
| 20 | + |
| 21 | + - id: cache-rust |
| 22 | + uses: Swatinem/rust-cache@v2 |
| 23 | + |
| 24 | + - uses: pre-commit/action@v3.0.0 |
| 25 | + with: |
| 26 | + extra_args: --all-files --verbose |
| 27 | + env: |
| 28 | + PRE_COMMIT_COLOR: always |
| 29 | + SKIP: test |
| 30 | + |
| 31 | + resolve: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + outputs: |
| 34 | + MSRV: ${{ steps.resolve-msrv.outputs.MSRV }} |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: set up python |
| 39 | + uses: actions/setup-python@v5 |
| 40 | + with: |
| 41 | + python-version: '3.12' |
| 42 | + |
| 43 | + - name: resolve MSRV |
| 44 | + id: resolve-msrv |
| 45 | + run: |
| 46 | + echo MSRV=`python -c 'import tomllib; print(tomllib.load(open("Cargo.toml", "rb"))["package"]["rust-version"])'` >> $GITHUB_OUTPUT |
| 47 | + |
| 48 | + test: |
| 49 | + needs: [resolve] |
| 50 | + name: test rust-${{ matrix.rust-version }} |
| 51 | + strategy: |
| 52 | + fail-fast: false |
| 53 | + matrix: |
| 54 | + rust-version: [stable, nightly] |
| 55 | + include: |
| 56 | + - rust-version: ${{ needs.resolve.outputs.MSRV }} |
| 57 | + |
| 58 | + runs-on: ubuntu-latest |
| 59 | + |
| 60 | + env: |
| 61 | + RUST_VERSION: ${{ matrix.rust-version }} |
| 62 | + |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v3 |
| 65 | + |
| 66 | + - uses: dtolnay/rust-toolchain@master |
| 67 | + with: |
| 68 | + toolchain: ${{ matrix.rust-version }} |
| 69 | + |
| 70 | + - id: cache-rust |
| 71 | + uses: Swatinem/rust-cache@v2 |
| 72 | + |
| 73 | + - uses: taiki-e/install-action@cargo-llvm-cov |
| 74 | + |
| 75 | + - run: cargo llvm-cov --all-features --codecov --output-path codecov.json |
| 76 | + |
| 77 | + - uses: codecov/codecov-action@v3 |
| 78 | + with: |
| 79 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 80 | + files: codecov.json |
| 81 | + env_vars: RUST_VERSION |
| 82 | + |
| 83 | + # https://github.com/marketplace/actions/alls-green#why used for branch protection checks |
| 84 | + check: |
| 85 | + if: always() |
| 86 | + needs: [test, lint] |
| 87 | + runs-on: ubuntu-latest |
| 88 | + steps: |
| 89 | + - name: Decide whether the needed jobs succeeded or failed |
| 90 | + uses: re-actors/alls-green@release/v1 |
| 91 | + with: |
| 92 | + jobs: ${{ toJSON(needs) }} |
| 93 | + |
| 94 | + release: |
| 95 | + needs: [check] |
| 96 | + if: "success() && startsWith(github.ref, 'refs/tags/')" |
| 97 | + runs-on: ubuntu-latest |
| 98 | + environment: release |
| 99 | + |
| 100 | + steps: |
| 101 | + - uses: actions/checkout@v2 |
| 102 | + |
| 103 | + - name: install rust stable |
| 104 | + uses: dtolnay/rust-toolchain@stable |
| 105 | + |
| 106 | + - uses: Swatinem/rust-cache@v2 |
| 107 | + |
| 108 | + - run: cargo publish |
| 109 | + env: |
| 110 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
0 commit comments