Skip to content

Commit

Permalink
Improve log_url by requiring context data to be specified (#3)
Browse files Browse the repository at this point in the history
* Add required run_id input to improve log_url
* Add deployment_status_url input
* Make status input required

Closes #3
  • Loading branch information
alexjurkiewicz authored and rsotnychenko committed Apr 23, 2020
1 parent 750b77d commit 06e6b80
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ This action lets you easily update status of a Deployment on GitHub. Learn more

| Name | Required | Default value | Description |
|-----------------|----------|----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| status | no | `in_progress` | Desired status of the Deployment. Can be one of `error`, `failure`, `inactive`, `in_progress`, `queued`, `pending` or `success` |
| run_id | **yes** | | Set this to `${{ github.run_id }}` so the deployment status log URL can be properly set. |
| status | **yes** | | Desired status of the Deployment. Can be one of `error`, `failure`, `inactive`, `in_progress`, `queued`, `pending` or `success` |
| description | no | <empty string> | A short description of the status. The maximum description length is 140 characters. |
| auto_inactive | no | true | Adds a new inactive status to all prior non-transient, non-production environment deployments with the same repository and environment name as the created status's deployment. An inactive status is only added to deployments that had a success state. |
| environment_url | no | <empty string> | Sets the URL for accessing your environment. |
| deployment_status_url | no | (loaded from event) | Explicitly specify the deployment status URL to post the deployment status to. Normally, this will be auto-detected from the GitHub Actions [`DeploymentEvent`](https://developer.github.com/v3/activity/events/types/#deploymentevent) payload. However, if you are runnning from another event type or want to override the deployment to update, you can manually specify the full `https://api.github.com/repos/:owner/:repo/deployments/:deployment_id/statuses` URL here. |

## Action outputs

Expand Down Expand Up @@ -38,7 +40,10 @@ jobs:
- uses: actions/checkout@v1
- id: set_state_in_progress
name: Set deployment status to [in_progress]
uses: rsotnychenko/deployment-status-update@0.1.3
uses: rsotnychenko/deployment-status-update@0.2.0
with:
run_id: ${{ github.run_id }}
status: in_progress
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy to GAE
Expand All @@ -51,9 +56,10 @@ jobs:
- id: set_state_final
if: always()
name: Set deployment status
uses: rsotnychenko/deployment-status-update@0.1.3
uses: rsotnychenko/deployment-status-update@0.2.0
with:
status: ${{ job.status }}
run_id: ${{ github.run_id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# TODO: Add rollback operations
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ branding:
icon: 'rss'
color: 'gray-dark'
inputs:
run_id:
description: 'Set this to `github.run_id` so the deployment status log URL can be properly set.'
required: true
status:
description: 'desired deployment status'
required: true
Expand All @@ -17,6 +20,8 @@ inputs:
environment_url:
default: ''
description: 'Sets the URL for accessing your environment'
deployment_status_url:
description: Override the default deployment status URL.
outputs:
deployment_id:
description: 'An ID of the deployment in GitHub'
Expand Down
31 changes: 22 additions & 9 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
#!/bin/ash -xe

if [ "${GITHUB_EVENT_NAME}" != "deployment" ]; then
echo "Expected GITHUB_EVENT_NAME=deployment, got [${GITHUB_EVENT_NAME}]"
exit 1
fi

get_from_event() {
jq -r "$1" "${GITHUB_EVENT_PATH}"
}

GITHUB_API_DEPLOYMENTS_URL="$(get_from_event '.deployment.statuses_url')"
GITHUB_ACTIONS_URL="$(get_from_event '.repository.html_url')/actions"
# Test required inputs are set
if [ -z "${INPUT_STATUS}" ]; then
echo "Missing input status"
exit 1
fi
if [ -z "${INPUT_RUN_ID:-}" ]; then
echo "Missing input run_id"
exit 1
fi
if [ -n "${INPUT_DEPLOYMENT_STATUS_URL:-}" ]; then
GITHUB_API_DEPLOYMENTS_URL=$INPUT_DEPLOYMENT_STATUS_URL
else
GITHUB_API_DEPLOYMENTS_URL="$(get_from_event '.deployment.statuses_url')"
if [ "$GITHUB_API_DEPLOYMENTS_URL" = "null" ]; then
echo "Couldn't detect deployment URL from the GitHub Actions workflow event. If you aren't running from a 'deployment' event, you must set the 'deployment_status_url' input."
exit 1
fi
fi

# Set variables
GITHUB_ACTIONS_RUN_URL="$(get_from_event '.repository.html_url')/actions/runs/$INPUT_RUN_ID"
INPUT_STATUS=$(echo "$INPUT_STATUS" | tr '[:upper:]' '[:lower:]')
if [ "$INPUT_STATUS" = cancelled ] ; then
echo "Rewriting status from cancelled to error"
INPUT_STATUS=error
fi
: ${INPUT_STATUS:=in_progress} # set default

curl --fail \
-X POST "${GITHUB_API_DEPLOYMENTS_URL}" \
Expand All @@ -26,7 +39,7 @@ curl --fail \
-d @- <<EOF
{
"state": "${INPUT_STATUS}",
"log_url": "${GITHUB_ACTIONS_URL}",
"log_url": "${GITHUB_ACTIONS_RUN_URL}",
"description": "${INPUT_DESCRIPTION}",
"auto_inactive": ${INPUT_AUTO_INACTIVE},
"environment_url": "${INPUT_ENVIRONMENT_URL}"
Expand Down

0 comments on commit 06e6b80

Please sign in to comment.