Skip to content
Merged
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM alpine:3.15.0

RUN apk update
RUN apk --no-cache add curl jq coreutils
RUN apk update \
&& apk --no-cache add curl jq coreutils

COPY entrypoint.sh /entrypoint.sh

Expand Down
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ When deploying an app you may need to deploy additional services, this Github Ac
| `propagate_failure` | False | `true` | Fail current job if downstream job fails. |
| `trigger_workflow` | False | `true` | Trigger the specified workflow. |
| `wait_workflow` | False | `true` | Wait for workflow to finish. |
| `last_workflow_interval` | False | 0 | The number of seconds delay between checking for the last workflow. default: 0 |


## Example
Expand Down Expand Up @@ -53,7 +52,6 @@ When deploying an app you may need to deploy additional services, this Github Ac
propagate_failure: false
trigger_workflow: true
wait_workflow: true
last_workflow_interval: 1
```


Expand All @@ -62,18 +60,18 @@ When deploying an app you may need to deploy additional services, this Github Ac
You can test out the action locally by cloning the repository to your computer. You can run:

```shell
INPUT_OWNER="keithconvictional" \
INPUT_REPO="myrepo" \
INPUT_GITHUB_TOKEN="<REDACTED>" \
INPUT_GITHUB_USER="github-user" \
INPUT_WORKFLOW_FILE_NAME="main.yml" \
INPUT_REF="release-branch" \
INPUT_WAIT_INTERVAL=10 \
INPUT_PROPAGATE_FAILURE=false \
INPUT_TRIGGER_WORKFLOW=true \
INPUT_WORKFLOW_FILE_NAME="main.yml" \
INPUT_GITHUB_USER="github-user" \
INPUT_WAIT_WORKFLOW=true \
INPUT_LAST_WORKFLOW_INTERVAL=1 \
INPUT_OWNER="keithconvictional" \
INPUT_REPO="trigger-workflow-and-wait-example-repo1" \
INPUT_GITHUB_TOKEN="<REDACTED>" \
INPUT_CLIENT_PAYLOAD='{}' \
busybox sh entrypoint.sh
INPUT_CLIENT_PAYLOAD='{}' \
INPUT_PROPAGATE_FAILURE=false \
INPUT_TRIGGER_WORKFLOW=true \
INPUT_WAIT_WORKFLOW=true \
busybox sh entrypoint.sh
```

You will have to create a Github Personal access token. You can create a test workflow to be executed. In a repository, add a new `main.yml` to `.github/workflows/`. The workflow will be:
Expand Down
3 changes: 0 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ inputs:
wait_workflow:
description: 'Wait for workflow to finish. default: true'
required: false
last_workflow_interval:
description: 'The number of seconds delay between checking for the last workflow. default: 0'
required: false
outputs:
workflow_id:
description: The ID of the workflow that was triggered by this action
Expand Down
24 changes: 11 additions & 13 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ validate_args() {
wait_workflow=${INPUT_WAIT_WORKFLOW}
fi

last_workflow_interval=0
if [ -n "${INPUT_LAST_WORKFLOW_INTERVAL}" ]
then
last_workflow_interval=${INPUT_LAST_WORKFLOW_INTERVAL}
fi

if [ -z "${INPUT_OWNER}" ]
then
echo "Error: Owner is a required argument."
Expand Down Expand Up @@ -75,10 +69,10 @@ validate_args() {
exit 1
fi

client_payload=$(echo '{}' | jq)
client_payload=$(echo '{}' | jq -c)
if [ "${INPUT_CLIENT_PAYLOAD}" ]
then
client_payload=$(echo "${INPUT_CLIENT_PAYLOAD}" | jq)
client_payload=$(echo "${INPUT_CLIENT_PAYLOAD}" | jq -c)
fi

ref="main"
Expand Down Expand Up @@ -106,6 +100,12 @@ api() {
fi
}

lets_wait() {
local interval=${1:-$wait_interval}
echo >&2 "Sleeping for $interval seconds"
sleep "$interval"
}

# Return the ids of the most recent workflow runs, optionally filtered by user
get_workflow_runs() {
since=${1:?}
Expand All @@ -115,7 +115,7 @@ get_workflow_runs() {
echo "Getting workflow runs using query: ${query}" >&2

api "workflows/${INPUT_WORKFLOW_FILE_NAME}/runs?${query}" |
jq '.workflow_runs[].id' |
jq -r '.workflow_runs[].id' |
sort # Sort to ensure repeatable order, and lexicographically for compatibility with join
}

Expand All @@ -135,8 +135,7 @@ trigger_workflow() {
NEW_RUNS=$OLD_RUNS
while [ "$NEW_RUNS" = "$OLD_RUNS" ]
do
echo >&2 "Sleeping for ${wait_interval} seconds"
sleep "$wait_interval"
lets_wait
NEW_RUNS=$(get_workflow_runs "$SINCE")
done

Expand All @@ -160,8 +159,7 @@ wait_for_workflow_to_finish() {

while [[ "${conclusion}" == "null" && "${status}" != "completed" ]]
do
echo "Sleeping for \"${wait_interval}\" seconds"
sleep "${wait_interval}"
lets_wait

workflow=$(api "runs/$last_workflow_id")
conclusion=$(echo "${workflow}" | jq -r '.conclusion')
Expand Down