diff --git a/apis/actions.summerwind.net/v1alpha1/runner_types.go b/apis/actions.summerwind.net/v1alpha1/runner_types.go index 9dda5ad9..7986efad 100644 --- a/apis/actions.summerwind.net/v1alpha1/runner_types.go +++ b/apis/actions.summerwind.net/v1alpha1/runner_types.go @@ -248,10 +248,60 @@ type RunnerStatus struct { // +optional Message string `json:"message,omitempty"` // +optional + WorkflowStatus *WorkflowStatus `json:"workflow"` + // +optional // +nullable LastRegistrationCheckTime *metav1.Time `json:"lastRegistrationCheckTime,omitempty"` } +// WorkflowStatus contains various information that is propagated +// from GitHub Actions workflow run environment variables to +// ease monitoring workflow run/job/steps that are triggerred on the runner. +type WorkflowStatus struct { + // +optional + // Name is the name of the workflow + // that is triggerred within the runner. + // It corresponds to GITHUB_WORKFLOW defined in + // https://docs.github.com/en/actions/learn-github-actions/environment-variables + Name string `json:"name,omitempty"` + // +optional + // Repository is the owner and repository name of the workflow + // that is triggerred within the runner. + // It corresponds to GITHUB_REPOSITORY defined in + // https://docs.github.com/en/actions/learn-github-actions/environment-variables + Repository string `json:"repository,omitempty"` + // +optional + // ReositoryOwner is the repository owner's name for the workflow + // that is triggerred within the runner. + // It corresponds to GITHUB_REPOSITORY_OWNER defined in + // https://docs.github.com/en/actions/learn-github-actions/environment-variables + RepositoryOwner string `json:"repositoryOwner,omitempty"` + // +optional + // GITHUB_RUN_NUMBER is the unique number for the current workflow run + // that is triggerred within the runner. + // It corresponds to GITHUB_RUN_ID defined in + // https://docs.github.com/en/actions/learn-github-actions/environment-variables + RunNumber string `json:"runNumber,omitempty"` + // +optional + // RunID is the unique number for the current workflow run + // that is triggerred within the runner. + // It corresponds to GITHUB_RUN_ID defined in + // https://docs.github.com/en/actions/learn-github-actions/environment-variables + RunID string `json:"runID,omitempty"` + // +optional + // Job is the name of the current job + // that is triggerred within the runner. + // It corresponds to GITHUB_JOB defined in + // https://docs.github.com/en/actions/learn-github-actions/environment-variables + Job string `json:"job,omitempty"` + // +optional + // Action is the name of the current action or the step ID of the current step + // that is triggerred within the runner. + // It corresponds to GITHUB_ACTION defined in + // https://docs.github.com/en/actions/learn-github-actions/environment-variables + Action string `json:"action,omitempty"` +} + // RunnerStatusRegistration contains runner registration status type RunnerStatusRegistration struct { Enterprise string `json:"enterprise,omitempty"` @@ -316,6 +366,8 @@ func (w *WorkVolumeClaimTemplate) V1VolumeMount(mountPath string) corev1.VolumeM // +kubebuilder:printcolumn:JSONPath=".spec.labels",name=Labels,type=string // +kubebuilder:printcolumn:JSONPath=".status.phase",name=Status,type=string // +kubebuilder:printcolumn:JSONPath=".status.message",name=Message,type=string +// +kubebuilder:printcolumn:JSONPath=".status.workflow.repository",name=WF Repo,type=string +// +kubebuilder:printcolumn:JSONPath=".status.workflow.runID",name=WF Run,type=string // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" // Runner is the Schema for the runners API diff --git a/apis/actions.summerwind.net/v1alpha1/zz_generated.deepcopy.go b/apis/actions.summerwind.net/v1alpha1/zz_generated.deepcopy.go index 6021b7a5..bc450b7c 100644 --- a/apis/actions.summerwind.net/v1alpha1/zz_generated.deepcopy.go +++ b/apis/actions.summerwind.net/v1alpha1/zz_generated.deepcopy.go @@ -1049,6 +1049,11 @@ func (in *RunnerSpec) DeepCopy() *RunnerSpec { func (in *RunnerStatus) DeepCopyInto(out *RunnerStatus) { *out = *in in.Registration.DeepCopyInto(&out.Registration) + if in.WorkflowStatus != nil { + in, out := &in.WorkflowStatus, &out.WorkflowStatus + *out = new(WorkflowStatus) + **out = **in + } if in.LastRegistrationCheckTime != nil { in, out := &in.LastRegistrationCheckTime, &out.LastRegistrationCheckTime *out = (*in).DeepCopy() @@ -1212,3 +1217,18 @@ func (in *WorkflowJobSpec) DeepCopy() *WorkflowJobSpec { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *WorkflowStatus) DeepCopyInto(out *WorkflowStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkflowStatus. +func (in *WorkflowStatus) DeepCopy() *WorkflowStatus { + if in == nil { + return nil + } + out := new(WorkflowStatus) + in.DeepCopyInto(out) + return out +} diff --git a/charts/actions-runner-controller/crds/actions.summerwind.dev_runners.yaml b/charts/actions-runner-controller/crds/actions.summerwind.dev_runners.yaml index fdbb0059..4129a909 100644 --- a/charts/actions-runner-controller/crds/actions.summerwind.dev_runners.yaml +++ b/charts/actions-runner-controller/crds/actions.summerwind.dev_runners.yaml @@ -36,6 +36,12 @@ spec: - jsonPath: .status.message name: Message type: string + - jsonPath: .status.workflow.repository + name: WF Repo + type: string + - jsonPath: .status.workflow.runID + name: WF Run + type: string - jsonPath: .metadata.creationTimestamp name: Age type: date @@ -5225,6 +5231,31 @@ spec: - expiresAt - token type: object + workflow: + description: WorkflowStatus contains various information that is propagated from GitHub Actions workflow run environment variables to ease monitoring workflow run/job/steps that are triggerred on the runner. + properties: + action: + description: Action is the name of the current action or the step ID of the current step that is triggerred within the runner. It corresponds to GITHUB_ACTION defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables + type: string + job: + description: Job is the name of the current job that is triggerred within the runner. It corresponds to GITHUB_JOB defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables + type: string + name: + description: Name is the name of the workflow that is triggerred within the runner. It corresponds to GITHUB_WORKFLOW defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables + type: string + repository: + description: Repository is the owner and repository name of the workflow that is triggerred within the runner. It corresponds to GITHUB_REPOSITORY defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables + type: string + repositoryOwner: + description: ReositoryOwner is the repository owner's name for the workflow that is triggerred within the runner. It corresponds to GITHUB_REPOSITORY_OWNER defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables + type: string + runID: + description: RunID is the unique number for the current workflow run that is triggerred within the runner. It corresponds to GITHUB_RUN_ID defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables + type: string + runNumber: + description: GITHUB_RUN_NUMBER is the unique number for the current workflow run that is triggerred within the runner. It corresponds to GITHUB_RUN_ID defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables + type: string + type: object type: object type: object served: true diff --git a/config/crd/bases/actions.summerwind.dev_runners.yaml b/config/crd/bases/actions.summerwind.dev_runners.yaml index fdbb0059..4129a909 100644 --- a/config/crd/bases/actions.summerwind.dev_runners.yaml +++ b/config/crd/bases/actions.summerwind.dev_runners.yaml @@ -36,6 +36,12 @@ spec: - jsonPath: .status.message name: Message type: string + - jsonPath: .status.workflow.repository + name: WF Repo + type: string + - jsonPath: .status.workflow.runID + name: WF Run + type: string - jsonPath: .metadata.creationTimestamp name: Age type: date @@ -5225,6 +5231,31 @@ spec: - expiresAt - token type: object + workflow: + description: WorkflowStatus contains various information that is propagated from GitHub Actions workflow run environment variables to ease monitoring workflow run/job/steps that are triggerred on the runner. + properties: + action: + description: Action is the name of the current action or the step ID of the current step that is triggerred within the runner. It corresponds to GITHUB_ACTION defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables + type: string + job: + description: Job is the name of the current job that is triggerred within the runner. It corresponds to GITHUB_JOB defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables + type: string + name: + description: Name is the name of the workflow that is triggerred within the runner. It corresponds to GITHUB_WORKFLOW defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables + type: string + repository: + description: Repository is the owner and repository name of the workflow that is triggerred within the runner. It corresponds to GITHUB_REPOSITORY defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables + type: string + repositoryOwner: + description: ReositoryOwner is the repository owner's name for the workflow that is triggerred within the runner. It corresponds to GITHUB_REPOSITORY_OWNER defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables + type: string + runID: + description: RunID is the unique number for the current workflow run that is triggerred within the runner. It corresponds to GITHUB_RUN_ID defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables + type: string + runNumber: + description: GITHUB_RUN_NUMBER is the unique number for the current workflow run that is triggerred within the runner. It corresponds to GITHUB_RUN_ID defined in https://docs.github.com/en/actions/learn-github-actions/environment-variables + type: string + type: object type: object type: object served: true diff --git a/runner/update-status b/runner/update-status index d12e92a1..81b1932a 100755 --- a/runner/update-status +++ b/runner/update-status @@ -15,9 +15,30 @@ if [[ ${RUNNER_STATUS_UPDATE_HOOK:-false} == true ]]; then namespace=$(cat ${serviceaccount}/namespace) token=$(cat ${serviceaccount}/token) phase=$1 - shift + message=${2:-} - jq -n --arg phase "$phase" --arg message "${*:-}" '.status.phase = $phase | .status.message = $message' | curl \ + data=$(jq -n --arg phase "$phase" \ + --arg message "$message" \ + --arg workflow_repository "${GITHUB_REPOSITORY:-}" \ + --arg workflow_repository_owner "${GITHUB_REPOSITORY_OWNER:-}" \ + --arg workflow_name "${GITHUB_WORKFLOW:-}" \ + --arg workflow_run_id "${GITHUB_RUN_ID:-}" \ + --arg workflow_run_number "${GITHUB_RUN_NUMBER:-}" \ + --arg workflow_job "${GITHUB_JOB:-}" \ + --arg workflow_action "${GITHUB_ACTION:-}" \ + ' + .status.phase = $phase + | .status.message = $message + | .status.workflow.name = $workflow_name + | .status.workflow.runID = $workflow_run_id + | .status.workflow.runNumber = $workflow_run_number + | .status.workflow.repository = $workflow_repository + | .status.workflow.repositoryOwner = $workflow_repository_owner + | .status.workflow.job = $workflow_job + | .status.workflow.action = $workflow_action + ') + + echo "$data" | curl \ --cacert ${serviceaccount}/ca.crt \ --data @- \ --noproxy '*' \