|
6 | 6 | pull_request: |
7 | 7 | workflow_dispatch: |
8 | 8 |
|
9 | | -env: |
10 | | - CARGO_INCREMENTAL: 0 |
11 | | - RUSTUP_MAX_RETRIES: 10 |
12 | | - CARGO_NET_RETRY: 10 |
13 | | - RUST_BACKTRACE: full |
| 9 | +defaults: |
| 10 | + run: |
| 11 | + shell: bash |
14 | 12 |
|
15 | 13 | jobs: |
16 | | - fmt: |
17 | | - name: Rustfmt |
18 | | - runs-on: ubuntu-latest |
19 | | - steps: |
20 | | - - uses: actions/checkout@v6 |
21 | | - - run: rustup component add rustfmt |
22 | | - - run: cargo fmt --all -- --check |
23 | | - |
24 | | - rust: |
25 | | - name: Rust |
| 14 | + test: |
| 15 | + name: Test |
26 | 16 | runs-on: ${{ matrix.os }} |
27 | | - |
28 | 17 | strategy: |
29 | | - fail-fast: false |
| 18 | + fail-fast: true |
30 | 19 | matrix: |
31 | | - os: [ubuntu-latest] |
32 | | - |
| 20 | + os: [ ubuntu-latest ] |
33 | 21 | steps: |
34 | | - - name: Checkout repository |
35 | | - uses: actions/checkout@v6 |
| 22 | + - uses: actions/checkout@v6 |
36 | 23 | with: { submodules: 'recursive' } |
| 24 | + - if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' |
| 25 | + uses: Swatinem/rust-cache@v2 |
| 26 | + - uses: taiki-e/install-action@v2 |
| 27 | + with: { tool: 'just,cargo-binstall' } |
| 28 | + - run: just ci-test |
37 | 29 |
|
38 | | - - name: Cache cargo registry |
39 | | - uses: actions/cache@v5 |
40 | | - with: |
41 | | - path: ~/.cargo/registry |
42 | | - key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} |
43 | | - - name: Cache cargo index |
44 | | - uses: actions/cache@v5 |
45 | | - with: |
46 | | - path: ~/.cargo/git |
47 | | - key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} |
48 | | - - name: Cache cargo target dir |
49 | | - uses: actions/cache@v5 |
| 30 | + test-msrv: |
| 31 | + name: Test MSRV |
| 32 | + runs-on: ubuntu-latest |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v6 |
| 35 | + with: { submodules: 'recursive' } |
| 36 | + - if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' |
| 37 | + uses: Swatinem/rust-cache@v2 |
| 38 | + - uses: taiki-e/install-action@v2 |
| 39 | + with: { tool: 'just' } |
| 40 | + - name: Read MSRV |
| 41 | + id: msrv |
| 42 | + run: echo "value=$(just get-msrv)" >> $GITHUB_OUTPUT |
| 43 | + - name: Install MSRV Rust ${{ steps.msrv.outputs.value }} |
| 44 | + uses: dtolnay/rust-toolchain@stable |
50 | 45 | with: |
51 | | - path: target |
52 | | - key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} |
| 46 | + toolchain: ${{ steps.msrv.outputs.value }} |
| 47 | + - run: just ci_mode=0 ci-test-msrv # Ignore warnings in MSRV |
53 | 48 |
|
54 | | - - name: Build |
55 | | - run: cargo build --workspace --all-features --all-targets --verbose |
56 | | - - name: Tests |
57 | | - run: cargo test --workspace --all-features --all-targets --verbose |
| 49 | + coverage: |
| 50 | + name: Code Coverage |
| 51 | + if: github.event_name != 'release' |
| 52 | + runs-on: ubuntu-latest |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v6 |
| 55 | + with: { submodules: 'recursive' } |
| 56 | + - uses: Swatinem/rust-cache@v2 |
| 57 | + - uses: taiki-e/install-action@v2 |
| 58 | + with: { tool: 'just,cargo-llvm-cov' } |
| 59 | + - name: Generate code coverage |
| 60 | + run: just ci-coverage |
| 61 | + - name: Upload coverage to Codecov |
| 62 | + uses: codecov/codecov-action@v5 |
| 63 | + with: |
| 64 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 65 | + files: target/llvm-cov/codecov.info |
58 | 66 |
|
59 | | - - name: Install Rust targets we use for embedded |
60 | | - run: rustup target install thumbv7em-none-eabihf |
61 | | - - name: Build for embedded |
62 | | - run: cargo build -p can-embedded --target=thumbv7em-none-eabihf --no-default-features |
| 67 | + # This job checks if any of the previous jobs failed or were canceled. |
| 68 | + # This approach also allows some jobs to be skipped if they are not needed. |
| 69 | + ci-passed: |
| 70 | + needs: [ test, test-msrv ] |
| 71 | + if: always() |
| 72 | + runs-on: ubuntu-latest |
| 73 | + steps: |
| 74 | + - name: Result of the needed steps |
| 75 | + run: echo "${{ toJSON(needs) }}" |
| 76 | + - if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} |
| 77 | + run: exit 1 |
63 | 78 |
|
64 | | - - name: Install clippy |
65 | | - run: rustup component add clippy |
66 | | - - name: Annotate commit with clippy warnings |
67 | | - if: startsWith(matrix.os, 'ubuntu') |
68 | | - run: cargo clippy --workspace --all-features --all-targets |
| 79 | + # Release unpublished packages or create a PR with changes |
| 80 | + release-plz: |
| 81 | + needs: [ ci-passed ] |
| 82 | + if: | |
| 83 | + always() |
| 84 | + && needs.ci-passed.result == 'success' |
| 85 | + && github.event_name == 'push' |
| 86 | + && github.ref == 'refs/heads/main' |
| 87 | + && github.repository_owner == 'oxibus' |
| 88 | + runs-on: ubuntu-latest |
| 89 | + permissions: |
| 90 | + contents: write |
| 91 | + id-token: write |
| 92 | + pull-requests: write |
| 93 | + concurrency: |
| 94 | + group: release-plz-${{ github.ref }} |
| 95 | + cancel-in-progress: false |
| 96 | + steps: |
| 97 | + - uses: actions/checkout@v6 |
| 98 | + with: { fetch-depth: 0 } |
| 99 | + - uses: dtolnay/rust-toolchain@stable |
| 100 | + - name: Publish to crates.io if crate's version is newer |
| 101 | + uses: release-plz/action@v0.5 |
| 102 | + id: release |
| 103 | + with: { command: release, verbose: 1 } |
| 104 | + env: |
| 105 | + GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }} |
| 106 | + - if: ${{ steps.release.outputs.releases_created == 'false' }} |
| 107 | + name: If version is the same, create a PR proposing new version and changelog for the next release |
| 108 | + uses: release-plz/action@v0.5 |
| 109 | + with: { command: release-pr, verbose: 1 } |
| 110 | + env: |
| 111 | + GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }} |
0 commit comments