Skip to content

Commit c396b8e

Browse files
committed
fix: add env to override go pkg version
1 parent ed306a6 commit c396b8e

File tree

2 files changed

+6
-30
lines changed

2 files changed

+6
-30
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ jobs:
2828
lfs: true
2929
submodules: true
3030
- uses: moonrepo/setup-rust@v1
31-
env:
32-
CODSPEED_LOCAL_GO_PKG: true
3331
- run: |
3432
cd go-runner
3533
cargo test --all
34+
env:
35+
CODSPEED_GO_PKG_VERSION: ${{ github.head_ref || github.ref_name }}
3636
3737
3838
compat-integration-test-walltime:
@@ -49,7 +49,7 @@ jobs:
4949
- name: Run the benchmarks
5050
uses: CodSpeedHQ/action@main
5151
env:
52-
CODSPEED_LOCAL_GO_PKG: true
52+
CODSPEED_GO_PKG_VERSION: ${{ github.head_ref || github.ref_name }}
5353
with:
5454
mode: walltime
5555
working-directory: example

go-runner/src/builder/patcher.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,6 @@ use std::fs;
55
use std::path::{Path, PathBuf};
66
use std::process::Command;
77

8-
fn codspeed_go_version() -> anyhow::Result<String> {
9-
if std::env::var("CODSPEED_LOCAL_GO_PKG").is_err() && cfg!(not(test)) {
10-
return Ok(format!("v{}", env!("CARGO_PKG_VERSION")));
11-
}
12-
13-
// When running in GitHub Actions, we always want to use the latest
14-
// codspeed-go package. For this, we have to use the current branch.
15-
if std::env::var("GITHUB_ACTIONS").is_ok() {
16-
return Ok(std::env::var("GITHUB_HEAD_REF")?);
17-
}
18-
19-
// Locally, run `git rev-parse --abbrev-ref HEAD` to get the current branch name
20-
let output = Command::new("git")
21-
.args(["rev-parse", "--abbrev-ref", "HEAD"])
22-
.output()
23-
.context("Failed to execute 'git rev-parse' command")?;
24-
if !output.status.success() {
25-
let stderr = String::from_utf8_lossy(&output.stderr);
26-
bail!("Failed to get current git branch: {}", stderr);
27-
}
28-
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
29-
}
30-
318
pub fn replace_pkg<P: AsRef<Path>>(folder: P) -> anyhow::Result<()> {
329
let codspeed_root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
3310
let replace_arg = format!(
@@ -78,10 +55,9 @@ pub fn patch_imports<P: AsRef<Path>>(
7855
debug!("Patched {patched_files} files");
7956

8057
// 2. Update the go module to use the codspeed package
81-
let pkg = format!(
82-
"github.com/CodSpeedHQ/codspeed-go@{}",
83-
codspeed_go_version()?
84-
);
58+
let version = std::env::var("CODSPEED_GO_PKG_VERSION")
59+
.unwrap_or_else(|_| format!("v{}", env!("CARGO_PKG_VERSION")));
60+
let pkg = format!("github.com/CodSpeedHQ/codspeed-go@{}", version);
8561
debug!("Installing {pkg}");
8662

8763
let mut cmd: Command = Command::new("go");

0 commit comments

Comments
 (0)