From 6efbb031c8c11e92daf10a9601c95e94c8d359a4 Mon Sep 17 00:00:00 2001 From: Daan Steenbergen Date: Tue, 8 Aug 2023 13:50:09 +0200 Subject: [PATCH] - Made CI actions run in parallel to be able extract the most information - Fix coverage report unable to find PR number when pushing to branch without open PR - Give descriptive names to all steps in CI actions - Only update documentation based on changes to the main branch - Renamed build.yml to ci.yml --- .github/workflows/build.yml | 85 ---------------------------- .github/workflows/ci.yml | 108 ++++++++++++++++++++++++++++++++++++ .github/workflows/docs.yml | 20 +++++-- 3 files changed, 123 insertions(+), 90 deletions(-) delete mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 626133e..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,85 +0,0 @@ -name: Build -on: [push] - -jobs: - rustfmt: - runs-on: ubuntu-latest - env: - CARGO_TERM_COLOR: always - NUM_JOBS: 2 - steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - override: true - components: rustfmt, clippy - - uses: Swatinem/rust-cache@v2 - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --check - - # Run the build, clippy, and test commands in the same job in serial so they can share the same - # build directory, and hopefully run faster. - build-lint-test: - runs-on: ubuntu-latest - env: - RUSTFLAGS: -Dwarnings - CARGO_TERM_COLOR: always - NUM_JOBS: 2 - steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - override: true - components: rustfmt, clippy - - uses: Swatinem/rust-cache@v2 - - uses: taiki-e/install-action@v2 - with: - tool: cargo-tarpaulin - - - name: Build - uses: actions-rs/cargo@v1 - with: - command: build - args: --release --all-targets --all-features - - - name: Lint - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --release --all-targets --all-features - - - name: Test - uses: actions-rs/cargo@v1 - with: - command: tarpaulin - args: --release --all-features --out xml - - # TODO: Code coverage badge on README - - - name: Get Pull Request Number - id: pr - run: echo "pull_request_number=$(gh pr view --json number -q .number || echo "")" >> $GITHUB_OUTPUT - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - run: echo "Found PR number '${{ steps.pr.outputs.pull_request_number }}' with the github CLI" - - - name: PR coverage report comment - uses: 5monkeys/cobertura-action@v13 - if: github.ref != 'refs/heads/main' - with: - path: 'cobertura.xml' - repo_token: ${{ secrets.GITHUB_TOKEN }} - pull_request_number: ${{ steps.pr.outputs.pull_request_number }} - only_changed_files: true - show_line: true - show_branch: true - skip_covered: false - # If we want to enforce a minimum coverage percentage, this is how. - minimum_coverage: 0 - fail_below_threshold: false diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7e18d79 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,108 @@ +name: CI + +on: + push: + pull_request: + types: [opened, synchronize, reopened] + +env: + CARGO_TERM_COLOR: always + NUM_JOBS: 2 + +jobs: + # Run Format, Lint, and Test in parallel. This way we can get feedback on all topics + # instead of (possibly) failing fast on the first one. It should also be faster. + rustfmt: + name: Format + runs-on: ubuntu-latest + + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + components: rustfmt + + - name: Setup cache + uses: Swatinem/rust-cache@v2 + + - name: Check formatting + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --check + + lint: + name: Lint + runs-on: ubuntu-latest + + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + components: clippy + + - name: Setup cache + uses: Swatinem/rust-cache@v2 + + - name: Check linting + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-targets --all-features + + test_coverage: + name: Test and coverage + runs-on: ubuntu-latest + + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Setup cache + uses: Swatinem/rust-cache@v2 + + - name: Setup tarpaulin + uses: taiki-e/install-action@v2 + with: + tool: cargo-tarpaulin + + - name: Test + uses: actions-rs/cargo@v1 + with: + command: tarpaulin + args: --release --all-features --out xml + + # TODO: Code coverage badge on README (codecov.io?) + + - name: PR coverage report comment + uses: 5monkeys/cobertura-action@v13 + if: github.event_name == 'pull_request' + with: + path: 'cobertura.xml' + repo_token: ${{ secrets.GITHUB_TOKEN }} + only_changed_files: true + show_line: true + show_branch: true + skip_covered: false + # If we want to enforce a minimum coverage percentage, this is how. + minimum_coverage: 0 + fail_below_threshold: false diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 7e4a798..d9fc70d 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,5 +1,10 @@ -name: Build -on: [push] +name: Docs + +# Only publish documentation on changes to the main branch +on: + push: + branches: + - main jobs: rustdoc: @@ -9,13 +14,18 @@ jobs: CARGO_TERM_COLOR: always NUM_JOBS: 2 steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 with: toolchain: stable profile: minimal override: true - - uses: Swatinem/rust-cache@v2 + + - name: Setup cache + uses: Swatinem/rust-cache@v2 - name: Build documentation uses: actions-rs/cargo@v1