Skip to content

Commit

Permalink
docs: add example with github deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
badsyntax committed Jan 12, 2021
1 parent 9c1a871 commit 0717e6c
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ For simplicity, each example is standalone, but may be combined as necessary to
- [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
- [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.
- [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.
- [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.
79 changes: 79 additions & 0 deletions example-workflows/github-deployments.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
name: 'deploy'

# yamllint disable-line rule:truthy
on:
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Cloning repo
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Create deployment
id: create_deployment
uses: octokit/request-action@v2.x
with:
route: POST /repos/:repository/deployments
repository: ${{ github.repository }}
ref: ${{ github.sha }}
environment: production
required_contexts: '[]'
production_environment: true
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- name: Set deployment status to in progress
uses: octokit/request-action@v2.x
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
environment: production
environment_url: https://example.com
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: in_progress
mediaType: '{"previews": ["flash", "ant-man"]}' # required for setting in_progress state and environment_url
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- name: Push to dokku
uses: dokku/github-action@master
with:
git_remote_url: 'ssh://dokku@dokku.me:22/appname'
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Set deployment status to success
uses: octokit/request-action@v2.x
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
environment: production
environment_url: https://example.com
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
mediaType: '{"previews": ["ant-man"]}' # required for environment_url
state: success
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- name: Set deployment status to failure
uses: octokit/request-action@v2.x
if: failure()
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }}
environment: production
environment_url: https://example.com
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
mediaType: '{"previews": ["ant-man"]}' # required for environment_url
state: failure
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

0 comments on commit 0717e6c

Please sign in to comment.