-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaction.yml
More file actions
111 lines (102 loc) · 3.65 KB
/
action.yml
File metadata and controls
111 lines (102 loc) · 3.65 KB
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
name: Job Summary URL
description: Calculates the job summary URL and other job related URLs which are not available by default
branding:
icon: award
color: green
inputs:
repository:
description: 'The owner and repository name. Defaults to `GITHUB_REPOSITORY`.'
required: true
default: ${{ github.repository }}
server_url:
description: 'The URL of the GitHub server. Defaults to `GITHUB_SERVER_URL`.'
required: true
default: ${{ github.server_url }}
workflow:
description: 'The name or the id of the workflow. Defaults to `GITHUB_WORKFLOW`.'
required: true
default: ${{ github.workflow }}
run_id:
description: 'The id of the workflow run. Or `latest`. Defaults to `GITHUB_RUN_ID`.'
required: true
default: ${{ github.run_id }}
run_attempt:
description: 'The number of the attempt of the workflow run. Or `latest`. Defaults to `GITHUB_RUN_ATTEMPT`.'
required: true
default: ${{ github.run_attempt }}
job:
description: 'A unique string for the workflow run job. Or `latest`. Defaults to `latest`.'
required: true
default: ${{ github.job }}
outputs:
run_url:
value: ${{ fromJSON(steps.script.outputs.result).run_url }}
description: The URL of the run
job_url:
value: ${{ fromJSON(steps.script.outputs.result).job_url }}
description: The URL of the job
job_summary_url:
value: ${{ fromJSON(steps.script.outputs.result).job_summary_url }}
description: The URL of the job summary
job_summary_raw_url:
value: ${{ fromJSON(steps.script.outputs.result).job_summary_raw_url }}
description: The URL of the raw job summary
runs:
using: "composite"
steps:
- id: script
uses: actions/github-script@v7
env:
REPOSITORY: ${{ inputs.repository }}
SERVER_URL: ${{ inputs.server_url }}
WORKFLOW: ${{ inputs.workflow }}
RUN_ID: ${{ inputs.run_id }}
RUN_ATTEMPT: ${{ inputs.run_attempt }}
JOB: ${{ inputs.job }}
with:
script: |
const LATEST = 'latest'
let {REPOSITORY, SERVER_URL, WORKFLOW, RUN_ID, RUN_ATTEMPT, JOB} = process.env
const owner = REPOSITORY.split('/')[0]
const repo = REPOSITORY.split('/')[1]
if (RUN_ID === LATEST) {
const runs = await github.rest.actions.listWorkflowRuns({
owner,
repo,
workflow_id: WORKFLOW,
per_page: 1
});
const run = runs.data.workflow_runs[0].id
RUN_ID = run.id
RUN_ATTEMPT = run.attempt
}
if (RUN_ATTEMPT === LATEST) {
const run = await github.rest.actions.getWorkflowRun({
owner,
repo,
run_id: RUN_ID,
})
RUN_ATTEMPT = run.data.run_attempt
}
const jobs = await github.rest.actions.listJobsForWorkflowRunAttempt({
owner,
repo,
run_id: RUN_ID,
attempt_number: RUN_ATTEMPT
})
let job
if (JOB === LATEST) {
job = jobs.data.jobs[jobs.data.jobs.length - 1]
} else {
job = jobs.data.jobs.find(j => j.name === JOB)
if (job === undefined) {
throw new Error(`Couldn't find '${JOB}' among ${jobs.data.jobs.map(j => `'${j.name}'`).join(', ')}`)
}
}
const run_url = `${SERVER_URL}/${REPOSITORY}/actions/runs/${RUN_ID}/attempts/${RUN_ATTEMPT}`
return {
run_url,
job_url: job.html_url,
job_summary_url: `${run_url}#summary-${job.id}`,
job_summary_raw_url: `${job.html_url}/summary_raw`
}