Skip to content

Commit

Permalink
Refactor dockerfile and entrypoint script (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
duhow authored Mar 9, 2022
1 parent ceed17d commit d2b75f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# https://hub.docker.com/_/alpine
FROM alpine:latest
FROM alpine:3.15.0

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

COPY entrypoint.sh /entrypoint.sh

Expand Down
19 changes: 13 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ validate_args() {
exit 1
fi

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

ref="main"
Expand All @@ -82,6 +82,11 @@ validate_args() {
fi
}

lets_wait() {
echo "Sleeping for ${wait_interval} seconds"
sleep $wait_interval
}

trigger_workflow() {
echo "${GITHUB_API_URL}/repos/${INPUT_OWNER}/${INPUT_REPO}/actions/workflows/${INPUT_WORKFLOW_FILE_NAME}/dispatches"

Expand All @@ -90,8 +95,11 @@ trigger_workflow() {
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${INPUT_GITHUB_TOKEN}" \
--data "{\"ref\":\"${ref}\",\"inputs\":${inputs}}"
echo "Sleeping for ${wait_interval} seconds"
sleep $wait_interval
if [[ "$?" -gt 0 ]]; then
echo "Failed to call workflow_dispatch. Exiting."
exit 1
fi
lets_wait
}

wait_for_workflow_to_finish() {
Expand Down Expand Up @@ -123,8 +131,7 @@ wait_for_workflow_to_finish() {

while [[ "${conclusion}" == "null" && "${status}" != "\"completed\"" ]]
do
echo "Sleeping for \"${wait_interval}\" seconds"
sleep "${wait_interval}"
lets_wait
workflow=$(curl -X GET "${GITHUB_API_URL}/repos/${INPUT_OWNER}/${INPUT_REPO}/actions/workflows/${INPUT_WORKFLOW_FILE_NAME}/runs" \
-H 'Accept: application/vnd.github.antiope-preview+json' \
-H "Authorization: Bearer ${INPUT_GITHUB_TOKEN}" | jq '.workflow_runs[] | select(.id == '${last_workflow_id}')')
Expand Down

0 comments on commit d2b75f3

Please sign in to comment.