From 07d1481149ac3a1775479b887a02b274f6f5c5d2 Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Wed, 11 Jun 2025 08:57:47 +0200 Subject: [PATCH 1/9] Build and test in a matrix Signed-off-by: Wiktor Kwapisiewicz --- .github/actions/ci_script/action.yml | 37 --------------------------- .github/workflows/ci.yml | 38 +++++++++++++++++++++++++--- ci.sh | 30 +++++++--------------- 3 files changed, 44 insertions(+), 61 deletions(-) delete mode 100644 .github/actions/ci_script/action.yml diff --git a/.github/actions/ci_script/action.yml b/.github/actions/ci_script/action.yml deleted file mode 100644 index 18a98e3a..00000000 --- a/.github/actions/ci_script/action.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: "CI script Tests" -description: "Installs SoftHSM and executes tests" - -runs: - using: "composite" - steps: - - name: Install SoftHSM - run: | - sudo apt-get update -y -qq && - sudo apt-get install -y -qq libsofthsm2 && - mkdir /tmp/tokens - echo "directories.tokendir = /tmp/tokens" > /tmp/softhsm2.conf - shell: bash - - - name: Install Rust targets - run: | - rustup target add armv7-unknown-linux-gnueabi && - rustup target add armv7-unknown-linux-gnueabihf && - rustup target add arm-unknown-linux-gnueabi && - rustup target add aarch64-unknown-linux-gnu && - rustup target add i686-unknown-linux-gnu && - rustup target add loongarch64-unknown-linux-gnu && - rustup target add powerpc64-unknown-linux-gnu && - rustup target add powerpc64le-unknown-linux-gnu && - rustup target add x86_64-pc-windows-msvc && - rustup target add x86_64-apple-darwin && - rustup target add aarch64-apple-darwin && - rustup target add x86_64-unknown-freebsd && - rustup target add riscv64gc-unknown-linux-gnu - shell: bash - - - name: Test script - env: - TEST_PKCS11_MODULE: /usr/lib/softhsm/libsofthsm2.so - SOFTHSM2_CONF: /tmp/softhsm2.conf - run: ./ci.sh - shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 085fc4f0..620906b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,14 +32,46 @@ jobs: build: name: Execute CI script runs-on: ubuntu-latest + strategy: + matrix: + target: + - armv7-unknown-linux-gnueabi + - armv7-unknown-linux-gnueabihf + - arm-unknown-linux-gnueabi + - aarch64-unknown-linux-gnu + - i686-unknown-linux-gnu + - loongarch64-unknown-linux-gnu + - powerpc64-unknown-linux-gnu + - powerpc64le-unknown-linux-gnu + - x86_64-pc-windows-msvc + - x86_64-apple-darwin + - aarch64-apple-darwin + - x86_64-unknown-freebsd + - riscv64gc-unknown-linux-gnu + toolchain: + - stable + - "1.66.0" # MSRV steps: - uses: actions/checkout@v4 - name: Setup Rust toolchain uses: actions-rs/toolchain@v1 with: - toolchain: stable - - name: "Installs SoftHSM and execute tests" - uses: ./.github/actions/ci_script + toolchain: ${{ matrix.toolchain }} + - name: Install SoftHSM + run: | + sudo apt-get update -y -qq && + sudo apt-get install -y -qq libsofthsm2 && + mkdir /tmp/tokens + echo "directories.tokendir = /tmp/tokens" > /tmp/softhsm2.conf + - name: Install Rust target + run: rustup target add ${{ matrix.target }} + - name: Test script + env: + TEST_PKCS11_MODULE: /usr/lib/softhsm/libsofthsm2.so + SOFTHSM2_CONF: /tmp/softhsm2.conf + TARGET: ${{ matrix.target }} + RUST_BACKTRACE: 1 + run: ./ci.sh build-windows: name: Build on Windows diff --git a/ci.sh b/ci.sh index 93bfde39..10324cdb 100755 --- a/ci.sh +++ b/ci.sh @@ -5,10 +5,10 @@ # Continuous Integration test script -set -euf -o pipefail +set -euxf -o pipefail pushd cryptoki-sys -RUST_BACKTRACE=1 cargo build --features generate-bindings +cargo build --features generate-bindings popd # check formatting before going through all the builds @@ -19,22 +19,10 @@ if cargo clippy --version; then cargo clippy --all-targets -- -D clippy::all -D clippy::cargo fi -RUST_BACKTRACE=1 cargo build - -RUST_BACKTRACE=1 cargo build --all-features - -RUST_BACKTRACE=1 cargo build --target arm-unknown-linux-gnueabi -RUST_BACKTRACE=1 cargo build --target armv7-unknown-linux-gnueabi -RUST_BACKTRACE=1 cargo build --target armv7-unknown-linux-gnueabihf -RUST_BACKTRACE=1 cargo build --target aarch64-unknown-linux-gnu -RUST_BACKTRACE=1 cargo build --target i686-unknown-linux-gnu -RUST_BACKTRACE=1 cargo build --target loongarch64-unknown-linux-gnu -RUST_BACKTRACE=1 cargo build --target powerpc64-unknown-linux-gnu -RUST_BACKTRACE=1 cargo build --target powerpc64le-unknown-linux-gnu -RUST_BACKTRACE=1 cargo build --target riscv64gc-unknown-linux-gnu -RUST_BACKTRACE=1 cargo build --target x86_64-pc-windows-msvc -RUST_BACKTRACE=1 cargo build --target x86_64-apple-darwin -RUST_BACKTRACE=1 cargo build --target aarch64-apple-darwin -RUST_BACKTRACE=1 cargo build --target x86_64-unknown-freebsd - -RUST_BACKTRACE=1 cargo test +cargo build + +cargo build --all-features + +cargo build --target "$TARGET" + +cargo test From dcc7c1675b2d5ac36183e0dc673e88ef976b83a8 Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Wed, 11 Jun 2025 09:21:36 +0200 Subject: [PATCH 2/9] Fail on lint warnings, fix outstanding warning Signed-off-by: Wiktor Kwapisiewicz --- .github/workflows/ci.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 620906b9..8a7a8de2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,6 +71,7 @@ jobs: SOFTHSM2_CONF: /tmp/softhsm2.conf TARGET: ${{ matrix.target }} RUST_BACKTRACE: 1 + RUSTFLAGS: "-D warnings" run: ./ci.sh build-windows: @@ -97,7 +98,6 @@ jobs: RUST_BACKTRACE=1 cargo build --all-features && RUST_BACKTRACE=1 cargo test - build-msrv: name: MSRV - Execute CI script runs-on: ubuntu-latest @@ -114,10 +114,10 @@ jobs: name: Check links runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Link Checker - uses: peter-evans/link-checker@v1 - with: - args: -v -r *.md - - name: Fail if there were link errors - run: exit ${{ steps.lc.outputs.exit_code }} + - uses: actions/checkout@v4 + - name: Link Checker + uses: peter-evans/link-checker@v1 + with: + args: -v -r *.md + - name: Fail if there were link errors + run: exit ${{ steps.lc.outputs.exit_code }} From f1ecf3810da136d0f0c7585cff71eea8e1104968 Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Wed, 11 Jun 2025 12:52:51 +0200 Subject: [PATCH 3/9] Add `cargo check` before running tests Signed-off-by: Wiktor Kwapisiewicz --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a7a8de2..9cfb114d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,6 +65,8 @@ jobs: echo "directories.tokendir = /tmp/tokens" > /tmp/softhsm2.conf - name: Install Rust target run: rustup target add ${{ matrix.target }} + - name: Check + run: cargo check --target ${{ matrix.target }} --workspace --all-targets - name: Test script env: TEST_PKCS11_MODULE: /usr/lib/softhsm/libsofthsm2.so From 0d15a702ec5b93ec0991067ac2d61f759431e472 Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Wed, 11 Jun 2025 13:06:25 +0200 Subject: [PATCH 4/9] Remove redundant job Signed-off-by: Wiktor Kwapisiewicz --- .github/workflows/ci.yml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cfb114d..b65913b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -100,18 +100,6 @@ jobs: RUST_BACKTRACE=1 cargo build --all-features && RUST_BACKTRACE=1 cargo test - build-msrv: - name: MSRV - Execute CI script - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Setup Rust toolchain on MSRV - uses: actions-rs/toolchain@v1 - with: - toolchain: 1.66.0 - - name: "Installs SoftHSM and execute tests" - uses: ./.github/actions/ci_script - links: name: Check links runs-on: ubuntu-latest From 74e7c3b46a0f21598542370ca508edf3b9d766ba Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Wed, 11 Jun 2025 13:08:38 +0200 Subject: [PATCH 5/9] Continue other matrix jobs on one job error Signed-off-by: Wiktor Kwapisiewicz --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b65913b2..d61747ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,7 @@ jobs: build: name: Execute CI script runs-on: ubuntu-latest + continue-on-error: true strategy: matrix: target: From dcda207810508ae04cc4bf81a6840a3dde113a54 Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Mon, 16 Jun 2025 09:04:49 +0200 Subject: [PATCH 6/9] Split tests from checks Signed-off-by: Wiktor Kwapisiewicz --- .github/workflows/ci.yml | 33 +++++++++++++++++++++++++++++++-- ci.sh | 16 +--------------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d61747ea..256260e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,13 +29,14 @@ jobs: - name: Check documentation run: RUSTDOCFLAGS="-Dwarnings" cargo doc --document-private-items --no-deps - build: - name: Execute CI script + check: + name: Check runs-on: ubuntu-latest continue-on-error: true strategy: matrix: target: + - x86_64-unknown-linux-gnu - armv7-unknown-linux-gnueabi - armv7-unknown-linux-gnueabihf - arm-unknown-linux-gnueabi @@ -52,6 +53,34 @@ jobs: toolchain: - stable - "1.66.0" # MSRV + steps: + - uses: actions/checkout@v4 + - name: Setup Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.toolchain }} + - name: Install Rust target + run: rustup target add ${{ matrix.target }} + - name: Check formatting + run: cargo fmt --all -- --check + - name: Check lints + run: cargo clippy --all-targets -- -D clippy::all -D clippy::cargo + - name: Check source + run: cargo check --target ${{ matrix.target }} --workspace --all-targets + - name: Check all features source + run: cargo check --target ${{ matrix.target }} --all-features --workspace --all-targets + + test: + name: Unit tests + runs-on: ubuntu-latest + continue-on-error: true + strategy: + matrix: + target: + - x86_64-unknown-linux-gnu + toolchain: + - stable + - "1.66.0" # MSRV steps: - uses: actions/checkout@v4 - name: Setup Rust toolchain diff --git a/ci.sh b/ci.sh index 10324cdb..029cd813 100755 --- a/ci.sh +++ b/ci.sh @@ -11,18 +11,4 @@ pushd cryptoki-sys cargo build --features generate-bindings popd -# check formatting before going through all the builds -if cargo fmt --version; then - cargo fmt --all -- --check -fi -if cargo clippy --version; then - cargo clippy --all-targets -- -D clippy::all -D clippy::cargo -fi - -cargo build - -cargo build --all-features - -cargo build --target "$TARGET" - -cargo test +cargo test --target "$TARGET" From d5c421c87f823f476a311d8533aa384b941adef6 Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Mon, 16 Jun 2025 09:07:56 +0200 Subject: [PATCH 7/9] Extract lints job Signed-off-by: Wiktor Kwapisiewicz --- .github/workflows/ci.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 256260e4..e205bf30 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,14 @@ jobs: - name: Check formatting run: cargo fmt --all -- --check + lints: + name: Check lints + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check formatting + run: cargo clippy --all-targets -- -D clippy::all -D clippy::cargo + docs: name: Check documentation runs-on: ubuntu-latest @@ -30,7 +38,7 @@ jobs: run: RUSTDOCFLAGS="-Dwarnings" cargo doc --document-private-items --no-deps check: - name: Check + name: Check for errors runs-on: ubuntu-latest continue-on-error: true strategy: @@ -61,10 +69,6 @@ jobs: toolchain: ${{ matrix.toolchain }} - name: Install Rust target run: rustup target add ${{ matrix.target }} - - name: Check formatting - run: cargo fmt --all -- --check - - name: Check lints - run: cargo clippy --all-targets -- -D clippy::all -D clippy::cargo - name: Check source run: cargo check --target ${{ matrix.target }} --workspace --all-targets - name: Check all features source From c4f2c3e09dcc5234e6b9b5dd7ee2343fc26c614f Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Mon, 16 Jun 2025 09:11:27 +0200 Subject: [PATCH 8/9] Clarify that unit tests are run against SoftHSM Signed-off-by: Wiktor Kwapisiewicz --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e205bf30..31839187 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,8 +74,8 @@ jobs: - name: Check all features source run: cargo check --target ${{ matrix.target }} --all-features --workspace --all-targets - test: - name: Unit tests + tests-softhsm: + name: Run tests against SoftHSM runs-on: ubuntu-latest continue-on-error: true strategy: From 1059ce907b009a52af4a7e6664ab5d3f897cba7a Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Thu, 26 Jun 2025 17:07:33 +0200 Subject: [PATCH 9/9] Add `check-matrix` job for verifying if all `check` jobs succeeded Signed-off-by: Wiktor Kwapisiewicz --- .github/workflows/ci.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31839187..5fcdc321 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,6 +74,18 @@ jobs: - name: Check all features source run: cargo check --target ${{ matrix.target }} --all-features --workspace --all-targets + check-matrix: + name: Check if all checks succeeded + if: always() + needs: + - check + runs-on: ubuntu-latest + steps: + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@release/v1 + with: + jobs: ${{ toJSON(needs) }} + tests-softhsm: name: Run tests against SoftHSM runs-on: ubuntu-latest