From a6f303ec30c41b04349265c6c1c971c2007e1ca5 Mon Sep 17 00:00:00 2001 From: Fabio Napoleoni Date: Wed, 30 Oct 2024 15:38:37 +0100 Subject: [PATCH 1/3] Add last run id to the outputs of the action --- action.yml | 2 ++ entrypoint.sh | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f6df592..06cf671 100644 --- a/action.yml +++ b/action.yml @@ -53,6 +53,8 @@ outputs: description: The URL of the workflow that was triggered by this action conclusion: description: Conclusion of the job, i.e pass/failure + workflow_run_id: + description: The ID of the triggered workflow run triggered by this action runs: using: 'docker' image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index 58dca5f..a65ebe6 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -101,7 +101,7 @@ api() { echo >&2 "api failed:" echo >&2 "path: $path" echo >&2 "response: $response" - if [[ "$response" == *'"Server Error"'* ]]; then + if [[ "$response" == *'"Server Error"'* ]]; then echo "Server error - trying again" else exit 1 @@ -196,6 +196,11 @@ wait_for_workflow_to_finish() { echo "conclusion=${conclusion}" >> $GITHUB_OUTPUT done + # Add the run ID to the outputs of the action + workflow=$(api "runs/$last_workflow_id") + workflow_run_id=$(echo "${workflow}" | jq -r '.id') + echo "workflow_run_id=${workflow_run_id}" >> $GITHUB_OUTPUT + if [[ "${conclusion}" == "success" && "${status}" == "completed" ]] then echo "Yes, success" From 03a01eabd3512e4b3a826e937c261d0d3ab97133 Mon Sep 17 00:00:00 2001 From: Fabio Napoleoni Date: Wed, 30 Oct 2024 15:41:34 +0100 Subject: [PATCH 2/3] Add SHAs to outputs of action --- action.yml | 4 ++++ entrypoint.sh | 3 +++ 2 files changed, 7 insertions(+) diff --git a/action.yml b/action.yml index 06cf671..caef5c8 100644 --- a/action.yml +++ b/action.yml @@ -55,6 +55,10 @@ outputs: description: Conclusion of the job, i.e pass/failure workflow_run_id: description: The ID of the triggered workflow run triggered by this action + full_sha: + description: The full SHA of commit that triggered the workflow + short_sha: + description: The short SHA of commit that triggered the workflow first 10 chars runs: using: 'docker' image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index a65ebe6..0b2aa2b 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -200,6 +200,9 @@ wait_for_workflow_to_finish() { workflow=$(api "runs/$last_workflow_id") workflow_run_id=$(echo "${workflow}" | jq -r '.id') echo "workflow_run_id=${workflow_run_id}" >> $GITHUB_OUTPUT + head_sha=$(echo "${workflow}" | jq -r '.head_sha') + echo "full_sha=${full_sha}" >> $GITHUB_OUTPUT + echo "short_sha=${full_sha:0:10}" >> $GITHUB_OUTPUT if [[ "${conclusion}" == "success" && "${status}" == "completed" ]] then From 1841116af9ccf199f92839df514b27e845257d2f Mon Sep 17 00:00:00 2001 From: Fabio Napoleoni Date: Wed, 30 Oct 2024 16:11:07 +0100 Subject: [PATCH 3/3] Fix outputs --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 0b2aa2b..2de36e6 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -201,8 +201,8 @@ wait_for_workflow_to_finish() { workflow_run_id=$(echo "${workflow}" | jq -r '.id') echo "workflow_run_id=${workflow_run_id}" >> $GITHUB_OUTPUT head_sha=$(echo "${workflow}" | jq -r '.head_sha') - echo "full_sha=${full_sha}" >> $GITHUB_OUTPUT - echo "short_sha=${full_sha:0:10}" >> $GITHUB_OUTPUT + echo "full_sha=${head_sha}" >> $GITHUB_OUTPUT + echo "short_sha=${head_sha:0:10}" >> $GITHUB_OUTPUT if [[ "${conclusion}" == "success" && "${status}" == "completed" ]] then