Skip to content

Commit bdae32a

Browse files
committed
Support github action inputs
1 parent babfd8a commit bdae32a

File tree

10 files changed

+60
-61
lines changed

10 files changed

+60
-61
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ jobs:
1414
os: [ubuntu-latest, macos-latest, windows-latest]
1515
steps:
1616
- name: Deploy Rust to GitHub Pages
17-
uses: valkyrie-language/[email protected].0
17+
uses: valkyrie-language/[email protected].1
1818
with:
1919
config: .config/Publish.toml

.run/build-wasi.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
cargo build --release --target wasm32-wasip2
1+
cargo component 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

action.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Rust Auto Publish
2+
description: Auto publish rust binary to github release
3+
author: Aster <[email protected]>
4+
branding:
5+
icon: package
6+
color: orange
7+
runs:
8+
using: node20
9+
main: rust-publish.js
10+
env:
11+
GITHUB_TOKEN: Secret provided by github.com
12+
CRATES_TOKEN: Secret provided by crates.io
13+
inputs:
14+
config:
15+
description: Path of the config file
16+
required: true
17+
default: .config/rust-publish.toml
18+
outputs:
19+
DEPLOYMENT_STATUS:
20+
description: 'The status of the deployment that indicates if the run failed or passed. Possible outputs include: success|failed|skipped'

projects/publish-rs/Cargo.toml

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ readme = "readme.md"
99
license = "MPL-2.0"
1010
edition = "2021"
1111

12+
[lib]
13+
name = "github"
14+
crate-type = ["cdylib"]
15+
1216
[dependencies]
13-
anyhow = "1.0.95"
14-
clap = { version = "4.5.27", features = ["derive"] }
15-
#url = "2.5.4"
16-
wat = { version = "1.224.0", features = ["component-model", "dwarf"] }
17-
wasmprinter = { version = "0.224.0", features = ["component-model"] }
18-
js-component-bindgen = "1.9.1"
1917
reqwest = { version = "0.12.12", features = ["socks"] }
2018
#inquire = "0.7.5"
2119
dialoguer = "0.11.0"
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use crate::{
2+
GithubError, bindings,
3+
bindings::{Guest, export},
4+
};
5+
6+
pub struct RunningContext {}
7+
8+
impl Guest for RunningContext {
9+
fn run_with_config(config: String) -> Result<(), GithubError> {
10+
tokio::runtime::Builder::new_current_thread().enable_all().build()?.block_on(async {
11+
let ctx = RunningContext {};
12+
ctx.run(config).await
13+
})
14+
}
15+
}
16+
17+
impl RunningContext {
18+
async fn run(&self, config: String) -> Result<(), GithubError> {
19+
let args = std::env::args();
20+
println!("Args: {:?}", args);
21+
println!("Config: {}", config);
22+
Ok(())
23+
}
24+
}
25+
26+
export!(RunningContext with_types_in bindings);

projects/publish-rs/src/errors/mod.rs

-12
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@ impl From<std::io::Error> for GithubError {
66
}
77
}
88

9-
impl From<anyhow::Error> for GithubError {
10-
fn from(error: anyhow::Error) -> Self {
11-
GithubError::Custom(error.to_string())
12-
}
13-
}
14-
15-
impl From<wat::Error> for GithubError {
16-
fn from(error: wat::Error) -> Self {
17-
GithubError::Custom(error.to_string())
18-
}
19-
}
20-
219
impl From<dialoguer::Error> for GithubError {
2210
fn from(error: dialoguer::Error) -> Self {
2311
GithubError::Custom(error.to_string())

projects/publish-rs/src/lib.rs

+3-26
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,5 @@
1-
pub mod commands;
1+
pub mod bindings;
2+
mod commands;
23
mod errors;
3-
pub use crate::bindings::GithubError;
4-
use crate::commands::{LegionArguments, LegionCommands};
5-
use clap::Parser;
6-
mod bindings;
74

8-
#[derive(Debug, Parser)]
9-
#[command(version, about, long_about = None)]
10-
pub struct GithubCLI {
11-
#[command(subcommand)]
12-
commands: Option<LegionCommands>,
13-
#[command(flatten)]
14-
arguments: LegionArguments,
15-
}
16-
17-
impl GithubCLI {
18-
pub async fn run(self) -> Result<(), GithubError> {
19-
let args: Vec<String> = std::env::args().collect();
20-
println!("Args:\n{:#?}", args);
21-
// let Self { commands, arguments } = self;
22-
// match commands {
23-
// Some(s) => s.run(&arguments).await?,
24-
// None => {}
25-
// }
26-
Ok(())
27-
}
28-
}
5+
pub use crate::{bindings::GithubError, commands::RunningContext};

projects/publish-rs/src/main.rs

-9
This file was deleted.

projects/publish-wasm32-wasi/action.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ runs:
88
using: node20
99
main: rust-publish.js
1010
env:
11-
GITHUB_TOKEN: As provided by Github Actions
11+
GITHUB_TOKEN: Secret provided by github.com
12+
CRATES_TOKEN: Secret provided by crates.io
1213
inputs:
1314
config:
1415
description: Path of the config file
1516
required: true
16-
default: '{json}'
17+
default: .config/rust-publish.toml
1718
outputs:
1819
DEPLOYMENT_STATUS:
1920
description: 'The status of the deployment that indicates if the run failed or passed. Possible outputs include: success|failed|skipped'
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env node
22

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

6-
const name = getInput('name');
7-
8-
run.run()
6+
runWithConfig(getInput('config'))

0 commit comments

Comments
 (0)