Skip to content

Commit 61b6cb8

Browse files
committed
Read config file
1 parent 286e960 commit 61b6cb8

File tree

6 files changed

+25
-58
lines changed

6 files changed

+25
-58
lines changed

.run/build-wasi.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
cargo component build --release --target wasm32-wasip2
1+
cargo build --release --target wasm32-wasip2
22
cp target/wasm32-wasip2/release/github.wasm projects/publish-wasm32-wasi/github-wasm32-wasi.wasm
33
jco transpile projects/publish-wasm32-wasi/github-wasm32-wasi.wasm -o projects/publish-wasm32-wasi/src --name index --no-namespaced-exports --multi-memory --valid-lifting-optimization --optimize
+2-35
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,9 @@
11
use crate::{GithubCLI, GithubError};
2-
use std::{
3-
collections::{BTreeMap},
4-
path::Path,
5-
};
2+
use std::{collections::BTreeMap, path::Path};
63

74
impl GithubCLI {
85
pub async fn run(&self) -> Result<(), GithubError> {
9-
match std::env::var("INPUT_CONFIG") {
10-
Ok(o) => {
11-
println!("Config Path: {}", o);
12-
}
13-
Err(e) => {
14-
println!("MissingConfig {}", e);
15-
}
16-
}
17-
match std::env::var("GITHUB_WORKSPACE") {
18-
Ok(s) => {
19-
println!("GITHUB_WORKSPACE");
20-
read_dir(&s)
21-
}
22-
Err(e) => {
23-
println!(" {}", e)
24-
}
25-
}
6+
println!("Config: {:?}", std::fs::read_to_string(&self.config));
267
let mut envs = BTreeMap::new();
278
for (key, value) in std::env::vars() {
289
envs.insert(key, value);
@@ -31,17 +12,3 @@ impl GithubCLI {
3112
Ok(())
3213
}
3314
}
34-
fn read_dir(dir_path: &str) {
35-
let path = Path::new(dir_path);
36-
if let Ok(dir_entries) = std::fs::read_dir(path) {
37-
for entry in dir_entries {
38-
if let Ok(entry) = entry {
39-
let file_name = entry.file_name();
40-
println!("{}", file_name.to_string_lossy());
41-
}
42-
}
43-
}
44-
else {
45-
println!("Error reading directory: {}", dir_path);
46-
}
47-
}

projects/publish-rs/src/lib.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,35 @@ mod commands;
22
mod errors;
33

44
pub use crate::errors::GithubError;
5-
use std::str::FromStr;
5+
use std::{env::VarError, path::PathBuf, str::FromStr};
66

77
#[derive(Debug)]
8-
pub struct GithubCLI {}
8+
pub struct GithubCLI {
9+
root: PathBuf,
10+
config: PathBuf,
11+
mode: GithubTarget,
12+
}
913

1014
impl GithubCLI {
1115
pub fn new() -> Result<Self, GithubError> {
12-
Ok(GithubCLI {})
16+
let root = match std::env::var("GITHUB_WORKSPACE") {
17+
Ok(o) => PathBuf::from(o),
18+
Err(e) => panic!("{e}"),
19+
};
20+
let config = match std::env::var("INPUT_CONFIG") {
21+
Ok(o) => root.join(o),
22+
Err(_) => panic!("Missing `config`"),
23+
};
24+
let mode = match std::env::var("INPUT_MODE") {
25+
Ok(o) => GithubTarget::from_str(&o)?,
26+
Err(_) => panic!("Missing `mode`"),
27+
};
28+
Ok(GithubCLI { root, config, mode })
1329
}
1430
}
1531

1632
#[repr(u8)]
17-
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
33+
#[derive(Clone, Copy, Eq, Debug, Ord, PartialEq, PartialOrd)]
1834
pub enum GithubTarget {
1935
All,
2036
Github,

projects/publish-rs/wit/world.wit

-14
This file was deleted.

projects/publish-wasm32-wasi/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"private": "true",
33
"type": "module",
44
"dependencies": {
5-
"@actions/core": "^1.11.1",
65
"@bytecodealliance/preview2-shim": "^0.17.1"
76
}
87
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env node
22

3-
import {getInput} from '@actions/core';
4-
import {runWithConfig} from "./src/index.js";
3+
import {run} from "./src/index.js";
54

6-
runWithConfig(getInput('config'), getInput('mode'))
5+
run.run()

0 commit comments

Comments
 (0)