-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from brunojppb/store-gha-state
Store gha state
- Loading branch information
Showing
3 changed files
with
66 additions
and
18 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use std::{ | ||
env::{self}, | ||
fs::OpenOptions, | ||
}; | ||
|
||
use std::io::prelude::*; | ||
|
||
pub fn save_state(key: &str, value: &str) { | ||
let state = format!("{}={}", key, value); | ||
let gha_file_path = env::var("GITHUB_STATE") | ||
.unwrap_or_else(|_| panic!("Could not read GITHUB_STATE env variable")); | ||
println!("GHA state file: {}", gha_file_path); | ||
|
||
let mut gha_file = OpenOptions::new() | ||
.write(true) | ||
.append(true) | ||
.open(gha_file_path) | ||
.expect("GHA file should be available"); | ||
|
||
if let Err(e) = writeln!(gha_file, "{}", &state) { | ||
panic!("Could not write to GHA state file: {}", e); | ||
} | ||
} | ||
|
||
pub fn get_state(key: &str) -> Result<String, env::VarError> { | ||
println!("Reading env 'STATE_{}'", key); | ||
env::var(format!("STATE_{}", key)) | ||
} |
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