diff --git a/README.md b/README.md index 38fd600..84f5ceb 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/example-workflows/github-deployments.yml b/example-workflows/github-deployments.yml new file mode 100644 index 0000000..46ad57c --- /dev/null +++ b/example-workflows/github-deployments.yml @@ -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 }}'