Skip to content

Commit 30e5698

Browse files
committed
merged changes from renamed upstream repo
1 parent 7a93465 commit 30e5698

File tree

3 files changed

+63
-7
lines changed

3 files changed

+63
-7
lines changed

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
Github Action for trigger a workflow from another workflow. The action then waits for a response.
44
see: <https://github.com/datavisyn/github-action-trigger-workflow/blob/main/README.md>
55

6-
see also <https://github.com/convictional/github-action-trigger-workflow>
6+
see also <https://github.com/convictional/trigger-workflow-and-wait>
7+
based on <https://github.com/convictional/github-action-trigger-workflow>
78

89
**When would you use it?**
910

@@ -24,6 +25,16 @@ When deploying an app you may need to deploy additional services, this Github Ac
2425
| `propagate_failure` | False | `true` | Fail current job if downstream job fails. |
2526
| `trigger_workflow` | False | `true` | Trigger the specified workflow. |
2627
| `wait_workflow` | False | `true` | Wait for workflow to finish. |
28+
| `comment_downstream_url` | False | `` | A comments API URL to comment the current downstream job URL to. Default: no comment |
29+
| `comment_github_token` | False | `${{github.token}}` | token used for pull_request comments |
30+
31+
## Outputs
32+
33+
| Output Name | Description |
34+
| ------------- | --------------------- |
35+
| `workflow_id` | The ID of the workflow that was triggered by this action |
36+
| `workflow_url` | The URL of the workflow that was triggered by this action |
37+
| `conclusion` | The conclusion of the workflow that was triggered by this action |
2738

2839
## Example
2940

@@ -55,6 +66,17 @@ When deploying an app you may need to deploy additional services, this Github Ac
5566
wait_workflow: true
5667
```
5768
69+
### Comment the current running workflow URL for a PR
70+
71+
```yaml
72+
- uses: ./.github/actions/github-action-trigger-workflow
73+
with:
74+
owner: datavisyn
75+
repo: myrepo
76+
github_token: ${{ secrets.GITHUB_PERSONAL_ACCESS_TOKEN }}
77+
comment_downstream_url: ${{ github.event.pull_request.comments_url }}
78+
```
79+
5880
## Testing
5981
6082
You can test out the action locally by cloning the repository to your computer. You can run:
@@ -90,7 +112,7 @@ jobs:
90112
sleep 25
91113
```
92114

93-
For testing a failure case, just add this line after the sleep:
115+
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:
94116

95117
```yaml
96118
...
@@ -100,6 +122,8 @@ For testing a failure case, just add this line after the sleep:
100122
echo "For testing failure"
101123
exit 1
102124
```
125+
exit 1
126+
```
103127

104128
## Potential Issues
105129

action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,20 @@ inputs:
3636
wait_workflow:
3737
description: 'Wait for workflow to finish. default: true'
3838
required: false
39+
comment_downstream_url:
40+
description: 'A comments API URL to comment the current downstream job URL to. Default: no comment'
41+
required: false
42+
comment_github_token:
43+
description: 'token used for pull_request comments'
44+
required: false
45+
default: ${{github.token}}
3946
outputs:
4047
workflow_id:
4148
description: The ID of the workflow that was triggered by this action
4249
workflow_url:
4350
description: The URL of the workflow that was triggered by this action
51+
conclusion:
52+
description: The conclusion of the workflow that was triggered by this action
4453
runs:
4554
using: 'docker'
4655
image: 'Dockerfile'

entrypoint.sh

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ validate_args() {
8383
}
8484

8585
lets_wait() {
86-
echo "Sleeping for ${wait_interval} seconds"
87-
sleep "$wait_interval"
86+
local interval=${1:-$wait_interval}
87+
echo >&2 "Sleeping for $interval seconds"
88+
sleep "$interval"
8889
}
8990

9091
api() {
@@ -101,7 +102,11 @@ api() {
101102
echo >&2 "api failed:"
102103
echo >&2 "path: $path"
103104
echo >&2 "response: $response"
104-
exit 1
105+
if [[ "$response" == *'"Server Error"'* ]]; then
106+
echo "Server error - trying again"
107+
else
108+
exit 1
109+
fi
105110
fi
106111
}
107112

@@ -142,17 +147,34 @@ trigger_workflow() {
142147
join -v2 <(echo "$OLD_RUNS") <(echo "$NEW_RUNS")
143148
}
144149

150+
comment_downstream_link() {
151+
if response=$(curl --fail-with-body -sSL -X POST \
152+
"${INPUT_COMMENT_DOWNSTREAM_URL}" \
153+
-H "Authorization: Bearer ${INPUT_COMMENT_GITHUB_TOKEN}" \
154+
-H 'Accept: application/vnd.github.v3+json' \
155+
-d "{\"body\": \"Running downstream job at $1\"}")
156+
then
157+
echo "$response"
158+
else
159+
echo >&2 "failed to comment to ${INPUT_COMMENT_DOWNSTREAM_URL}:"
160+
fi
161+
}
162+
145163
wait_for_workflow_to_finish() {
146164
last_workflow_id=${1:?}
147165
last_workflow_url="${GITHUB_SERVER_URL}/${INPUT_OWNER}/${INPUT_REPO}/actions/runs/${last_workflow_id}"
148166

149167
echo "Waiting for workflow to finish:"
150168
echo "The workflow id is [${last_workflow_id}]."
151169
echo "The workflow logs can be found at ${last_workflow_url}"
152-
echo "workflow_id=$last_workflow_id" >> "$GITHUB_OUTPUT"
153-
echo "workflow_url=$last_workflow_url" >> "$GITHUB_OUTPUT"
170+
echo "workflow_id=${last_workflow_id}" >> $GITHUB_OUTPUT
171+
echo "workflow_url=${last_workflow_url}" >> $GITHUB_OUTPUT
154172
echo ""
155173

174+
if [ -n "${INPUT_COMMENT_DOWNSTREAM_URL}" ]; then
175+
comment_downstream_link ${last_workflow_url}
176+
fi
177+
156178
conclusion=null
157179
status=
158180

@@ -166,6 +188,7 @@ wait_for_workflow_to_finish() {
166188

167189
echo "Checking conclusion [${conclusion}]"
168190
echo "Checking status [${status}]"
191+
echo "conclusion=${conclusion}" >> $GITHUB_OUTPUT
169192
done
170193

171194
if [[ "${conclusion}" == "success" && "${status}" == "completed" ]]

0 commit comments

Comments
 (0)