Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Included branch parameter to filter runs #122

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ proceeding with the next steps in your workflow.
- `repository`: The repository in the format 'owner/repository'. It is used to
fetch the workflow runs. If not provided, it falls back to the current
repository (default: `github.context.repo.owner/github.context.repo.repo`).
- `branch`: The branch to fetch the workflow runs (If not provided, considers all branches.)
- `retryIntervalSeconds`: The number of seconds to wait between each retry
(default: 60).
- `timeoutSeconds`: The maximum number of seconds to wait before timing out
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ inputs:
'The repository in the format owner/repo to fetch the workflow runs
(default is the current repository)'

branch:
description:
'The branch to fetch the workflow runs (If not provided, considers all branches)'

retryIntervalSeconds:
description: 'Retry interval in seconds'
default: '60'
Expand Down
12 changes: 9 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "await-workflow",
"description": "This GitHub Action allows you to wait for a specific workflow to complete before proceeding with the next steps in your workflow.",
"version": "1.0.5",
"version": "1.0.6",
"author": "Johannes Vedder",
"private": true,
"repository": {
Expand Down
14 changes: 11 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
repository:
core.getInput('repository') ||
`${github.context.repo.owner}/${github.context.repo.repo}`,
branch: core.getInput('branch'),
retryIntervalSeconds: Number(core.getInput('retryIntervalSeconds')),
timeoutSeconds: Number(core.getInput('timeoutSeconds')),
initialWaitSeconds: Number(core.getInput('initialWaitSeconds')),
Expand Down Expand Up @@ -34,7 +35,13 @@
}
)

const latestWorkflowRun = response.data.workflow_runs?.[0]
let workflow_runs = response.data.workflow_runs;

Check failure on line 38 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Delete `;`

Check failure on line 38 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Extra semicolon

if (inputs.branch){

Check failure on line 40 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Insert `·`
workflow_runs = workflow_runs?.filter(run => run.head_branch === inputs.branch);

Check failure on line 41 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace `run·=>·run.head_branch·===·inputs.branch);` with `⏎········run·=>·run.head_branch·===·inputs.branch`

Check failure on line 41 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

'run' is already declared in the upper scope on line 101 column 23

Check failure on line 41 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Extra semicolon
}

Check failure on line 42 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace `}` with `··)`

Check failure on line 43 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Insert `}⏎`
const latestWorkflowRun = workflow_runs?.[0]
const totalCounts = response.data.total_count

if (totalCounts === 0) {
Expand All @@ -44,6 +51,7 @@

const latestRunStatus = latestWorkflowRun?.status
const latestRunConclusion = latestWorkflowRun?.conclusion
const latestRunBranch = latestWorkflowRun?.head_branch

if (latestRunStatus === 'completed') {
if (
Expand All @@ -55,11 +63,11 @@
)
break
} else if (latestRunConclusion === 'failure') {
core.setFailed('Latest run of the given workflow was a failure')
core.setFailed(`Latest run of the given workflow in branch ${latestRunBranch} was a failure`)

Check failure on line 66 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace ``Latest·run·of·the·given·workflow·in·branch·${latestRunBranch}·was·a·failure`` with `⏎··········`Latest·run·of·the·given·workflow·in·branch·${latestRunBranch}·was·a·failure`⏎········`
process.exit(1)
} else {
core.setFailed(
`Latest run of the given workflow was not successful [${latestRunStatus}]`
`Latest run of the given workflow in branch ${latestRunBranch} was not successful [${latestRunStatus}]`
)
process.exit(1)
}
Expand Down
Loading