From b6bd4ffb1fa179703712305a58cf23eb3b523994 Mon Sep 17 00:00:00 2001 From: hinto-janai Date: Sat, 28 Jun 2025 14:02:40 +0000 Subject: [PATCH] ci: extend build environments (#480) * apply * update * fix * revert * latest * hash * use `GITHUB_SHA` * update * cargo update -p randomx-rs * alpine * bash * curl * comment alpine --- .github/workflows/ci.yml | 130 +++++++++++++++++++++++++---------- binaries/cuprated/Cargo.toml | 2 +- constants/build.rs | 37 ++++++---- 3 files changed, 118 insertions(+), 51 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3132134..79930a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,17 @@ env: RUSTDOCFLAGS: '-D warnings' # Enable debug information generation for build dependencies. CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG: true + # Build commands. + CMD_DOC: cargo doc --all-features --no-deps + CMD_CLIPPY: cargo clippy --all-features --all-targets -- -D warnings + CMD_TEST: | + # HACK: how to test both DB backends that are feature-gated? + cargo test --all-features + cargo test --package cuprate-blockchain --no-default-features --features redb + CMD_BUILD: cargo build --all-features --all-targets + CMD_HACK: | + cargo install cargo-hack --locked + cargo hack check --feature-powerset --no-dev-deps jobs: # Run format separately. @@ -78,7 +89,7 @@ jobs: - name: Build WASM 32-bit run: cargo build --target wasm32-unknown-unknown -p ${{ matrix.crate }} - # All other CI. + # CI, runs on GitHub provided OSs. ci: runs-on: ${{ matrix.os }} @@ -93,46 +104,95 @@ jobs: ] steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: recursive + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive - - name: Install Rust - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - components: clippy + - name: Install Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: clippy - - name: Cache - uses: actions/cache@v4 - with: - path: target - key: ${{ matrix.os }} + - name: Cache + uses: actions/cache@v4 + with: + path: target + key: ${{ matrix.os }} - - name: Download monerod - uses: ./.github/actions/monerod-download + - name: Download monerod + uses: ./.github/actions/monerod-download - - name: Install dependencies (Windows) - if: matrix.os == 'windows-2022' - uses: lukka/get-cmake@v3.31.6 # Needed for `randomx-rs` + - name: Install dependencies (Windows) + if: matrix.os == 'windows-2022' + uses: lukka/get-cmake@v3.31.6 # Needed for `randomx-rs` - - name: Documentation - run: cargo doc --all-features --no-deps + - name: Documentation + run: ${{ env.CMD_DOC }} - - name: Clippy (fail on warnings) - run: cargo clippy --all-features --all-targets -- -D warnings + - name: Clippy (fail on warnings) + run: ${{ env.CMD_CLIPPY }} - # HACK: how to test both DB backends that are feature-gated? - - name: Test - run: | - cargo test --all-features - cargo test --package cuprate-blockchain --no-default-features --features redb + - name: Test + run: ${{ env.CMD_TEST }} - - name: Build - run: cargo build --all-features --all-targets + - name: Build + run: ${{ env.CMD_BUILD }} - - name: Hack Check - run: | - cargo install cargo-hack --locked - cargo hack check --feature-powerset --no-dev-deps + - name: Hack Check + run: ${{ env.CMD_HACK }} + + # CI, runs in a Docker image. + ci-docker: + runs-on: ubuntu-latest + container: + image: ${{ matrix.os.image }} + + strategy: + matrix: + os: + # TODO: support musl + # - { image: alpine:latest, commands: "apk update && apk add alpine-sdk cmake curl bash" } + - { image: archlinux:latest, commands: "pacman -Syyu --noconfirm base-devel git cmake" } + - { image: debian:stable, commands: "apt update && apt -y install build-essential curl cmake git" } + - { image: fedora:latest, commands: "dnf install --assumeyes @development-tools gcc gcc-c++ cmake git" } + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + clean: false + + - name: Cache + uses: actions/cache@v4 + with: + path: target + key: ${{ matrix.os.image }} + + - name: Dependencies + run: ${{ matrix.os.commands }} + + - name: Install Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: clippy + + - name: Download monerod + uses: ./.github/actions/monerod-download + + - name: Documentation + run: ${{ env.CMD_DOC }} + + - name: Clippy (fail on warnings) + run: ${{ env.CMD_CLIPPY }} + + - name: Test + run: ${{ env.CMD_TEST }} + + - name: Build + run: ${{ env.CMD_BUILD }} + + - name: Hack Check + run: ${{ env.CMD_HACK }} \ No newline at end of file diff --git a/binaries/cuprated/Cargo.toml b/binaries/cuprated/Cargo.toml index cd5f814..4744d0c 100644 --- a/binaries/cuprated/Cargo.toml +++ b/binaries/cuprated/Cargo.toml @@ -94,4 +94,4 @@ cuprate-hex = { workspace = true } serde_json = { workspace = true, features = ["std"] } [lints] -workspace = true +workspace = true \ No newline at end of file diff --git a/constants/build.rs b/constants/build.rs index 518f2a3..baf7639 100644 --- a/constants/build.rs +++ b/constants/build.rs @@ -8,23 +8,30 @@ fn set_commit_env() { println!("cargo:rerun-if-changed={PATH}"); - // FIXME: This could also be `std::fs::read({PATH}/{branch})` - // so the machine building doesn't need `git`, although: - // 1. Having `git` as a build dependency is probably ok - // 2. It causes issues on PRs that aren't the `main` branch - let output = std::process::Command::new("git") - .arg("rev-parse") - .arg("HEAD") - .output() - .unwrap(); - - let commit = std::str::from_utf8(&output.stdout) + let commit = if let Ok(t) = std::env::var("GITHUB_SHA") { + t + } else { + // FIXME: This could also be `std::fs::read({PATH}/{branch})` + // so the machine building doesn't need `git`, although: + // 1. Having `git` as a build dependency is probably ok + // 2. It causes issues on PRs that aren't the `main` branch + String::from_utf8( + std::process::Command::new("git") + .args(["show", "-s", "--format=%H"]) + .output() + .unwrap() + .stdout, + ) .unwrap() - .trim() - .to_lowercase(); + } + .trim() + .to_lowercase(); - // Commit hash should always be 40 bytes long. - assert_eq!(commit.len(), 40); + assert_eq!( + commit.len(), + 40, + "Commit hash should always be 40 bytes long." + ); println!("cargo:rustc-env=COMMIT={commit}"); }