From 30e56982acf0f267aa1532f8e9b680cd8822a7b0 Mon Sep 17 00:00:00 2001 From: Viktor Delev Date: Tue, 11 Nov 2025 13:51:32 +0100 Subject: [PATCH 1/2] merged changes from renamed upstream repo --- README.md | 28 ++++++++++++++++++++++++++-- action.yml | 9 +++++++++ entrypoint.sh | 33 ++++++++++++++++++++++++++++----- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7685667..33d69bf 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@ Github Action for trigger a workflow from another workflow. The action then waits for a response. see: -see also +see also +based on **When would you use it?** @@ -24,6 +25,16 @@ 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. | +| `comment_downstream_url` | False | `` | A comments API URL to comment the current downstream job URL to. Default: no comment | +| `comment_github_token` | False | `${{github.token}}` | token used for pull_request comments | + +## Outputs + +| Output Name | Description | +| ------------- | --------------------- | +| `workflow_id` | The ID of the workflow that was triggered by this action | +| `workflow_url` | The URL of the workflow that was triggered by this action | +| `conclusion` | The conclusion of the workflow that was triggered by this action | ## Example @@ -55,6 +66,17 @@ When deploying an app you may need to deploy additional services, this Github Ac wait_workflow: true ``` +### Comment the current running workflow URL for a PR + +```yaml +- uses: ./.github/actions/github-action-trigger-workflow + with: + owner: datavisyn + repo: myrepo + github_token: ${{ secrets.GITHUB_PERSONAL_ACCESS_TOKEN }} + comment_downstream_url: ${{ github.event.pull_request.comments_url }} +``` + ## Testing You can test out the action locally by cloning the repository to your computer. You can run: @@ -90,7 +112,7 @@ jobs: sleep 25 ``` -For testing a failure case, just add this line after the sleep: +You can see the example [here](https://github.com/keithconvictional/trigger-workflow-and-wait-example-repo1/blob/master/.github/workflows/main.yml). For testing a failure case, just add this line after the sleep: ```yaml ... @@ -100,6 +122,8 @@ For testing a failure case, just add this line after the sleep: echo "For testing failure" exit 1 ``` + exit 1 +``` ## Potential Issues diff --git a/action.yml b/action.yml index 135c894..026fca6 100644 --- a/action.yml +++ b/action.yml @@ -36,11 +36,20 @@ inputs: wait_workflow: description: 'Wait for workflow to finish. default: true' required: false + comment_downstream_url: + description: 'A comments API URL to comment the current downstream job URL to. Default: no comment' + required: false + comment_github_token: + description: 'token used for pull_request comments' + required: false + default: ${{github.token}} outputs: workflow_id: description: The ID of the workflow that was triggered by this action workflow_url: description: The URL of the workflow that was triggered by this action + conclusion: + description: The conclusion of the workflow that was triggered by this action runs: using: 'docker' image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index 2364477..e79c77a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -83,8 +83,9 @@ validate_args() { } lets_wait() { - echo "Sleeping for ${wait_interval} seconds" - sleep "$wait_interval" + local interval=${1:-$wait_interval} + echo >&2 "Sleeping for $interval seconds" + sleep "$interval" } api() { @@ -101,7 +102,11 @@ api() { echo >&2 "api failed:" echo >&2 "path: $path" echo >&2 "response: $response" - exit 1 + if [[ "$response" == *'"Server Error"'* ]]; then + echo "Server error - trying again" + else + exit 1 + fi fi } @@ -142,6 +147,19 @@ trigger_workflow() { join -v2 <(echo "$OLD_RUNS") <(echo "$NEW_RUNS") } +comment_downstream_link() { + if response=$(curl --fail-with-body -sSL -X POST \ + "${INPUT_COMMENT_DOWNSTREAM_URL}" \ + -H "Authorization: Bearer ${INPUT_COMMENT_GITHUB_TOKEN}" \ + -H 'Accept: application/vnd.github.v3+json' \ + -d "{\"body\": \"Running downstream job at $1\"}") + then + echo "$response" + else + echo >&2 "failed to comment to ${INPUT_COMMENT_DOWNSTREAM_URL}:" + fi +} + wait_for_workflow_to_finish() { last_workflow_id=${1:?} last_workflow_url="${GITHUB_SERVER_URL}/${INPUT_OWNER}/${INPUT_REPO}/actions/runs/${last_workflow_id}" @@ -149,10 +167,14 @@ wait_for_workflow_to_finish() { echo "Waiting for workflow to finish:" echo "The workflow id is [${last_workflow_id}]." echo "The workflow logs can be found at ${last_workflow_url}" - echo "workflow_id=$last_workflow_id" >> "$GITHUB_OUTPUT" - echo "workflow_url=$last_workflow_url" >> "$GITHUB_OUTPUT" + echo "workflow_id=${last_workflow_id}" >> $GITHUB_OUTPUT + echo "workflow_url=${last_workflow_url}" >> $GITHUB_OUTPUT echo "" + if [ -n "${INPUT_COMMENT_DOWNSTREAM_URL}" ]; then + comment_downstream_link ${last_workflow_url} + fi + conclusion=null status= @@ -166,6 +188,7 @@ wait_for_workflow_to_finish() { echo "Checking conclusion [${conclusion}]" echo "Checking status [${status}]" + echo "conclusion=${conclusion}" >> $GITHUB_OUTPUT done if [[ "${conclusion}" == "success" && "${status}" == "completed" ]] From c0f40fad89a74e6c723ee5b183080c8a8d8d2fe1 Mon Sep 17 00:00:00 2001 From: Viktor Delev Date: Tue, 11 Nov 2025 13:59:16 +0100 Subject: [PATCH 2/2] fix --- entrypoint.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index e79c77a..329d579 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -226,8 +226,5 @@ main() { echo "Skipping waiting for workflow." fi } -echo "${GITHUB_API_URL}" -echo "${INPUT_OWNER}" -echo "${INPUT_REPO}" main