-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaction.yaml
81 lines (76 loc) · 2.82 KB
/
action.yaml
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
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Get job
description: Gets the action job ID and URL, it fails if not found.
inputs:
job-name:
description: The name of the job.
default: ${{ github.job }}
repository-owner:
description: The owner of the repository.
default: ${{ github.repository_owner }}
repository-name:
description: The name of the repository.
default: ${{ github.event.repository.name }}
run-id:
description: The ID of the workflow run.
default: ${{ github.run_id }}
outputs:
id:
description: The action job ID.
value: ${{ fromJson(steps.job.outputs.result).id }}
url:
description: The action job URL.
value: ${{ fromJson(steps.job.outputs.result).url }}
runs:
using: composite
steps:
- uses: actions/github-script@v7
id: job
with:
script: |
async function* listJobs({owner, repo, run_id}) {
console.log(`Listing jobs for ${run_id}`);
for (let page = 1; page < 100; page++) {
// https://docs.github.com/en/rest/actions/workflow-jobs?apiVersion=2022-11-28#list-jobs-for-a-workflow-run
// https://octokit.github.io/rest.js/v21/#actions-list-jobs-for-workflow-run
const response = await github.rest.actions.listJobsForWorkflowRun({
owner: owner,
repo: repo,
run_id: run_id,
page: page;
});
if (response.data.jobs.length === 0) {
break;
}
for (const job of response.data.jobs) {
console.log(`- ${job.name}`);
yield job;
}
}
}
const jobs = listJobs({
owner: "${{ inputs.repository-owner }}",
repo: "${{ inputs.repository-name }}",
run_id: "${{ inputs.run-id }}",
});
for await (const job of jobs) {
if (job.name === "${{ inputs.job-name }}" || job.name.endsWith(" / ${{ inputs.job-name }}")) {
console.log(`Job found: ${job.name}`);
console.log(`id: ${job.id}`);
console.log(`url: ${job.html_url}`);
return {id: job.id, url: job.html_url};
}
}
core.setFailed(`Job not found: '${{ inputs.job-name }}'`);