Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 57 additions & 35 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# 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:
#
# * 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.
Expand All @@ -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 || '' }}
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -135,7 +147,7 @@ jobs:
run: |
# Parse out what we just built and upload it to scratch storage
echo "paths<<EOF" >> "$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"
Expand All @@ -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
Expand All @@ -177,7 +193,7 @@ jobs:

# Parse out what we just built and upload it to scratch storage
echo "paths<<EOF" >> "$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"
Expand Down Expand Up @@ -205,16 +221,19 @@ 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
with:
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: |
Expand All @@ -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
Expand All @@ -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:
Expand Down
22 changes: 19 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,28 @@ 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"]
targets = ["x86_64-unknown-linux-musl"]
# Target platforms to build apps for (Rust target-triple syntax)
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
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

[workspace.metadata.dist.github-custom-runners]
aarch64-unknown-linux-musl = "buildjet-2vcpu-ubuntu-2204-arm"
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
40 changes: 27 additions & 13 deletions src/run/check_system.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down Expand Up @@ -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);
}
31 changes: 23 additions & 8 deletions src/run/runner/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ fn run_with_sudo(command_args: &[&str]) -> Result<()> {
}

fn get_codspeed_valgrind_filename(system_info: &SystemInfo) -> Result<String> {
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
))
}

Expand Down Expand Up @@ -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"
);
}

Expand All @@ -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"
);
}
}