forked from rapidsai/cudf
-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (125 loc) · 5.18 KB
/
status.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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
outputs:
artifact_downloaded: ${{ steps.download_artifact.outputs.artifact_downloaded }}
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
id: download_artifact
uses: actions/github-script@v7
with:
retries: 3
script: |
const fs = require('fs');
const path = require('path');
const artifactName = 'gh-status';
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
// Find the specific artifact
const artifact = allArtifacts.data.artifacts.find(artifact => artifact.name === artifactName);
if (!artifact) {
core.info(`Artifact "${artifactName}" not found. Exiting safely.`);
core.setOutput('artifact_downloaded', 'false');
return;
}
core.setOutput('artifact_downloaded', 'true');
// Download the artifact
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
// Write the artifact to a file
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${artifactName}.zip`, Buffer.from(download.data));
- name: 'Unzip artifact'
if: ${{ steps.download_artifact.outputs.artifact_downloaded == 'true' }}
run: unzip 'gh-status.zip'
- name: Create status
if: ${{ steps.download_artifact.outputs.artifact_downloaded == 'true' }}
uses: actions/github-script@v7
env:
WORKFLOW_RUN_ID: ${{ github.event.workflow_run.id }}
COMMIT_SHA: ${{ github.event.workflow_run.head_sha }}
ATTEMPTS: ${{ github.event.workflow_run.run_attempt }}
with:
retries: 3
script: |
// Load the JSON content
const contentJSON = require('./gh-status.json');
const {
job_name: JOB_NAME,
context: CUSTOM_CONTEXT = 'Custom CI Status Check',
description: CUSTOM_DESCRIPTION = 'Custom CI Status description',
target_url: CUSTOM_TARGET_URL,
state: CUSTOM_STATE = 'success'
} = contentJSON;
// Fetch the first job ID from the workflow run
async function fetchAllJobs(owner, repo, run_id) {
let allJobs = [];
let page = 1;
const perPage = 100; // Adjust this value as needed, up to a maximum of 100
while (true) {
const response = await github.rest.actions.listJobsForWorkflowRun({
owner: owner,
repo: repo,
run_id: run_id,
per_page: perPage,
page: page
});
console.log(page, response);
allJobs = allJobs.concat(response.data.jobs);
console.log(allJobs);
if (response.data.jobs.length < perPage) {
break; // No more jobs to fetch, exit the loop
}
page++; // Increment the page number to fetch the next set of jobs
}
return allJobs;
}
const jobs = await fetchAllJobs(context.repo.owner, context.repo.repo, process.env.WORKFLOW_RUN_ID);
//console.log(JSON.stringify(jobs.data.jobs, undefined, 2));
const job = jobs.data.jobs.find(job => job.name === JOB_NAME);
const JOB_ID = job ? job.id : null;
// Set default target URL if not defined
const targetUrl = CUSTOM_TARGET_URL || `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.WORKFLOW_RUN_ID}/attempts/${process.env.ATTEMPTS}#summary-${JOB_ID}`;
console.log("job id: ", JOB_ID);
console.log("state: ", CUSTOM_STATE);
console.log("target url: ", targetUrl);
console.log("description: ", CUSTOM_DESCRIPTION);
console.log("context: ", CUSTOM_CONTEXT);
// Create status
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: process.env.COMMIT_SHA,
state: CUSTOM_STATE,
target_url: targetUrl,
description: CUSTOM_DESCRIPTION,
context: CUSTOM_CONTEXT,
});
#abc123