Skip to content

Commit 38927c8

Browse files
authored
Initial implementation (#1)
1 parent e397b25 commit 38927c8

File tree

11 files changed

+453
-1
lines changed

11 files changed

+453
-1
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# https://editorconfig.org/
2+
3+
# https://manpages.debian.org/testing/shfmt/shfmt.1.en.html#EXAMPLES
4+
[*.sh]
5+
indent_style = space
6+
indent_size = 4
7+
shell_variant = bash # --language-variant
8+
binary_next_line = false
9+
switch_case_indent = true # --case-indent
10+
space_redirects = false
11+
keep_padding = false
12+
function_next_line = false # --func-next-line

.github/workflows/gha.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: GitHub Actions
3+
on:
4+
pull_request:
5+
paths:
6+
- ".github/workflows/*"
7+
8+
jobs:
9+
lint:
10+
name: Lint
11+
# These permissions are needed to:
12+
# - Checkout the Git repo (`contents: read`)
13+
permissions:
14+
contents: read
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
# https://github.com/rhysd/actionlint/blob/v1.7.6/docs/usage.md#use-actionlint-on-github-actions
19+
# https://github.com/rhysd/actionlint/blob/v1.7.6/docs/usage.md#reviewdog
20+
# https://github.com/reviewdog/reviewdog#filter-mode
21+
# No support for non-workflows yet: https://github.com/rhysd/actionlint/issues/46
22+
- uses: reviewdog/action-actionlint@a1b7ce56be870acfe94b83ce5f6da076aecc6d8c # v1.62.0
23+
with:
24+
fail_level: error
25+
filter_mode: nofilter # Post results on all results and not just changed files
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
---
2+
name: Integration Tests
3+
on:
4+
pull_request:
5+
paths:
6+
- "action.yaml"
7+
- ".github/workflows/integration-tests.yaml"
8+
9+
jobs:
10+
target-unnamed:
11+
permissions: {}
12+
runs-on: ubuntu-latest
13+
steps:
14+
- run: sleep 10
15+
16+
target-named:
17+
name: Target Named
18+
permissions: {}
19+
runs-on: ubuntu-latest
20+
steps:
21+
- run: sleep 10
22+
23+
test-same-workflow:
24+
name: Test Same Workflow
25+
# These permissions are needed to:
26+
# - Checkout the repo
27+
permissions:
28+
contents: read
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
- uses: ./
33+
id: wait-for-job-unnamed
34+
with:
35+
run-id: ${{ github.run_id }}
36+
job-name: target-unnamed
37+
poll-interval: 5
38+
- name: Validate wait for unnamed job
39+
run: |
40+
set -x
41+
[[ "$conclusion" == "success" ]] || exit 1
42+
43+
# https://docs.github.com/en/rest/actions/workflow-jobs?apiVersion=2022-11-28#get-a-job-for-a-workflow-run
44+
job_status="$(gh api -X GET "/repos/{owner}/{repo}/actions/jobs/${job_id:?}" --jq '.status')"
45+
[[ "$job_status" == "completed" ]] || exit 1
46+
env:
47+
GH_TOKEN: ${{ github.token }}
48+
job_id: ${{ steps.wait-for-job-unnamed.outputs.job-id }}
49+
conclusion: ${{ steps.wait-for-job-unnamed.outputs.conclusion }}
50+
- uses: ./
51+
id: wait-for-job-named
52+
with:
53+
run-id: ${{ github.run_id }}
54+
job-name: Target Named
55+
poll-interval: 5
56+
- name: Validate wait for named job
57+
run: |
58+
set -x
59+
[[ "$conclusion" == "success" ]] || exit 1
60+
61+
# https://docs.github.com/en/rest/actions/workflow-jobs?apiVersion=2022-11-28#get-a-job-for-a-workflow-run
62+
job_status="$(gh api -X GET "/repos/{owner}/{repo}/actions/jobs/${job_id:?}" --jq '.status')"
63+
[[ "$job_status" == "completed" ]] || exit 1
64+
env:
65+
GH_TOKEN: ${{ github.token }}
66+
job_id: ${{ steps.wait-for-job-named.outputs.job-id }}
67+
conclusion: ${{ steps.wait-for-job-named.outputs.conclusion }}
68+
69+
test-build-workflow:
70+
name: Test Build Workflow
71+
# These permissions are needed to:
72+
# - Checkout the repo
73+
permissions:
74+
contents: read
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v4
78+
- uses: beacon-biosignals/get-workflow-run@v1
79+
id: workflow-run
80+
with:
81+
workflow-file: target-workflow.yaml
82+
commit-sha: ${{ github.event.pull_request.head.sha }}
83+
- uses: ./
84+
id: wait-for-job
85+
with:
86+
run-id: ${{ steps.workflow-run.outputs.run-id }}
87+
job-name: Build
88+
poll-interval: 5
89+
- name: Validate wait job
90+
run: |
91+
[[ "$conclusion" == "success" ]] || exit 1
92+
93+
# https://docs.github.com/en/rest/actions/workflow-jobs?apiVersion=2022-11-28#list-jobs-for-a-workflow-run
94+
run_jobs="$(gh api -X GET "/repos/{owner}/{repo}/actions/runs/${run_id:?}/jobs" --jq '.jobs | {jobs: map({name, status, conclusion})}')"
95+
96+
# https://docs.github.com/en/rest/actions/workflow-jobs?apiVersion=2022-11-28#get-a-job-for-a-workflow-run
97+
job_status="$(gh api -X GET "/repos/{owner}/{repo}/actions/jobs/${job_id:?}" --jq '.status')"
98+
if [[ "$job_status" != "completed" ]]; then
99+
jq <<<"$run_jobs"
100+
exit 1
101+
fi
102+
103+
# The workflow run status may be "queued" when a subset of the jobs have
104+
# completed and the remaining jobs are "queued".
105+
# https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#get-a-workflow-run
106+
run_status="$(gh api "/repos/{owner}/{repo}/actions/runs/${run_id}" --jq '.status')"
107+
if [[ "$run_status" != "in_progress" && "$run_status" != "queued" ]]; then
108+
jq <<<"$run_jobs"
109+
exit 1
110+
fi
111+
env:
112+
GH_TOKEN: ${{ github.token }}
113+
run_id: ${{ steps.workflow-run.outputs.run-id }}
114+
job_id: ${{ steps.wait-for-job.outputs.job-id }}
115+
conclusion: ${{ steps.wait-for-job.outputs.conclusion }}
116+
- uses: actions/download-artifact@v4
117+
with:
118+
name: build
119+
run-id: ${{ steps.workflow-run.outputs.run-id }}
120+
github-token: ${{ github.token }}
121+
- name: Validate artifact
122+
run: |
123+
jq <build.json
124+
[[ "$(jq -er .run_id <build.json)" == "${{ steps.workflow-run.outputs.run-id }}" ]] || exit 1
125+
[[ "$(jq -er .run_attempt <build.json)" == "${{ steps.workflow-run.outputs.run-attempt }}" ]] || exit 1
126+
127+
test-missing-workflow:
128+
name: Test Missing Workflow
129+
# These permissions are needed to:
130+
# - Checkout the repo
131+
permissions:
132+
contents: read
133+
runs-on: ubuntu-latest
134+
steps:
135+
- uses: actions/checkout@v4
136+
- uses: ./
137+
id: wait-for-job
138+
with:
139+
run-id: ${{ github.run_id }}
140+
job-name: missing
141+
timeout: 10
142+
poll-interval: 5
143+
continue-on-error: true
144+
- name: Validate timeout
145+
run: |
146+
[[ "$outcome" == "failure" ]] || exit 1
147+
[[ -z "$job_id" ]] || exit 1
148+
[[ -z "$conclusion" ]] || exit 1
149+
env:
150+
outcome: ${{ steps.wait-for-job.outcome }}
151+
job_id: ${{ steps.wait-for-job.outputs.job-id }}
152+
conclusion: ${{ steps.wait-for-job.outputs.conclusion }}

.github/workflows/shell.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
name: Shell
3+
on:
4+
pull_request:
5+
paths:
6+
- "**.sh"
7+
- ".github/workflows/*"
8+
9+
jobs:
10+
lint-format:
11+
name: Lint & Format
12+
# These permissions are needed to:
13+
# - Checkout the Git repo (`contents: read`)
14+
# - Post a comments on PRs: https://github.com/luizm/action-sh-checker#secrets
15+
permissions:
16+
contents: read
17+
pull-requests: write
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: Extract workflow shell scripts
22+
id: extract
23+
uses: beacon-biosignals/gha-extract-shell-scripts@v1
24+
- uses: luizm/action-sh-checker@c6edb3de93e904488b413636d96c6a56e3ad671a # v0.8.0
25+
env:
26+
GITHUB_TOKEN: ${{ github.token }}
27+
with:
28+
sh_checker_comment: true
29+
# Support investigating linting/formatting errors
30+
- uses: actions/upload-artifact@v4
31+
if: ${{ failure() }}
32+
with:
33+
name: workflow-scripts
34+
path: ${{ steps.extract.outputs.output-dir }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: Target Workflow
3+
on:
4+
pull_request:
5+
paths:
6+
- "action.yaml"
7+
- ".github/workflows/integration-tests.yaml"
8+
9+
jobs:
10+
build:
11+
name: Build
12+
runs-on: ubuntu-latest
13+
steps:
14+
- run: |
15+
jq -n \
16+
--argjson run_id "${{ github.run_id }}" \
17+
--argjson run_attempt "${{ github.run_attempt }}" \
18+
'$ARGS.named' >build.json
19+
jq <build.json
20+
- uses: actions/upload-artifact@v4
21+
with:
22+
name: build
23+
path: build.json
24+
25+
# Keep the workflow running to validate the action waits on job completion and not
26+
# workflow completion.
27+
post-build:
28+
name: Post Build
29+
needs: build
30+
runs-on: ubuntu-latest
31+
steps:
32+
- run: sleep 60

.github/workflows/yaml.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
# https://yamllint.readthedocs.io/en/stable/integration.html#integration-with-github-actions
3+
name: YAML
4+
on:
5+
pull_request:
6+
paths:
7+
- "**/*.yaml"
8+
- "**/*.yml"
9+
jobs:
10+
lint:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Install yamllint
16+
run: pip install yamllint
17+
- name: Lint YAML files
18+
run: yamllint . --format=github

.yamllint.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
rules:
3+
indentation:
4+
spaces: 2
5+
indent-sequences: true
6+
document-start:
7+
present: true
8+
new-line-at-end-of-file: enable

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Beacon Biosignals
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,56 @@
1-
# wait-for-job
1+
# Wait for Job
2+
3+
Wait for a specific GitHub Actions workflow job to complete. Can be useful for synchronization between separate workflows.
4+
5+
This action can be used to wait for jobs within the same workflow but users should typically rely on the built-in GitHub Actions [`jobs.*.needs`](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idneeds) functionality for this purpose.
6+
7+
## Example
8+
9+
```yaml
10+
---
11+
jobs:
12+
example:
13+
# These permissions are needed to:
14+
# - Get the workflow run: https://github.com/beacon-biosignals/get-workflow-run#permissions
15+
# - Wait for the workflow job: https://github.com/beacon-biosignals/wait-for-job#permissions
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: beacon-biosignals/get-workflow-run@v1
19+
id: workflow-run
20+
with:
21+
workflow-file: build.yaml
22+
commit-sha: ${{ github.event.pull_request.head.sha }}
23+
- uses: beacon-biosignals/wait-for-job@v1
24+
id: wait-for-job
25+
with:
26+
run-id: ${{ steps.workfow-run.outputs.run-id }}
27+
job-name: Build
28+
# Now interact with shared resource created or modified the the job
29+
```
30+
31+
## Inputs
32+
33+
| Name | Description | Required | Example |
34+
|:---------------------|:------------|:---------|:--------|
35+
| `run-id` | The workflow run containing the job to wait for. | Yes | `9035794515` |
36+
| `job-name` | The rendered workflow job name to wait for. | Yes | `Build` |
37+
| `timeout` | The maximum amount of seconds to wait for the workflow job. Defaults to `600` (10 minutes). | No | `300` |
38+
| `poll-interval` | Number of seconds between job status checks. Defaults to `15`. | No | `5` |
39+
| `repository` | The repository runing the workflow. Defaults to `${{ github.repository }}`. | No | `beacon-biosignals/wait-for-job` |
40+
| `token` | The GitHub token used to authenticate with the GitHub API. Need when attempting to access artifacts in a different repository. Defaults to `${{ github.token }}`. | No | `${{ secret.PAT }}` |
41+
42+
## Outputs
43+
44+
| Name | Description | Example |
45+
|:-------------|:------------|:--------|
46+
| `job-id` | The job ID of the job which was waited upon. | `35737668081` |
47+
| `conclusion` | The result of the completed job after [`continue-on-error`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepscontinue-on-error) is applied. Possible values are `success`, `failure`, `cancelled`, or `skipped`. | `success` |
48+
49+
## Permissions
50+
51+
The following [job permissions](https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs) are required to run this action:
52+
53+
```yaml
54+
permissions:
55+
actions: read
56+
```

0 commit comments

Comments
 (0)