Skip to content

Commit c6a009e

Browse files
committed
Select publish target
1 parent cd00d5e commit c6a009e

File tree

5 files changed

+65
-19
lines changed

5 files changed

+65
-19
lines changed

projects/publish-rs/src/bindings.rs

+51-10
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,53 @@ impl ::core::fmt::Display for GithubError {
1717
}
1818
}
1919
impl std::error::Error for GithubError {}
20+
#[repr(u8)]
21+
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
22+
pub enum GithubTarget {
23+
All,
24+
Github,
25+
Npm,
26+
Cargo,
27+
}
28+
impl ::core::fmt::Debug for GithubTarget {
29+
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
30+
match self {
31+
GithubTarget::All => f.debug_tuple("GithubTarget::All").finish(),
32+
GithubTarget::Github => f.debug_tuple("GithubTarget::Github").finish(),
33+
GithubTarget::Npm => f.debug_tuple("GithubTarget::Npm").finish(),
34+
GithubTarget::Cargo => f.debug_tuple("GithubTarget::Cargo").finish(),
35+
}
36+
}
37+
}
38+
impl GithubTarget {
39+
#[doc(hidden)]
40+
pub unsafe fn _lift(val: u8) -> GithubTarget {
41+
if !cfg!(debug_assertions) {
42+
return ::core::mem::transmute(val);
43+
}
44+
match val {
45+
0 => GithubTarget::All,
46+
1 => GithubTarget::Github,
47+
2 => GithubTarget::Npm,
48+
3 => GithubTarget::Cargo,
49+
_ => panic!("invalid enum discriminant"),
50+
}
51+
}
52+
}
2053
#[doc(hidden)]
2154
#[allow(non_snake_case)]
2255
pub unsafe fn _export_run_with_config_cabi<T: Guest>(
2356
arg0: *mut u8,
2457
arg1: usize,
58+
arg2: i32,
2559
) -> *mut u8 {
2660
#[cfg(target_arch = "wasm32")] _rt::run_ctors_once();
2761
let len0 = arg1;
2862
let bytes0 = _rt::Vec::from_raw_parts(arg0.cast(), len0, len0);
29-
let result1 = T::run_with_config(_rt::string_lift(bytes0));
63+
let result1 = T::run_with_config(
64+
_rt::string_lift(bytes0),
65+
GithubTarget::_lift(arg2 as u8),
66+
);
3067
let ptr2 = _RET_AREA.0.as_mut_ptr().cast::<u8>();
3168
match result1 {
3269
Ok(_) => {
@@ -68,14 +105,17 @@ pub unsafe fn __post_return_run_with_config<T: Guest>(arg0: *mut u8) {
68105
}
69106
}
70107
pub trait Guest {
71-
fn run_with_config(config: _rt::String) -> Result<(), GithubError>;
108+
fn run_with_config(
109+
config: _rt::String,
110+
target: GithubTarget,
111+
) -> Result<(), GithubError>;
72112
}
73113
#[doc(hidden)]
74114
macro_rules! __export_world_action_cabi {
75115
($ty:ident with_types_in $($path_to_types:tt)*) => {
76116
const _ : () = { #[export_name = "run-with-config"] unsafe extern "C" fn
77-
export_run_with_config(arg0 : * mut u8, arg1 : usize,) -> * mut u8 {
78-
$($path_to_types)*:: _export_run_with_config_cabi::<$ty > (arg0, arg1) }
117+
export_run_with_config(arg0 : * mut u8, arg1 : usize, arg2 : i32,) -> * mut u8 {
118+
$($path_to_types)*:: _export_run_with_config_cabi::<$ty > (arg0, arg1, arg2) }
79119
#[export_name = "cabi_post_run-with-config"] unsafe extern "C" fn
80120
_post_return_run_with_config(arg0 : * mut u8,) { $($path_to_types)*::
81121
__post_return_run_with_config::<$ty > (arg0) } };
@@ -142,12 +182,13 @@ pub(crate) use __export_action_impl as export;
142182
#[cfg(target_arch = "wasm32")]
143183
#[link_section = "component-type:wit-bindgen:0.35.0:github:rust-release:action:encoded world"]
144184
#[doc(hidden)]
145-
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 230] = *b"\
146-
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07j\x01A\x02\x01A\x05\x01\
147-
q\x01\x06custom\x01s\0\x03\0\x0cgithub-error\x03\0\0\x01j\0\x01\x01\x01@\x01\x06\
148-
configs\0\x02\x04\0\x0frun-with-config\x01\x03\x04\0\x1agithub:rust-release/acti\
149-
on\x04\0\x0b\x0c\x01\0\x06action\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\
150-
\x0dwit-component\x070.220.0\x10wit-bindgen-rust\x060.35.0";
185+
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 282] = *b"\
186+
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\x9d\x01\x01A\x02\x01\
187+
A\x07\x01q\x01\x06custom\x01s\0\x03\0\x0cgithub-error\x03\0\0\x01m\x04\x03all\x06\
188+
github\x03npm\x05cargo\x03\0\x0dgithub-target\x03\0\x02\x01j\0\x01\x01\x01@\x02\x06\
189+
configs\x06target\x03\0\x04\x04\0\x0frun-with-config\x01\x05\x04\0\x1agithub:rus\
190+
t-release/action\x04\0\x0b\x0c\x01\0\x06action\x03\0\0\0G\x09producers\x01\x0cpr\
191+
ocessed-by\x02\x0dwit-component\x070.220.0\x10wit-bindgen-rust\x060.35.0";
151192
#[inline(never)]
152193
#[doc(hidden)]
153194
pub fn __link_custom_section_describing_imports() {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ use crate::{
33
bindings::{Guest, export},
44
};
55
use std::{
6-
env::{VarError, current_dir, current_exe},
76
path::{Path, PathBuf},
87
};
8+
use crate::bindings::GithubTarget;
99

1010
pub struct RunningContext {}
1111

1212
impl Guest for RunningContext {
13-
fn run_with_config(config: String) -> Result<(), GithubError> {
13+
fn run_with_config(config: String, target: GithubTarget) -> Result<(), GithubError> {
1414
tokio::runtime::Builder::new_current_thread().enable_all().build()?.block_on(async {
1515
let ctx = RunningContext {};
1616
ctx.run(config).await

projects/publish-rs/wit/world.wit

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ world action {
44
variant github-error {
55
custom(string)
66
}
7-
8-
export run-with-config: func(config: string) -> result<_, github-error>;
7+
enum github-target {
8+
all,
9+
github,
10+
npm,
11+
cargo,
12+
}
13+
export run-with-config: func(config: string, target: github-target) -> result<_, github-error>;
914
}

projects/publish-wasm32-wasi/action.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ env:
1111
GITHUB_TOKEN: Secret provided by github.com
1212
CRATES_TOKEN: Secret provided by crates.io
1313
inputs:
14-
mode:
15-
description: publish to which package manager
16-
required: false
17-
default: all
1814
config:
1915
description: path of the publish config file
2016
required: false
2117
default: .config/rust-publish.toml
18+
mode:
19+
description: publish to which package manager
20+
required: false
21+
default: all
2222
outputs:
2323
DEPLOYMENT_STATUS:
2424
description: 'The status of the deployment that indicates if the run failed or passed. Possible outputs include: success|failed|skipped'

projects/publish-wasm32-wasi/rust-publish.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
import {getInput} from '@actions/core';
44
import {runWithConfig} from "./src/index.js";
55

6-
runWithConfig(getInput('config'))
6+
runWithConfig(getInput('config'), getInput('mode'))

0 commit comments

Comments
 (0)