From 49d6bf602d0a668531098387b98ec8dbfb66636c Mon Sep 17 00:00:00 2001 From: David Peter Date: Thu, 2 Nov 2023 08:17:18 +0100 Subject: [PATCH] CI updates --- .github/workflows/CICD.yml | 211 ++++++++++++++++--------------------- Cargo.toml | 6 ++ clippy.toml | 1 - 3 files changed, 99 insertions(+), 119 deletions(-) delete mode 100644 clippy.toml diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 0144b7af..8148aa05 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1,8 +1,8 @@ name: CICD env: - MIN_SUPPORTED_RUST_VERSION: "1.60.0" CICD_INTERMEDIATES_DIR: "_cicd-intermediates" + MSRV_FEATURES: "" on: workflow_dispatch: @@ -14,76 +14,75 @@ on: - '*' jobs: - code_quality: - name: Code quality + crate_metadata: + name: Extract crate metadata + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Extract crate information + id: crate_metadata + run: | + cargo metadata --no-deps --format-version 1 | jq -r '"name=" + .packages[0].name' | tee -a $GITHUB_OUTPUT + cargo metadata --no-deps --format-version 1 | jq -r '"version=" + .packages[0].version' | tee -a $GITHUB_OUTPUT + cargo metadata --no-deps --format-version 1 | jq -r '"maintainer=" + .packages[0].authors[0]' | tee -a $GITHUB_OUTPUT + cargo metadata --no-deps --format-version 1 | jq -r '"homepage=" + .packages[0].homepage' | tee -a $GITHUB_OUTPUT + cargo metadata --no-deps --format-version 1 | jq -r '"msrv=" + .packages[0].rust_version' | tee -a $GITHUB_OUTPUT + outputs: + name: ${{ steps.crate_metadata.outputs.name }} + version: ${{ steps.crate_metadata.outputs.version }} + maintainer: ${{ steps.crate_metadata.outputs.maintainer }} + homepage: ${{ steps.crate_metadata.outputs.homepage }} + msrv: ${{ steps.crate_metadata.outputs.msrv }} + + ensure_cargo_fmt: + name: Ensure 'cargo fmt' has been run runs-on: ubuntu-20.04 steps: - - name: Checkout source code - uses: actions/checkout@v4 - - name: Install rust toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - default: true - profile: minimal # minimal component installation (ie, no documentation) - components: clippy, rustfmt - - name: Ensure `cargo fmt` has been run - uses: actions-rs/cargo@v1 + - uses: dtolnay/rust-toolchain@stable with: - command: fmt - args: -- --check - - name: Ensure MSRV is set in `clippy.toml` - run: grep "^msrv = \"${{ env.MIN_SUPPORTED_RUST_VERSION }}\"\$" clippy.toml - - name: Run clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --locked --all-targets --all-features + components: rustfmt + - uses: actions/checkout@v4 + - run: cargo fmt -- --check min_version: name: Minimum supported rust version runs-on: ubuntu-20.04 + needs: crate_metadata steps: - name: Checkout source code uses: actions/checkout@v4 - - name: Install rust toolchain (v${{ env.MIN_SUPPORTED_RUST_VERSION }}) - uses: actions-rs/toolchain@v1 + - name: Install rust toolchain (v${{ needs.crate_metadata.outputs.msrv }}) + uses: dtolnay/rust-toolchain@master with: - toolchain: ${{ env.MIN_SUPPORTED_RUST_VERSION }} - default: true + toolchain: ${{ needs.crate_metadata.outputs.msrv }} components: clippy - profile: minimal # minimal component installation (ie, no documentation) - name: Run clippy (on minimum supported rust version to prevent warnings we can't fix) - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --locked --all-targets --all-features + run: cargo clippy --locked --all-targets ${{ env.MSRV_FEATURES }} - name: Run tests - uses: actions-rs/cargo@v1 - with: - command: test - args: --locked + run: cargo test --locked ${{ env.MSRV_FEATURES }} build: - name: ${{ matrix.job.os }} (${{ matrix.job.target }}) + name: ${{ matrix.job.target }} (${{ matrix.job.os }}) runs-on: ${{ matrix.job.os }} + needs: crate_metadata strategy: fail-fast: false matrix: job: - - { os: ubuntu-20.04, target: arm-unknown-linux-gnueabihf , use-cross: true } - - { os: ubuntu-20.04, target: arm-unknown-linux-musleabihf, use-cross: true } - - { os: ubuntu-20.04, target: aarch64-unknown-linux-gnu , use-cross: true } - - { os: ubuntu-20.04, target: i686-unknown-linux-gnu , use-cross: true } - - { os: ubuntu-20.04, target: i686-unknown-linux-musl , use-cross: true } - - { os: ubuntu-20.04, target: x86_64-unknown-linux-gnu , use-cross: true } - - { os: ubuntu-20.04, target: x86_64-unknown-linux-musl , use-cross: true } - - { os: macos-latest , target: x86_64-apple-darwin } - # - { os: windows-2019, target: i686-pc-windows-gnu } ## disabled; error: linker `i686-w64-mingw32-gcc` not found - - { os: windows-2019, target: i686-pc-windows-msvc } - - { os: windows-2019, target: x86_64-pc-windows-gnu } - - { os: windows-2019, target: x86_64-pc-windows-msvc } + - { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true } + - { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04, use-cross: true } + - { target: arm-unknown-linux-musleabihf, os: ubuntu-20.04, use-cross: true } + - { target: i686-pc-windows-msvc , os: windows-2019 } + - { target: i686-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true } + - { target: i686-unknown-linux-musl , os: ubuntu-20.04, use-cross: true } + - { target: x86_64-apple-darwin , os: macos-12 } + - { target: x86_64-pc-windows-gnu , os: windows-2019 } + - { target: x86_64-pc-windows-msvc , os: windows-2019 } + - { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true } + - { target: x86_64-unknown-linux-musl , os: ubuntu-20.04, use-cross: true } + env: + BUILD_CMD: cargo steps: - name: Checkout source code uses: actions/checkout@v4 @@ -96,21 +95,21 @@ jobs: aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;; esac - - name: Extract crate information - shell: bash - run: | - echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV - echo "PROJECT_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV - echo "PROJECT_MAINTAINER=$(sed -n 's/^authors = \["\(.*\)"\]/\1/p' Cargo.toml)" >> $GITHUB_ENV - echo "PROJECT_HOMEPAGE=$(sed -n 's/^homepage = "\(.*\)"/\1/p' Cargo.toml)" >> $GITHUB_ENV - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: - toolchain: stable - target: ${{ matrix.job.target }} - override: true - profile: minimal # minimal component installation (ie, no documentation) + targets: ${{ matrix.job.target }} + + - name: Install cross + if: matrix.job.use-cross + uses: taiki-e/install-action@v2 + with: + tool: cross + + - name: Overwrite build command env variable + if: matrix.job.use-cross + shell: bash + run: echo "BUILD_CMD=cross" >> $GITHUB_ENV - name: Show version information (Rust, cargo, GCC) shell: bash @@ -123,14 +122,11 @@ jobs: rustc -V - name: Build - uses: actions-rs/cargo@v1 - with: - use-cross: ${{ matrix.job.use-cross }} - command: build - args: --locked --release --target=${{ matrix.job.target }} + shell: bash + run: $BUILD_CMD build --locked --release --target=${{ matrix.job.target }} - - name: Strip debug information from executable - id: strip + - name: Set binary name & path + id: bin shell: bash run: | # Figure out suffix of binary @@ -139,31 +135,13 @@ jobs: *-pc-windows-*) EXE_suffix=".exe" ;; esac; - # Figure out what strip tool to use if any - STRIP="strip" - case ${{ matrix.job.target }} in - arm-unknown-linux-*) STRIP="arm-linux-gnueabihf-strip" ;; - aarch64-unknown-linux-gnu) STRIP="aarch64-linux-gnu-strip" ;; - *-pc-windows-msvc) STRIP="" ;; - esac; - # Setup paths - BIN_DIR="${{ env.CICD_INTERMEDIATES_DIR }}/stripped-release-bin/" - mkdir -p "${BIN_DIR}" - BIN_NAME="${{ env.PROJECT_NAME }}${EXE_suffix}" - BIN_PATH="${BIN_DIR}/${BIN_NAME}" - - # Copy the release build binary to the result location - cp "target/${{ matrix.job.target }}/release/${BIN_NAME}" "${BIN_DIR}" + BIN_NAME="${{ needs.crate_metadata.outputs.name }}${EXE_suffix}" + BIN_PATH="target/${{ matrix.job.target }}/release/${BIN_NAME}" - # Also strip if possible - if [ -n "${STRIP}" ]; then - "${STRIP}" "${BIN_PATH}" - fi - - # Let subsequent steps know where to find the (stripped) bin - echo ::set-output name=BIN_PATH::${BIN_PATH} - echo ::set-output name=BIN_NAME::${BIN_NAME} + # Let subsequent steps know where to find the binary + echo "BIN_PATH=${BIN_PATH}" >> $GITHUB_OUTPUT + echo "BIN_NAME=${BIN_NAME}" >> $GITHUB_OUTPUT - name: Set testing options id: test-options @@ -171,24 +149,21 @@ jobs: run: | # test only library unit tests and binary for arm-type targets unset CARGO_TEST_OPTIONS - unset CARGO_TEST_OPTIONS ; case ${{ matrix.job.target }} in arm-* | aarch64-*) CARGO_TEST_OPTIONS="--lib --bin ${PROJECT_NAME}" ;; esac; - echo ::set-output name=CARGO_TEST_OPTIONS::${CARGO_TEST_OPTIONS} + unset CARGO_TEST_OPTIONS ; case ${{ matrix.job.target }} in arm-* | aarch64-*) CARGO_TEST_OPTIONS="--bin ${{ needs.crate_metadata.outputs.name }}" ;; esac; + echo "CARGO_TEST_OPTIONS=${CARGO_TEST_OPTIONS}" >> $GITHUB_OUTPUT - name: Run tests - uses: actions-rs/cargo@v1 - with: - use-cross: ${{ matrix.job.use-cross }} - command: test - args: --locked --target=${{ matrix.job.target }} ${{ steps.test-options.outputs.CARGO_TEST_OPTIONS}} + shell: bash + run: $BUILD_CMD test --locked --target=${{ matrix.job.target }} ${{ steps.test-options.outputs.CARGO_TEST_OPTIONS}} - name: Create tarball id: package shell: bash run: | PKG_suffix=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_suffix=".zip" ;; esac; - PKG_BASENAME=${PROJECT_NAME}-v${PROJECT_VERSION}-${{ matrix.job.target }} + PKG_BASENAME=${{ needs.crate_metadata.outputs.name }}-v${{ needs.crate_metadata.outputs.version }}-${{ matrix.job.target }} PKG_NAME=${PKG_BASENAME}${PKG_suffix} - echo ::set-output name=PKG_NAME::${PKG_NAME} + echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_OUTPUT PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package" ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/" @@ -196,7 +171,7 @@ jobs: mkdir -p "${ARCHIVE_DIR}/autocomplete" # Binary - cp "${{ steps.strip.outputs.BIN_PATH }}" "$ARCHIVE_DIR" + cp "${{ steps.bin.outputs.BIN_PATH }}" "$ARCHIVE_DIR" # README, LICENSE and CHANGELOG files cp "README.md" "LICENSE-MIT" "LICENSE-APACHE" "CHANGELOG.md" "$ARCHIVE_DIR" @@ -216,7 +191,7 @@ jobs: popd >/dev/null # Let subsequent steps know where to find the compressed package - echo ::set-output name=PKG_PATH::"${PKG_STAGING}/${PKG_NAME}" + echo "PKG_PATH=${PKG_STAGING}/${PKG_NAME}" >> $GITHUB_OUTPUT - name: Create Debian package id: debian-package @@ -228,10 +203,10 @@ jobs: DPKG_DIR="${DPKG_STAGING}/dpkg" mkdir -p "${DPKG_DIR}" - DPKG_BASENAME=${PROJECT_NAME} - DPKG_CONFLICTS=${PROJECT_NAME}-musl - case ${{ matrix.job.target }} in *-musl) DPKG_BASENAME=${PROJECT_NAME}-musl ; DPKG_CONFLICTS=${PROJECT_NAME} ;; esac; - DPKG_VERSION=${PROJECT_VERSION} + DPKG_BASENAME=${{ needs.crate_metadata.outputs.name }} + DPKG_CONFLICTS=${{ needs.crate_metadata.outputs.name }}-musl + case ${{ matrix.job.target }} in *-musl) DPKG_BASENAME=${{ needs.crate_metadata.outputs.name }}-musl ; DPKG_CONFLICTS=${{ needs.crate_metadata.outputs.name }} ;; esac; + DPKG_VERSION=${{ needs.crate_metadata.outputs.version }} unset DPKG_ARCH case ${{ matrix.job.target }} in @@ -243,10 +218,10 @@ jobs: esac; DPKG_NAME="${DPKG_BASENAME}_${DPKG_VERSION}_${DPKG_ARCH}.deb" - echo ::set-output name=DPKG_NAME::${DPKG_NAME} + echo "DPKG_NAME=${DPKG_NAME}" >> $GITHUB_OUTPUT # Binary - install -Dm755 "${{ steps.strip.outputs.BIN_PATH }}" "${DPKG_DIR}/usr/bin/${{ steps.strip.outputs.BIN_NAME }}" + install -Dm755 "${{ steps.bin.outputs.BIN_PATH }}" "${DPKG_DIR}/usr/bin/${{ steps.bin.outputs.BIN_NAME }}" # Autocompletion files install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'*/out/'${{ env.PROJECT_NAME }}.bash' "${DPKG_DIR}/usr/share/bash-completion/completions/${{ env.PROJECT_NAME }}" @@ -262,12 +237,12 @@ jobs: cat > "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/copyright" <> $GITHUB_OUTPUT # build dpkg fakeroot dpkg-deb --build "${DPKG_DIR}" "${DPKG_PATH}" @@ -340,7 +315,7 @@ jobs: shell: bash run: | unset IS_RELEASE ; if [[ $GITHUB_REF =~ ^refs/tags/v[0-9].* ]]; then IS_RELEASE='true' ; fi - echo ::set-output name=IS_RELEASE::${IS_RELEASE} + echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT - name: Publish archives and packages uses: softprops/action-gh-release@v1 diff --git a/Cargo.toml b/Cargo.toml index f345bdcb..3829165f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ version = "0.9.0" edition = "2021" build = "build.rs" exclude = ["doc/pastel.gif"] +rust-version = "1.70.0" [dependencies] # library dependencies @@ -47,3 +48,8 @@ criterion = "0.4" [[bench]] name = "parse_color" harness = false + +[profile.release] +lto = true +strip = true +codegen-units = 1 diff --git a/clippy.toml b/clippy.toml deleted file mode 100644 index 16caf02e..00000000 --- a/clippy.toml +++ /dev/null @@ -1 +0,0 @@ -msrv = "1.60.0"