diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9648236..bd0a709 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,143 +1,295 @@ -name: Rust +# Main CI workflow to validate PRs and branches are correctly formatted +# and pass tests. +# +# CI workflow was based on a lot of work from other people: +# - https://github.com/heim-rs/heim/blob/master/.github/workflows/ci.yml +# - https://github.com/BurntSushi/ripgrep/blob/master/.github/workflows/ci.yml +# - https://www.reillywood.com/blog/rust-faster-ci/ +# - https://matklad.github.io/2021/09/04/fast-rust-builds.html +# +# Supported platforms run the following tasks: +# - cargo fmt +# - cargo test (built/test in separate steps) +# - cargo clippy (apparently faster to do it after the build/test) +# +# Unsupported platforms run the following tasks: +# - cargo build +# +# Note that not all platforms are tested using this CI action! There are some +# tested by Cirrus CI due to (free) platform limitations on GitHub. Currently, +# this is just macOS M1 and FreeBSD. + +name: ci on: - push: + workflow_dispatch: pull_request: + push: + branches: + - main env: - CARGO_TERM_COLOR: always + RUST_BACKTRACE: 1 + CARGO_INCREMENTAL: 0 + CARGO_PROFILE_DEV_DEBUG: 0 + CARGO_HUSKY_DONT_INSTALL_HOOKS: true + COMPLETION_DIR: "target/tmp/bottom/completion/" + MANPAGE_DIR: "target/tmp/bottom/manpage/" -defaults: - run: - # necessary for windows - shell: bash +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' || github.repository != 'ClementTsang/bottom' }} jobs: - test: + # Check if things should be skipped. + pre-job: runs-on: ubuntu-latest + outputs: + should_skip: ${{ steps.skip_check.outputs.should_skip }} steps: - - uses: actions/checkout@v2 - - name: Cargo cache - uses: actions/cache@v2 + - name: Check if this action should be skipped + id: skip_check + uses: fkirc/skip-duplicate-actions@f75f66ce1886f00957d99748a42c724f4330bdcf # v5.3.1 with: - path: | - ~/.cargo/registry - ./target - key: test-cargo-registry - - name: List - run: find ./ - - name: Run tests - run: cargo test --verbose + skip_after_successful_duplicate: "true" + paths: '[".cargo/**", ".github/workflows/ci.yml", "sample_configs/**", "src/**", "tests/**", "build.rs", "Cargo.lock", "Cargo.toml", "clippy.toml", "rustfmt.toml", "Cross.toml"]' + do_not_skip: '["workflow_dispatch", "push"]' - build: + # Runs rustfmt + tests + clippy on the main supported platforms. + # + # Note that m1 macOS is tested via CirrusCI. + supported: + needs: pre-job + if: ${{ needs.pre-job.outputs.should_skip != 'true' }} + runs-on: ${{ matrix.info.os }} + timeout-minutes: 18 strategy: fail-fast: false matrix: - # a list of all the targets - include: - - TARGET: x86_64-unknown-linux-gnu # tested in a debian container on a mac - OS: ubuntu-latest - - TARGET: x86_64-unknown-linux-musl # test in an alpine container on a mac - OS: ubuntu-latest - - TARGET: aarch64-unknown-linux-gnu # tested on aws t4g.nano - OS: ubuntu-latest - - TARGET: aarch64-unknown-linux-musl # tested on aws t4g.nano in alpine container - OS: ubuntu-latest - - TARGET: armv7-unknown-linux-gnueabihf # raspberry pi 2-3-4, not tested - OS: ubuntu-latest - - TARGET: armv7-unknown-linux-musleabihf # raspberry pi 2-3-4, not tested - OS: ubuntu-latest - - TARGET: arm-unknown-linux-gnueabihf # raspberry pi 0-1, not tested - OS: ubuntu-latest - - TARGET: arm-unknown-linux-musleabihf # raspberry pi 0-1, not tested - OS: ubuntu-latest - - TARGET: x86_64-apple-darwin # tested on a mac, is not properly signed so there are security warnings - OS: macos-latest - - TARGET: x86_64-pc-windows-msvc # tested on a windows machine - OS: windows-latest - needs: test - runs-on: ${{ matrix.OS }} - env: - NAME: rust-cross-compile-example # change with the name of your project - TARGET: ${{ matrix.TARGET }} - OS: ${{ matrix.OS }} + info: + - { + os: "ubuntu-latest", + target: "x86_64-unknown-linux-gnu", + cross: false, + } + - { + os: "ubuntu-latest", + target: "aarch64-unknown-linux-gnu", + cross: true, + } + - { os: "macos-12", target: "x86_64-apple-darwin", cross: false } + - { + os: "windows-2019", + target: "x86_64-pc-windows-msvc", + cross: false, + } + features: ["--all-features", "--no-default-features"] steps: - - uses: actions/checkout@v2 - - name: Cargo cache - uses: actions/cache@v2 + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Set up Rust toolchain + uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248 with: - path: | - ~/.cargo/registry - ./target - key: build-cargo-registry-${{matrix.TARGET}} - - name: List - run: find ./ - - name: Install and configure dependencies - run: | - # dependencies are only needed on ubuntu as that's the only place where - # we make cross-compilation - if [[ $OS =~ ^ubuntu.*$ ]]; then - sudo apt-get install -qq crossbuild-essential-arm64 crossbuild-essential-armhf - fi - - # some additional configuration for cross-compilation on linux - cat >>~/.cargo/config <