pub struct RunRef {
pub provider: String,
pub id: String,
pub attempt: u32,
pub workflow: String,
pub job: String,
pub url: String,
pub head_sha: Option<String>,
pub event: Option<String>,
}Expand description
The continuous-integration run an execution was recorded in: enough to navigate back to the run that produced it.
Origin says what kind of run it was and deliberately names no provider. This names the
one run, in the words the provider addressed it with when it happened — its identifier,
its attempt, the workflow and job, and the address a reader follows — because a link built
later from a template would point wherever the template’s idea of the provider had drifted
to. Only an adapter constructs it; nothing in the model reads the provider’s name.
use majordomus_cli::evidence::RunRef;
let actions = |k: &str| {
let v = match k {
"GITHUB_ACTIONS" => "true",
"GITHUB_SERVER_URL" => "https://github.com",
"GITHUB_REPOSITORY" => "owner/repo",
"GITHUB_RUN_ID" => "42",
"GITHUB_RUN_ATTEMPT" => "2",
"GITHUB_WORKFLOW" => "validate",
"GITHUB_JOB" => "evidence",
_ => return None,
};
Some(v.to_string())
};
let run = RunRef::from_env(actions).unwrap();
assert_eq!(run.id, "42");
assert_eq!(run.attempt, 2);
assert_eq!(run.url, "https://github.com/owner/repo/actions/runs/42/attempts/2");
// a run that names neither its pull request's head nor its event still names itself
assert_eq!((run.head_sha, run.event), (None, None));
let head = "0123456789abcdef0123456789abcdef01234567";
let pull = |k: &str| match k {
"MJ_RUN_HEAD_SHA" => Some(head.to_string()),
"GITHUB_EVENT_NAME" => Some("pull_request".to_string()),
_ => actions(k),
};
let run = RunRef::from_env(pull).unwrap();
assert_eq!(run.head_sha.as_deref(), Some(head));
assert_eq!(run.event.as_deref(), Some("pull_request"));
// outside a run there is nothing to name, and a half-described run is not a run
assert!(RunRef::from_env(|_| None).is_none());
assert!(RunRef::from_env(|k| (k == "GITHUB_ACTIONS").then(|| "true".to_string())).is_none());Fields§
§provider: StringThe provider that ran it, as the adapter that recorded it names it.
id: StringThe provider’s identifier of the run.
attempt: u32Which attempt of the run, counted from 1.
workflow: StringThe workflow the run belongs to.
job: StringThe job within the run that recorded the execution.
url: StringWhere a reader finds the run, as the provider addressed it at the time.
head_sha: Option<String>The pull request’s head commit when the run was a pull-request run (its commit is
GitHub’s merge commit, the tree that ran). Carried beside the commit, never
substituted for it.
event: Option<String>The event that started the run: push, pull_request, schedule,
workflow_dispatch.
Implementations§
Source§impl RunRef
impl RunRef
Sourcepub fn from_env(var: impl Fn(&str) -> Option<String>) -> Option<RunRef>
pub fn from_env(var: impl Fn(&str) -> Option<String>) -> Option<RunRef>
The run described by a GitHub Actions environment, read through var, or None when
the environment is not one or leaves out any part a reader would need to find it.
The variable reader is a parameter so the adapter can be exercised without mutating the process environment, which other threads of a test binary share.
use majordomus_cli::evidence::RunRef;
assert!(RunRef::from_env(|k| (k == "GITHUB_RUN_ID").then(|| "1".to_string())).is_none());Trait Implementations§
Source§impl<'de> Deserialize<'de> for RunRef
impl<'de> Deserialize<'de> for RunRef
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for RunRef
Source§impl JsonSchema for RunRef
impl JsonSchema for RunRef
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreimpl StructuralPartialEq for RunRef
Auto Trait Implementations§
impl Freeze for RunRef
impl RefUnwindSafe for RunRef
impl Send for RunRef
impl Sync for RunRef
impl Unpin for RunRef
impl UnsafeUnpin for RunRef
impl UnwindSafe for RunRef
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.