Skip to content

Process Workflow Artifacts and Update Status After Echo Job #93

Process Workflow Artifacts and Update Status After Echo Job

Process Workflow Artifacts and Update Status After Echo Job #93

Workflow file for this run

name: Process Workflow Artifacts and Update Status After Echo Job
on:
workflow_run:
workflows: ["Echo on PR"]
types:
- completed
jobs:
process_artifacts:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
permissions:
actions: read
checks: read
contents: read
deployments: read
id-token: write
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: write
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: gh-status
path: downloaded_artifacts/
# workflow: copy.yml
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Create status
uses: actions/github-script@v7
with:
script: |
const { context } = github;
const CONTENT_JSON = require('./downloaded_artifacts/gh-status.json');
const JOB_NAME = CONTENT_JSON.job_name;
const CUSTOM_CONTEXT = CONTENT_JSON.context || "Custom CI Status Check";
const CUSTOM_DESCRIPTION = CONTENT_JSON.description || "Custom CI Status description";
const CUSTOM_TARGET_URL = CONTENT_JSON.target_url || `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/attempts/${context.runAttempt}#summary-${context.job}`;
const CUSTOM_STATE = CONTENT_JSON.state || "success";
// Fetch the first job ID from the workflow run
const jobs = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId,
});
const job = jobs.data.jobs.find(job => job.name === JOB_NAME);
const JOB_ID = job ? job.id : null;
console.log(`Job ID: ${JOB_ID}`);
console.log(JOB_NAME);
console.log(CUSTOM_CONTEXT);
console.log(CUSTOM_DESCRIPTION);
console.log(CUSTOM_TARGET_URL);
console.log(CUSTOM_STATE);
console.log(context.runAttempt);
console.log(JOB_ID);
// Create status
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state: CUSTOM_STATE,
target_url: CUSTOM_TARGET_URL,
description: CUSTOM_DESCRIPTION,
context: CUSTOM_CONTEXT,
});
retries: 4
#abc123