This crate provides basic utilities that help you develop custom GitHub Actions in Rust.
use gha::github_workspace;
use std::fs::File;
let workspace = github_workspace();
let my_file = File::open(workspace.append("my_file.yaml"))?Easily generate workflow commands; e.g.,
use gha::{debug, error, mask, set_failed};
debug!("current dir: {:#?}", std::env::current_dir());
error!(title = "Validator", line = 42, "Invalid value");
mask!("{}", secret_token);
// set_failed! prints `::error::...` and exits with status 1
if !ok { set_failed!("aborting: {reason}"); }Append to the workflow's environment files ($GITHUB_ENV, $GITHUB_OUTPUT,
$GITHUB_PATH, $GITHUB_STEP_SUMMARY):
use gha::{
GITHUB_ENV, GITHUB_PATH, GITHUB_STEP_SUMMARY,
append_name_value, append_path, append_summary,
};
use std::env;
use std::fs::OpenOptions;
let mut env_file = OpenOptions::new().append(true).open(env::var(GITHUB_ENV)?)?;
append_name_value(&mut env_file, "VERSION", "1.2.3")?;
let mut path_file = OpenOptions::new().append(true).open(env::var(GITHUB_PATH)?)?;
append_path(&mut path_file, "/opt/my-tool/bin")?;
let mut summary = OpenOptions::new().append(true).open(env::var(GITHUB_STEP_SUMMARY)?)?;
append_summary(&mut summary, "## Build succeeded\n\nAll checks passed.")?;To get started with GitHub Actions in Rust, use the following project template:
cargo generate https://github.com/ecliptical/rust-gha-template