Skip to content

Commit 0717e6c

Browse files
committed
docs: add example with github deployments
1 parent 9c1a871 commit 0717e6c

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ For simplicity, each example is standalone, but may be combined as necessary to
7474
- [Verbose Push Logging](/example-workflows/verbose-logging.yml): Verbose client-side logging may be enabled with this method. Note that this does not enable trace mode on the deploy, and simply tells the `git` client to enable verbose log output
7575
- [Force Pushing](/example-workflows/force-push.yml): If the remote app has been previously pushed manually from a location other than CI, it may be necessary to enable force pushing to avoid git errors.
7676
- [Review Apps](/example-workflows/review-app.yml): Handles creation and deletion of review apps through use of `dokku apps:clone` and `dokku apps:destroy`. Review apps are a great way to allow folks to preview pull request changes before they get merged to production.
77+
- [GitHub Deployments](/example-workflows/github-deployments.yml): Deploys a codebase on push or merge to master using [GitHub Deployments](https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#deployments) to record the state of the deployment.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
name: 'deploy'
3+
4+
# yamllint disable-line rule:truthy
5+
on:
6+
push:
7+
branches:
8+
- master
9+
10+
jobs:
11+
deploy:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Cloning repo
15+
uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Create deployment
20+
id: create_deployment
21+
uses: octokit/[email protected]
22+
with:
23+
route: POST /repos/:repository/deployments
24+
repository: ${{ github.repository }}
25+
ref: ${{ github.sha }}
26+
environment: production
27+
required_contexts: '[]'
28+
production_environment: true
29+
env:
30+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
31+
32+
- name: Set deployment status to in progress
33+
uses: octokit/[email protected]
34+
with:
35+
route: POST /repos/:repository/deployments/:deployment/statuses
36+
repository: ${{ github.repository }}
37+
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
38+
environment: production
39+
environment_url: https://example.com
40+
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
41+
state: in_progress
42+
mediaType: '{"previews": ["flash", "ant-man"]}' # required for setting in_progress state and environment_url
43+
env:
44+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
45+
46+
- name: Push to dokku
47+
uses: dokku/github-action@master
48+
with:
49+
git_remote_url: 'ssh://[email protected]:22/appname'
50+
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
51+
52+
- name: Set deployment status to success
53+
uses: octokit/[email protected]
54+
with:
55+
route: POST /repos/:repository/deployments/:deployment/statuses
56+
repository: ${{ github.repository }}
57+
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
58+
environment: production
59+
environment_url: https://example.com
60+
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
61+
mediaType: '{"previews": ["ant-man"]}' # required for environment_url
62+
state: success
63+
env:
64+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
65+
66+
- name: Set deployment status to failure
67+
uses: octokit/[email protected]
68+
if: failure()
69+
with:
70+
route: POST /repos/:repository/deployments/:deployment/statuses
71+
repository: ${{ github.repository }}
72+
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
73+
environment: production
74+
environment_url: https://example.com
75+
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
76+
mediaType: '{"previews": ["ant-man"]}' # required for environment_url
77+
state: failure
78+
env:
79+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

0 commit comments

Comments
 (0)