Skip to content

Commit 5047cc6

Browse files
committed
build: add artifact
1 parent 991cf12 commit 5047cc6

File tree

3 files changed

+61
-11
lines changed

3 files changed

+61
-11
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ jobs:
3535
- name: Format
3636
run: cargo run --package tool-dev -- fmt
3737
- name: Build
38+
id: build
3839
run: cargo run --package tool-dev -- build --target ${{ matrix.target }}
3940
- name: Test
4041
run: cargo run --package tool-dev -- test --target ${{ matrix.target }}
42+
- name: Upload Artifact
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: ${{ matrix.target }}
46+
path: ${{ steps.build.outputs.ARTIFACT_PATH }}

crates/tools/dev/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition.workspace = true
55

66
[dependencies]
77
clap = { version = "4.4.18", features = ["derive", "cargo"] }
8+
zip = "0.6.6"
89

910
[dev-dependencies]
1011
cargo-husky = { version = "1", default-features = false, features = [

crates/tools/dev/src/main.rs

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
use clap::{Parser, Subcommand};
22
use std::{
3-
env, panic,
4-
process::{Command, Stdio},
3+
env,
4+
io::Write,
5+
panic,
6+
path::Path,
7+
process::{self, Stdio},
58
};
69

710
#[derive(Parser)]
811
#[command(arg_required_else_help = true)]
912
struct Cli {
1013
#[command(subcommand)]
11-
command: Option<Commands>,
14+
command: Option<Command>,
1215
}
1316

1417
#[derive(Subcommand)]
15-
enum Commands {
18+
enum Command {
1619
Check,
1720
Clippy,
1821
Fmt,
@@ -28,7 +31,7 @@ enum Commands {
2831
}
2932

3033
fn run(program: &str, args: &[&str]) {
31-
let mut command = Command::new(program);
34+
let mut command = process::Command::new(program);
3235
command
3336
.stdout(Stdio::inherit())
3437
.stderr(Stdio::inherit())
@@ -67,6 +70,46 @@ fn build(target: &str) {
6770
"cargo",
6871
&["build", "-p", "kill_tree_cli", "-r", "--target", target],
6972
);
73+
74+
if env::var("GITHUB_ACTIONS").is_ok() {
75+
match env::var("GITHUB_OUTPUT") {
76+
Ok(output) => {
77+
let windows_path = Path::new("target")
78+
.join(target)
79+
.join("release")
80+
.join("kill_tree_cli.exe");
81+
let file_path = if windows_path.exists() {
82+
windows_path
83+
} else {
84+
Path::new("target")
85+
.join(target)
86+
.join("release")
87+
.join("kill_tree_cli")
88+
};
89+
let zip_path = format!("{}.zip", target);
90+
let zip_file = std::fs::File::create(zip_path.clone()).unwrap();
91+
let mut zip = zip::ZipWriter::new(zip_file);
92+
let options = zip::write::FileOptions::default()
93+
.compression_method(zip::CompressionMethod::Stored)
94+
.unix_permissions(0o755);
95+
let file_name = file_path.file_name().unwrap().to_str().unwrap();
96+
zip.start_file(file_name, options).unwrap();
97+
let mut file = std::fs::File::open(file_path).unwrap();
98+
std::io::copy(&mut file, &mut zip).unwrap();
99+
zip.finish().unwrap();
100+
101+
let mut output_path = std::fs::OpenOptions::new()
102+
.write(true)
103+
.append(true)
104+
.open(output)
105+
.unwrap();
106+
writeln!(output_path, "ARTIFACT_PATH={}", zip_path).unwrap();
107+
}
108+
Err(_) => {
109+
panic!("No GITHUB_OUTPUT");
110+
}
111+
}
112+
}
70113
}
71114

72115
fn test(target: Option<String>) {
@@ -88,12 +131,12 @@ fn pre_push() {
88131
fn main() {
89132
let cli = Cli::parse();
90133
match cli.command {
91-
Some(Commands::Check) => check(),
92-
Some(Commands::Clippy) => clippy(),
93-
Some(Commands::Fmt) => fmt(),
94-
Some(Commands::Build { target }) => build(&target),
95-
Some(Commands::Test { target }) => test(target),
96-
Some(Commands::PrePush) => pre_push(),
134+
Some(Command::Check) => check(),
135+
Some(Command::Clippy) => clippy(),
136+
Some(Command::Fmt) => fmt(),
137+
Some(Command::Build { target }) => build(&target),
138+
Some(Command::Test { target }) => test(target),
139+
Some(Command::PrePush) => pre_push(),
97140
None => {
98141
panic!("No command");
99142
}

0 commit comments

Comments
 (0)