Skip to main content

RunRef

Struct RunRef 

Source
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: String

The provider that ran it, as the adapter that recorded it names it.

§id: String

The provider’s identifier of the run.

§attempt: u32

Which attempt of the run, counted from 1.

§workflow: String

The workflow the run belongs to.

§job: String

The job within the run that recorded the execution.

§url: String

Where 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

Source

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 Clone for RunRef

Source§

fn clone(&self) -> RunRef

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RunRef

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for RunRef

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for RunRef

Source§

impl JsonSchema for RunRef

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for RunRef

Source§

fn eq(&self, other: &RunRef) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for RunRef

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for RunRef

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more