Skip to content

Commit dc8fc82

Browse files
authored
action: add option to post the workflow URL (#57)
as a comment to a configurable comments API URL. For instance when having very long running workflows called by the action, it's hard for the user to see the actual pipeline and its results. For better tracebility and user expierence post the link to the acquired workflow URL as a comment. Typical setting would be to set it to ${{ github.event.pull_request.comments_url }} for pull requests. As this may not be wanted by all users set the default to empty, meaning no comments will be made
1 parent 2fcaa46 commit dc8fc82

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ When deploying an app you may need to deploy additional services, this Github Ac
2222
| `propagate_failure` | False | `true` | Fail current job if downstream job fails. |
2323
| `trigger_workflow` | False | `true` | Trigger the specified workflow. |
2424
| `wait_workflow` | False | `true` | Wait for workflow to finish. |
25+
| `comment_downstream_url` | False | '' | A comments API URL to comment the current downstream job URL to. Default: no comment |
2526

2627

2728
## Example
@@ -54,6 +55,16 @@ When deploying an app you may need to deploy additional services, this Github Ac
5455
wait_workflow: true
5556
```
5657
58+
### Comment the current running workflow URL for a PR
59+
60+
```yaml
61+
- uses: convictional/[email protected]
62+
with:
63+
owner: keithconvictional
64+
repo: myrepo
65+
github_token: ${{ secrets.GITHUB_PERSONAL_ACCESS_TOKEN }}
66+
comment_downstream_url: ${{ github.event.pull_request.comments_url }}
67+
```
5768
5869
## Testing
5970

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ inputs:
3838
wait_workflow:
3939
description: 'Wait for workflow to finish. default: true'
4040
required: false
41+
comment_downstream_url:
42+
description: 'Comment API link for commenting the downstream job URL'
43+
required: false
44+
default: ''
4145
outputs:
4246
workflow_id:
4347
description: The ID of the workflow that was triggered by this action

entrypoint.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,19 @@ trigger_workflow() {
148148
join -v2 <(echo "$OLD_RUNS") <(echo "$NEW_RUNS")
149149
}
150150

151+
comment_downstream_link() {
152+
if response=$(curl --fail-with-body -sSL -X POST \
153+
"${INPUT_COMMENT_DOWNSTREAM_URL}" \
154+
-H "Authorization: Bearer ${INPUT_GITHUB_TOKEN}" \
155+
-H 'Accept: application/vnd.github.v3+json' \
156+
-d "{\"body\": \"Running downstream job at $1\"}")
157+
then
158+
echo "$response"
159+
else
160+
echo >&2 "failed to comment to ${INPUT_COMMENT_DOWNSTREAM_URL}:"
161+
fi
162+
}
163+
151164
wait_for_workflow_to_finish() {
152165
last_workflow_id=${1:?}
153166
last_workflow_url="${GITHUB_SERVER_URL}/${INPUT_OWNER}/${INPUT_REPO}/actions/runs/${last_workflow_id}"
@@ -159,6 +172,10 @@ wait_for_workflow_to_finish() {
159172
echo "::set-output name=workflow_url::${last_workflow_url}"
160173
echo ""
161174

175+
if [ -n "${INPUT_COMMENT_DOWNSTREAM_URL}" ]; then
176+
comment_downstream_link ${last_workflow_url}
177+
fi
178+
162179
conclusion=null
163180
status=
164181

0 commit comments

Comments
 (0)