From f9d33ac560574ee7e26fa784b018b3e590641856 Mon Sep 17 00:00:00 2001 From: Adrien Cacciaguerra Date: Thu, 12 Sep 2024 12:09:59 +0200 Subject: [PATCH 1/3] chore: update cargo-dist to latest version --- .github/workflows/release.yml | 92 ++++++++++++++++++++++------------- Cargo.toml | 17 ++++++- 2 files changed, 72 insertions(+), 37 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ba77307e..e379610d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,6 @@ -# Copyright 2022-2023, axodotdev +# This file was autogenerated by cargo-dist: https://opensource.axo.dev/cargo-dist/ +# +# Copyright 2022-2024, axodotdev # SPDX-License-Identifier: MIT or Apache-2.0 # # CI that: @@ -6,15 +8,14 @@ # * checks for a Git Tag that looks like a release # * builds artifacts with cargo-dist (archives, installers, hashes) # * uploads those artifacts to temporary workflow zip -# * on success, uploads the artifacts to a Github Release +# * on success, uploads the artifacts to a GitHub Release # -# Note that the Github Release will be created with a generated +# Note that the GitHub Release will be created with a generated # title/body based on your changelogs. name: Release - permissions: - contents: write + "contents": "write" # This task will run whenever you push a git tag that looks like a version # like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc. @@ -31,22 +32,22 @@ permissions: # packages versioned/released in lockstep). # # If you push multiple tags at once, separate instances of this workflow will -# spin up, creating an independent announcement for each one. However Github +# spin up, creating an independent announcement for each one. However, GitHub # will hard limit this to 3 tags per commit, as it will assume more tags is a # mistake. # # If there's a prerelease-style suffix to the version, then the release(s) # will be marked as a prerelease. on: + pull_request: push: tags: - '**[0-9]+.[0-9]+.[0-9]+*' - pull_request: jobs: # Run 'cargo dist plan' (or host) to determine what tasks we need to do plan: - runs-on: ubuntu-latest + runs-on: "ubuntu-20.04" outputs: val: ${{ steps.plan.outputs.manifest }} tag: ${{ !github.event.pull_request && github.ref_name || '' }} @@ -62,7 +63,12 @@ jobs: # we specify bash to get pipefail; it guards against the `curl` command # failing. otherwise `sh` won't catch that `curl` returned non-0 shell: bash - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.10.0/cargo-dist-installer.sh | sh" + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.22.1/cargo-dist-installer.sh | sh" + - name: Cache cargo-dist + uses: actions/upload-artifact@v4 + with: + name: cargo-dist-cache + path: ~/.cargo/bin/cargo-dist # sure would be cool if github gave us proper conditionals... # so here's a doubly-nested ternary-via-truthiness to try to provide the best possible # functionality based on whether this is a pull_request, and whether it's from a fork. @@ -105,10 +111,16 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json steps: + - name: enable windows longpaths + run: | + git config --global core.longpaths true - uses: actions/checkout@v4 with: submodules: recursive - uses: swatinem/rust-cache@v2 + with: + key: ${{ join(matrix.targets, '-') }} + cache-provider: ${{ matrix.cache_provider }} - name: Install cargo-dist run: ${{ matrix.install_dist }} # Get the dist-manifest @@ -135,7 +147,7 @@ jobs: run: | # Parse out what we just built and upload it to scratch storage echo "paths<> "$GITHUB_OUTPUT" - jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT" + jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT" echo "EOF" >> "$GITHUB_OUTPUT" cp dist-manifest.json "$BUILD_MANIFEST_NAME" @@ -160,8 +172,12 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cargo-dist - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.10.0/cargo-dist-installer.sh | sh" + - name: Install cached cargo-dist + uses: actions/download-artifact@v4 + with: + name: cargo-dist-cache + path: ~/.cargo/bin/ + - run: chmod +x ~/.cargo/bin/cargo-dist # Get all the local artifacts for the global tasks to use (for e.g. checksums) - name: Fetch local artifacts uses: actions/download-artifact@v4 @@ -177,7 +193,7 @@ jobs: # Parse out what we just built and upload it to scratch storage echo "paths<> "$GITHUB_OUTPUT" - jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT" + jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT" echo "EOF" >> "$GITHUB_OUTPUT" cp dist-manifest.json "$BUILD_MANIFEST_NAME" @@ -205,8 +221,12 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cargo-dist - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.10.0/cargo-dist-installer.sh | sh" + - name: Install cached cargo-dist + uses: actions/download-artifact@v4 + with: + name: cargo-dist-cache + path: ~/.cargo/bin/ + - run: chmod +x ~/.cargo/bin/cargo-dist # Fetch artifacts from scratch-storage - name: Fetch artifacts uses: actions/download-artifact@v4 @@ -214,7 +234,6 @@ jobs: pattern: artifacts-* path: target/distrib/ merge-multiple: true - # This is a harmless no-op for Github Releases, hosting for that happens in "announce" - id: host shell: bash run: | @@ -228,8 +247,29 @@ jobs: # Overwrite the previous copy name: artifacts-dist-manifest path: dist-manifest.json + # Create a GitHub Release while uploading all files to it + - name: "Download GitHub Artifacts" + uses: actions/download-artifact@v4 + with: + pattern: artifacts-* + path: artifacts + merge-multiple: true + - name: Cleanup + run: | + # Remove the granular manifests + rm -f artifacts/*-dist-manifest.json + - name: Create GitHub Release + env: + PRERELEASE_FLAG: "${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}" + ANNOUNCEMENT_TITLE: "${{ fromJson(steps.host.outputs.manifest).announcement_title }}" + ANNOUNCEMENT_BODY: "${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}" + RELEASE_COMMIT: "${{ github.sha }}" + run: | + # Write and read notes from a file to avoid quoting breaking things + echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt + + gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/* - # Create a Github Release while uploading all files to it announce: needs: - plan @@ -245,24 +285,6 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: "Download Github Artifacts" - uses: actions/download-artifact@v4 - with: - pattern: artifacts-* - path: artifacts - merge-multiple: true - - name: Cleanup - run: | - # Remove the granular manifests - rm -f artifacts/*-dist-manifest.json - - name: Create Github Release - uses: ncipollo/release-action@v1 - with: - tag: ${{ needs.plan.outputs.tag }} - name: ${{ fromJson(needs.host.outputs.val).announcement_title }} - body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }} - prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }} - artifacts: "artifacts/*" custom-bump-action: needs: diff --git a/Cargo.toml b/Cargo.toml index 5ee472b4..a3768504 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,12 +60,25 @@ inherits = "release" lto = "thin" strip = true +# Config for 'cargo dist' [workspace.metadata.dist] +# Whether to consider the binaries in a package for distribution (defaults true) dist = true -cargo-dist-version = "0.10.0" -ci = ["github"] +# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax) +cargo-dist-version = "0.22.1" +# CI backends to support +ci = "github" +# The installers to generate for each app installers = ["shell"] +# Target platforms to build apps for (Rust target-triple syntax) targets = ["x86_64-unknown-linux-musl"] +# The archive format to use for non-windows builds (defaults .tar.xz) unix-archive = ".tar.gz" +# Which actions to run on pull requests pr-run-mode = "upload" +# Post-announce jobs to run in CI post-announce-jobs = ["./bump-action"] +# Path that installers should place binaries in +install-path = "CARGO_HOME" +# Whether to install an updater program +install-updater = false From e3e0e1deb7bb979fd2bed45aa7a32467751563d9 Mon Sep 17 00:00:00 2001 From: Adrien Cacciaguerra Date: Thu, 12 Sep 2024 12:16:07 +0200 Subject: [PATCH 2/3] chore: add arm64 Linux musl target --- Cargo.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a3768504..a6d310d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,7 +71,7 @@ ci = "github" # The installers to generate for each app installers = ["shell"] # Target platforms to build apps for (Rust target-triple syntax) -targets = ["x86_64-unknown-linux-musl"] +targets = ["aarch64-unknown-linux-musl", "x86_64-unknown-linux-musl"] # The archive format to use for non-windows builds (defaults .tar.xz) unix-archive = ".tar.gz" # Which actions to run on pull requests @@ -82,3 +82,6 @@ post-announce-jobs = ["./bump-action"] install-path = "CARGO_HOME" # Whether to install an updater program install-updater = false + +[workspace.metadata.dist.github-custom-runners] +aarch64-unknown-linux-musl = "buildjet-2vcpu-ubuntu-2204-arm" From 2808f7512ae391dca2dc7f00ca66cc156e7348dc Mon Sep 17 00:00:00 2001 From: Adrien Cacciaguerra Date: Thu, 12 Sep 2024 12:29:49 +0200 Subject: [PATCH 3/3] feat(run): support arm64 architecture --- src/main.rs | 2 +- src/run/check_system.rs | 40 +++++++++++++++++++++++++++------------- src/run/runner/setup.rs | 31 +++++++++++++++++++++++-------- 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/src/main.rs b/src/main.rs index b9bfac5b..a4717631 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ use log::log_enabled; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const MONGODB_TRACER_VERSION: &str = "cs-mongo-tracer-v0.2.0"; -pub const VALGRIND_CODSPEED_VERSION: &str = "3.21.0-0codspeed1"; +pub const VALGRIND_CODSPEED_VERSION: &str = "3.21.0-0codspeed2"; #[tokio::main(flavor = "current_thread")] async fn main() { diff --git a/src/run/check_system.rs b/src/run/check_system.rs index 416c00d4..360fb2a1 100644 --- a/src/run/check_system.rs +++ b/src/run/check_system.rs @@ -1,6 +1,8 @@ use std::process::Command; +use lazy_static::lazy_static; use serde::{Deserialize, Serialize}; +use std::collections::HashSet; use sysinfo::System; use crate::prelude::*; @@ -58,25 +60,37 @@ impl SystemInfo { } } +lazy_static! { + static ref SUPPORTED_SYSTEMS: HashSet<(&'static str, &'static str, &'static str)> = { + HashSet::from([ + ("Ubuntu", "20.04", "x86_64"), + ("Ubuntu", "22.04", "x86_64"), + ("Ubuntu", "22.04", "aarch64"), + ("Debian", "11", "x86_64"), + ("Debian", "12", "x86_64"), + ]) + }; +} + /// Checks if the provided system info is supported /// /// Supported systems: -/// - Ubuntu 20.04 on x86_64 -/// - Ubuntu 22.04 on x86_64 -/// - Debian 11 on x86_64 -/// - Debian 12 on x86_64 +/// - Ubuntu 20.04 x86_64 +/// - Ubuntu 22.04 x86_64 and aarch64 +/// - Debian 11 x86_64 +/// - Debian 12 x86_64 pub fn check_system(system_info: &SystemInfo) -> Result<()> { debug!("System info: {:#?}", system_info); - match (system_info.os.as_str(), system_info.os_version.as_str()) { - ("Ubuntu", "20.04") | ("Ubuntu", "22.04") | ("Debian", "11") | ("Debian", "12") => (), - ("Ubuntu", _) => bail!("Only Ubuntu 20.04 and 22.04 are supported at the moment"), - ("Debian", _) => bail!("Only Debian 11 and 12 are supported at the moment"), - _ => bail!("Only Ubuntu and Debian are supported at the moment"), - } - if system_info.arch != "x86_64" { - bail!("Only x86_64 is supported at the moment"); + let system_tuple = ( + system_info.os.as_str(), + system_info.os_version.as_str(), + system_info.arch.as_str(), + ); + + if SUPPORTED_SYSTEMS.contains(&system_tuple) { + return Ok(()); } - Ok(()) + bail!("Unsupported system: {:?}", system_info); } diff --git a/src/run/runner/setup.rs b/src/run/runner/setup.rs index 5563d758..37835a3d 100644 --- a/src/run/runner/setup.rs +++ b/src/run/runner/setup.rs @@ -39,22 +39,22 @@ fn run_with_sudo(command_args: &[&str]) -> Result<()> { } fn get_codspeed_valgrind_filename(system_info: &SystemInfo) -> Result { - let version = match ( + let (version, architecture) = match ( system_info.os.as_str(), system_info.os_version.as_str(), system_info.arch.as_str(), ) { ("Ubuntu", "20.04", "x86_64") | ("Debian", "11", "x86_64") | ("Debian", "12", "x86_64") => { - "20.04" + ("20.04", "amd64") } - ("Ubuntu", "22.04", "x86_64") => "22.04", - + ("Ubuntu", "22.04", "x86_64") => ("22.04", "amd64"), + ("Ubuntu", "22.04", "aarch64") => ("22.04", "arm64"), _ => bail!("Unsupported system"), }; Ok(format!( - "valgrind_{}_ubuntu-{}_amd64.deb", - VALGRIND_CODSPEED_VERSION, version + "valgrind_{}_ubuntu-{}_{}.deb", + VALGRIND_CODSPEED_VERSION, version, architecture )) } @@ -154,7 +154,7 @@ mod tests { }; assert_snapshot!( get_codspeed_valgrind_filename(&system_info).unwrap(), - @"valgrind_3.21.0-0codspeed1_ubuntu-22.04_amd64.deb" + @"valgrind_3.21.0-0codspeed2_ubuntu-22.04_amd64.deb" ); } @@ -169,7 +169,22 @@ mod tests { }; assert_snapshot!( get_codspeed_valgrind_filename(&system_info).unwrap(), - @"valgrind_3.21.0-0codspeed1_ubuntu-20.04_amd64.deb" + @"valgrind_3.21.0-0codspeed2_ubuntu-20.04_amd64.deb" + ); + } + + #[test] + fn test_system_info_to_codspeed_valgrind_version_ubuntu_arm() { + let system_info = SystemInfo { + os: "Ubuntu".to_string(), + os_version: "22.04".to_string(), + arch: "aarch64".to_string(), + host: "host".to_string(), + user: "user".to_string(), + }; + assert_snapshot!( + get_codspeed_valgrind_filename(&system_info).unwrap(), + @"valgrind_3.21.0-0codspeed2_ubuntu-22.04_arm64.deb" ); } }