From 68684896ff94e5d071864085f2ee989f66f8e9ad Mon Sep 17 00:00:00 2001 From: SteveLauC Date: Wed, 8 Nov 2023 08:53:46 +0800 Subject: [PATCH] chore: try GitHub Action (#2166) * chore: try GitHub Action * fix branch name * migrate 33 tasks * add RUSTFLAGS and RUSTDOCFLAGS to env * respond to review --- .github/actions/build/action.yml | 72 +++++++ .github/actions/test/action.yml | 27 +++ .github/workflows/ci.yml | 334 +++++++++++++++++++++++++++++++ 3 files changed, 433 insertions(+) create mode 100644 .github/actions/build/action.yml create mode 100644 .github/actions/test/action.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml new file mode 100644 index 0000000000..9cf2fbff5d --- /dev/null +++ b/.github/actions/build/action.yml @@ -0,0 +1,72 @@ +name: 'Build' +description: 'Build nix' +inputs: + # This is required + TARGET: + required: true + + BUILD: + required: false + default: build + + CLIPPYFLAGS: + required: false + default: -D warnings -A unknown-lints + + RUSTFLAGS: + required: false + default: -D warnings -A unknown-lints + + RUSTDOCFLAGS: + required: false + default: -D warnings + + TOOL: + description: 'Tool used to involve the BUILD command, can be cargo or cross' + required: false + default: cargo + + ZFLAGS: + required: false + default: + + NOHACK: + description: "whether to run cargo hack" + required: false + default: false + +runs: + using: "composite" + steps: + - name: set up Rust env + shell: bash + run: | + echo "RUSTFLAGS=${{ inputs.RUSTFLAGS }}" >> $GITHUB_ENV + echo "RUSTDOCFLAGS=${{ inputs.RUSTDOCFLAGS }}" >> $GITHUB_ENV + + - name: debug info + shell: bash + run: | + ${{ inputs.TOOL }} -Vv + rustc -Vv + + - name: build + shell: bash + run: ${{ inputs.TOOL }} ${{ inputs.BUILD }} ${{ inputs.ZFLAGS }} --target ${{ inputs.TARGET }} --all-targets --all-features + + - name: doc + shell: bash + run: ${{ inputs.TOOL }} doc ${{ inputs.ZFLAGS }} --no-deps --target ${{ inputs.TARGET }} --all-features + + - name: clippy + shell: bash + run: ${{ inputs.TOOL}} clippy ${{ inputs.ZFLAGS }} --target ${{ inputs.TARGET }} --all-targets --all-features -- ${{ inputs.CLIPPYFLAGS }} + + - name: Set up cargo-hack + if: inputs.NOHACK == 'false' + uses: taiki-e/install-action@cargo-hack + + - name: run cargo hack + shell: bash + if: inputs.NOHACK == 'false' + run: ${{ inputs.TOOL }} hack ${{ inputs.ZFLAGS }} check --target ${{ inputs.TARGET }} --each-feature diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml new file mode 100644 index 0000000000..ce011a2da2 --- /dev/null +++ b/.github/actions/test/action.yml @@ -0,0 +1,27 @@ +name: 'Test' +description: 'Test nix' +inputs: + # This is required + TARGET: + required: true + + TOOL: + description: 'Tool used to involve the test command, can be cargo or cross' + required: false + default: cargo + + RUSTFLAGS: + required: false + default: -D warnings -A unknown-lints + +runs: + using: "composite" + steps: + - name: set up Rust env + shell: bash + run: | + echo "RUSTFLAGS=${{ inputs.RUSTFLAGS }}" >> $GITHUB_ENV + + - name: test + shell: bash + run: ${{ inputs.TOOL }} test --target ${{ inputs.TARGET }} --all-features diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..0ff0afe5af --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,334 @@ +name: CI + +on: + pull_request: + types: [opened, synchronize, reopened] + push: + branches: + - master + +permissions: + contents: read + +env: + MSRV: 1.69.0 + +jobs: + + macos: + runs-on: macos-13 + env: + TARGET: x86_64-apple-darwin + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: setup Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: '${{ env.MSRV }}' + components: clippy + + - name: build + uses: ./.github/actions/build + with: + TARGET: '${{ env.TARGET }}' + + - name: test + uses: ./.github/actions/test + with: + TARGET: '${{ env.TARGET }}' + + - name: before_cache_script + run: rm -rf $CARGO_HOME/registry/index + + + # Use cross for QEMU-based testing + # cross needs to execute Docker, GitHub Action already has it installed + cross: + runs-on: ubuntu-20.04 + needs: [rustfmt, minver, macos, linux_native_builds, rust_stable] + strategy: + fail-fast: false + matrix: + target: [ + arm-unknown-linux-gnueabi, + armv7-unknown-linux-gnueabihf, + i686-unknown-linux-gnu, + i686-unknown-linux-musl, + mips-unknown-linux-gnu, + mips64-unknown-linux-gnuabi64, + mips64el-unknown-linux-gnuabi64, + mipsel-unknown-linux-gnu, + powerpc64le-unknown-linux-gnu, + ] + + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: setup Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: '${{ env.MSRV }}' + components: clippy + + # cross relies on docker or podman, GitHub Acton already has it installed. + - name: Set up cross + uses: taiki-e/install-action@v2 + with: + tool: cross@0.2.5 + + - name: build + uses: ./.github/actions/build + with: + TARGET: '${{ matrix.target }}' + TOOL: cross + RUSTFLAGS: --cfg qemu -D warnings + + - name: test + uses: ./.github/actions/test + with: + TARGET: '${{ matrix.target }}' + TOOL: cross + RUSTFLAGS: --cfg qemu -D warnings + + - name: before_cache_script + run: rm -rf $CARGO_HOME/registry/index + + + + # Tasks for Linux native builds + # Only test x86_64 targets on GitHub Action, leave aarch64 one in Cirrus CI. + linux_native_builds: + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + target: [ + x86_64-unknown-linux-gnu, + x86_64-unknown-linux-musl, + ] + + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: setup Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: '${{ env.MSRV }}' + components: clippy + + - name: install targets + run: rustup target add ${{ matrix.target }} + + - name: build + uses: ./.github/actions/build + with: + TARGET: '${{ matrix.TARGET }}' + + - name: test + uses: ./.github/actions/test + with: + TARGET: '${{ matrix.TARGET }}' + + - name: before_cache_script + run: rm -rf $CARGO_HOME/registry/index + + rust_stable: + runs-on: ubuntu-20.04 + env: + TARGET: x86_64-unknown-linux-gnu + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: setup Rust + uses: dtolnay/rust-toolchain@stable + with: + components: clippy + + - name: build + uses: ./.github/actions/build + with: + TARGET: '${{ env.TARGET }}' + + - name: test + uses: ./.github/actions/test + with: + TARGET: '${{ env.TARGET }}' + + - name: before_cache_script + run: rm -rf $CARGO_HOME/registry/index + + + + # Tasks for cross-compiling, but no testing + cross_compiling: + runs-on: ubuntu-20.04 + needs: [rustfmt, minver, macos, linux_native_builds, rust_stable] + env: + BUILD: check + strategy: + fail-fast: false + matrix: + include: + # Cross claims to support Android, but when it tries to run Nix's tests it + # reports undefined symbol references. + - target: aarch64-linux-android + - target: arm-linux-androideabi + - target: armv7-linux-androideabi + - target: i686-linux-android + - target: x86_64-linux-android + - target: arm-unknown-linux-musleabi + - target: x86_64-unknown-fuchsia + - target: x86_64-unknown-illumos + # Cross claims to support running tests on iOS, but it actually doesn't. + # https://github.com/rust-embedded/cross/issues/535 + - target: aarch64-apple-ios + # cargo hack tries to invoke the iphonesimulator SDK for iOS + NOHACK: true + # Cross claims to support Linux powerpc64, but it really doesn't. + # https://github.com/rust-embedded/cross/issues/441 + - target: powerpc64-unknown-linux-gnu + - target: s390x-unknown-linux-gnu + - target: x86_64-unknown-linux-gnux32 + - target: x86_64-unknown-netbsd + + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: setup Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: '${{ env.MSRV }}' + components: clippy + + - name: install targets + run: rustup target add ${{ matrix.target }} + + - name: build + uses: ./.github/actions/build + with: + TARGET: '${{ matrix.target }}' + BUILD: '${{ env.BUILD }}' + NOHACK: '${{ matrix.NOHACK }}' + + - name: before_cache_script + run: rm -rf $CARGO_HOME/registry/index + + + redox: + runs-on: ubuntu-20.04 + needs: [rustfmt, minver, macos, linux_native_builds, rust_stable] + env: + TARGET: x86_64-unknown-redox + CLIPPYFLAGS: -D warnings + BUILD: check + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: setup Rust + # Redox's MSRV policy is unclear. Until they define it, use nightly. + uses: dtolnay/rust-toolchain@nightly + with: + components: clippy + + - name: install targets + run: rustup target add ${{ env.TARGET }} + + - name: build + uses: ./.github/actions/build + with: + TARGET: '${{ env.TARGET }}' + BUILD: '${{ env.BUILD }}' + CLIPPYFLAGS: '${{ env.CLIPPYFLAGS }}' + + - name: before_cache_script + run: rm -rf $CARGO_HOME/registry/index + + + + # Rust Tier 3 targets can't use Rustup + tier3: + runs-on: ubuntu-20.04 + env: + BUILD: check + ZFLAGS: -Zbuild-std + CLIPPYFLAGS: -D warnings + strategy: + fail-fast: false + matrix: + include: + - target: x86_64-unknown-dragonfly + - target: x86_64-unknown-openbsd + - target: armv7-unknown-linux-uclibceabihf + - target: x86_64-unknown-haiku + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: setup Rust + uses: dtolnay/rust-toolchain@nightly + with: + components: clippy + + - name: install src + run: rustup component add rust-src + + - name: build + uses: ./.github/actions/build + with: + TARGET: '${{ matrix.target }}' + BUILD: '${{ env.BUILD }}' + ZFLAGS: '${{ env.ZFLAGS }}' + CLIPPYFLAGS: '${{ env.CLIPPYFLAGS }}' + + - name: before_cache_script + run: rm -rf $CARGO_HOME/registry/index + + + # Test that we can build with the lowest version of all dependencies. + # "cargo test" doesn't work because some of our dev-dependencies, like + # rand, can't build with their own minimal dependencies. + minver: + runs-on: ubuntu-20.04 + env: + TARGET: x86_64-unknown-linux-gnu + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: setup Rust + uses: dtolnay/rust-toolchain@nightly + + - name: setup + run: cargo update -Zminimal-versions + + - name: check + run: cargo check + + - name: before_cache_script + run: rm -rf $CARGO_HOME/registry/index + + # Tasks that checks if the code is formatted right using `cargo fmt` tool + rustfmt: + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + + - name: Check format + run: cargo fmt --all -- --check **/*.rs + + - name: before_cache_script + run: rm -rf $CARGO_HOME/registry/index +