-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added method to produce an [output](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter) - Copied from [here](https://github.com/actions/toolkit/blob/d1df13e178816d69d96bdc5c753b36a66ad03728/packages/core/src/core.ts#L192) ## Summary - **Documentation** - Updated `README.md` to mark the `set_output` method as complete and included an example of its usage. - **Bug Fixes** - Enhanced error handling with a new `Output` variant in the `ActionsError` enum. - **Chores** - Added `uuid` dependency with `v4` feature for better UUID handling.
- Loading branch information
Showing
7 changed files
with
159 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ doctest = false | |
|
||
[dependencies] | ||
json = "0.12.4" | ||
uuid = { version = "1.8.0", features = ["v4"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
pub mod context; | ||
pub mod core; | ||
pub mod error; | ||
mod util; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use std::fs; | ||
use std::io::Write; | ||
use std::path::Path; | ||
use std::{env, io}; | ||
use uuid::Uuid; | ||
|
||
#[cfg(windows)] | ||
pub const EOL: &str = "\r\n"; | ||
#[cfg(not(windows))] | ||
pub const EOL: &str = "\n"; | ||
|
||
pub fn issue_file_command(command: &str, message: String) -> Result<(), String> { | ||
let env_var = format!("GITHUB_{}", command); | ||
let file_path = match env::var(env_var) { | ||
Ok(path) => path, | ||
Err(_) => { | ||
return Err(format!( | ||
"Unable to find environment variable for file command {}", | ||
command | ||
)) | ||
} | ||
}; | ||
|
||
if !Path::new(&file_path).exists() { | ||
return Err(format!("Missing file at path: {}", file_path)); | ||
} | ||
|
||
let mut file = match fs::OpenOptions::new().append(true).open(&file_path) { | ||
Ok(f) => f, | ||
Err(_) => return Err(format!("Unable to open file at path: {}", file_path)), | ||
}; | ||
|
||
if writeln!(file, "{}{}", message, EOL).is_err() { | ||
return Err(format!("Unable to write to file at path: {}", file_path)); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn prepare_key_value_message(key: &str, value: &str) -> Result<String, String> { | ||
let delimiter = format!("ghadelimiter_{}", Uuid::new_v4()); | ||
|
||
// These should realistically never happen, but just in case someone finds a | ||
// way to exploit uuid generation let's not allow keys or values that contain | ||
// the delimiter. | ||
if key.contains(&delimiter) { | ||
return Err(format!( | ||
"Unexpected input: name should not contain the delimiter \"{}\"", | ||
&delimiter | ||
)); | ||
} | ||
|
||
if value.contains(&delimiter) { | ||
return Err(format!( | ||
"Unexpected input: value should not contain the delimiter \"{}\"", | ||
&delimiter | ||
)); | ||
} | ||
|
||
Ok(format!( | ||
"{}<<{}{}{}{}{}", | ||
key, delimiter, EOL, value, EOL, delimiter | ||
)) | ||
} | ||
|
||
pub fn issue_old_command(command: &str, name: &str, value: &str) { | ||
let msg: String = format!("::{} name={}::{}", command, name, value); | ||
io::stdout() | ||
.write_all((msg.to_string() + EOL).as_bytes()) | ||
.expect("Failed to write command") | ||
} |