Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

action: add option to post the workflow URL #57

Merged
merged 1 commit into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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 |


## Example
Expand Down Expand Up @@ -54,6 +55,16 @@ 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: convictional/trigger-workflow-and-wait@v1.6.1
with:
owner: keithconvictional
repo: myrepo
github_token: ${{ secrets.GITHUB_PERSONAL_ACCESS_TOKEN }}
comment_downstream_url: ${{ github.event.pull_request.comments_url }}
```

## Testing

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ inputs:
wait_workflow:
description: 'Wait for workflow to finish. default: true'
required: false
comment_downstream_url:
description: 'Comment API link for commenting the downstream job URL'
required: false
default: ''
outputs:
workflow_id:
description: The ID of the workflow that was triggered by this action
Expand Down
17 changes: 17 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,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_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}"
Expand All @@ -159,6 +172,10 @@ wait_for_workflow_to_finish() {
echo "::set-output name=workflow_url::${last_workflow_url}"
echo ""

if [ -n "${INPUT_COMMENT_DOWNSTREAM_URL}" ]; then
comment_downstream_link ${last_workflow_url}
fi

conclusion=null
status=

Expand Down