Skip to content

Commit b5551df

Browse files
authored
Merge pull request #16 from unacast/environment_url
Add environment_url as parameters to create status
2 parents d6be60b + a60e032 commit b5551df

File tree

3 files changed

+70
-12
lines changed

3 files changed

+70
-12
lines changed

README.md

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,65 @@
22

33
This Github actions adds functions for creating a status on the github deployment api.
44

5-
It is a small wrapper for your workflows to use the Github Deployment Status API https://developer.github.com/v3/repos/deployments/#create-a-deployment-status
5+
It is a small wrapper for your workflows to use the Github Deployment Status API https://docs.github.com/en/rest/reference/repos#deployments
6+
7+
Read more on the deployment event on github actions https://docs.github.com/en/actions/reference/events-that-trigger-workflows#deployment
68

79
## Usage
810

9-
For example use this at the end of your job like this:
11+
For example like this
12+
```
13+
on: deployment
14+
name: Deploy
15+
jobs:
16+
deploy:
17+
name: Deploy event
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Set deploystatus in_progress
21+
uses: unacast/actions-github-deployment-status@[version]
22+
with:
23+
github_token: ${{ secrets.GITHUB_TOKEN }}
24+
status: in_progress
25+
26+
... <Do your deploy stuff>
27+
- name: Set an environment
28+
run: |
29+
echo '::set-env name=DEPLOY_ENVIRONMENT::http://halloi.lol'
1030
31+
- name: Update result to Deployment API
32+
if: always()
33+
uses: unacast/actions-github-deployment-status@[version]
34+
with:
35+
github_token: ${{ secrets.GITHUB_TOKEN }}
36+
status: ${{ job.status }}
37+
description: "Deployed to some magic"
38+
environment_url: '${{ DEPLOY_ENVIRONMENT }}'
1139
```
12-
- name: update deploy status
13-
if: always()
14-
uses: unacast/actions-github-deployment-status@[version]
15-
with:
16-
github_token: ${{ secrets.GITHUB_TOKEN }}
17-
status: ${{ job.status }}
18-
description: "The description to create. Restricted to 140 chars"
40+
41+
### Inputs
42+
The action has the following inputs (see in action.yml)
1943
```
44+
github_token:
45+
description: 'The GITHUB_TOKEN secret'
46+
required: true
47+
status:
48+
description: 'The status to create. Can be one of error, failure, inactive, in_progress, queued, pending, or success'
49+
required: true
50+
description:
51+
description: 'The description to create. Restricted to 140 chars'
52+
required: false
53+
default: ""
54+
environment_url:
55+
description: 'Sets the URL for accessing your environment'
56+
required: false
57+
default: ""
58+
auto_inactive:
59+
description: "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."
60+
required: false
61+
default: true
62+
```
63+
64+
## FAQ
65+
Q: Can I use this in workflows that listens to events other than the deployment event?
66+
A: No. This is tailored to the deployment event.

action.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ inputs:
1212
description: 'The description to create. Restricted to 140 chars'
1313
required: false
1414
default: ""
15+
environment_url:
16+
description: 'Sets the URL for accessing your environment'
17+
required: false
18+
default: ""
19+
auto_inactive:
20+
description: "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."
21+
required: false
22+
default: true
1523
runs:
1624
using: 'docker'
1725
image: 'Dockerfile'
18-
args: ['${{ inputs.status }}', '${{ inputs.description }}']
26+
args: ['${{ inputs.status }}', '${{ inputs.description }}', '${{ inputs.environment_url }}', '${{ inputs.auto_inactive }}']
1927
branding:
2028
icon: 'send'
2129
color: 'green'

bin/deployment-create-status

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# Arguments:
77
# $1 - The deployment state
88
# $2 - The deployment description
9+
# $3 - The deployment environment_url
10+
# $4 - auto_inactive flag
911
#
1012
set -e
1113

@@ -15,15 +17,16 @@ GITHUB_WORKFLOW_URL=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_R
1517

1618
DEPLOY_STATE=$(echo "${1}"|tr "[:upper:]" "[:lower:]")
1719
DEPLOY_DESC="${2}"
20+
DEPLOY_ENVIRONMENT_URL="${3}"
21+
DEPLOY_AUTO_INACTIVE="${4}"
1822

1923
ACCEPT_HEADER="application/vnd.github.ant-man-preview+json,application/vnd.github.flash-preview+json"
2024

21-
2225
[ -n "${DEPLOY_DESC}" ] || DEPLOY_DESC="Deploying from GitHub Actions"
2326

2427
echo "Setting status to ${DEPLOY_STATE} for deployment-id '${DEPLOYMENT_ID}'"
2528
wget -O-- \
26-
--post-data "{\"state\":\"${DEPLOY_STATE}\", \"target_url\":\"https://github.com/${GITHUB_REPOSITORY}/actions\", \"description\":\"${DEPLOY_DESC}\", \"log_url\":\"${GITHUB_WORKFLOW_URL}\"}" \
29+
--post-data "{\"state\":\"${DEPLOY_STATE}\", \"description\":\"${DEPLOY_DESC}\", \"log_url\":\"${GITHUB_WORKFLOW_URL}\", \"auto_inactive\":${DEPLOY_AUTO_INACTIVE}, \"environment_url\":\"${DEPLOY_ENVIRONMENT_URL}\"}" \
2730
--header "Authorization: token ${INPUT_GITHUB_TOKEN}" \
2831
--header "Content-Type: text/json; charset=utf-8" \
2932
--header "Accept: ${ACCEPT_HEADER}" \

0 commit comments

Comments
 (0)