diff --git a/.github/workflows/prod-deploy.yml b/.github/workflows/prod-deploy.yml index 8f51ae0..a32a76f 100644 --- a/.github/workflows/prod-deploy.yml +++ b/.github/workflows/prod-deploy.yml @@ -11,74 +11,20 @@ jobs: deploy: name: Deploy to production runs-on: ubuntu-latest + + # deploy to the production environment + environment: + name: production + url: http://github-actions-demo-app.dokku.proxima-web.com + steps: - name: Cloning repo uses: actions/checkout@v2 with: fetch-depth: 0 - - name: Create deployment - id: create_deployment - uses: octokit/request-action@v2.0.26 - with: - route: POST /repos/:repository/deployments - repository: ${{ github.repository }} - ref: ${{ github.sha }} - environment: production - required_contexts: '[]' - production_environment: true - auto_merge: false - env: - GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' - - - name: Set deployment status to in progress - uses: octokit/request-action@v2.0.26 - with: - route: POST /repos/:repository/deployments/:deployment/statuses - repository: ${{ github.repository }} - deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }} - environment: production - environment_url: http://github-actions-demo-app.dokku.proxima-web.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.proxima-web.com:22/github-actions-demo-app' ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} - - - name: Set GitHub deployment status to success - id: successful_deployment - if: success() - uses: octokit/request-action@v2.0.26 - with: - route: POST /repos/:repository/deployments/:deployment/statuses - repository: ${{ github.repository }} - deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }} - environment: review - environment_url: http://github-actions-demo-app.dokku.proxima-web.com - log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} - mediaType: '{"previews": ["ant-man"]}' - state: success - env: - GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' - - - name: Set GitHub deployment status to failure - id: failed_deployment - uses: octokit/request-action@v2.0.26 - if: failure() - with: - route: POST /repos/:repository/deployments/:deployment/statuses - repository: ${{ github.repository }} - deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }} - environment: review - environment_url: http://github-actions-demo-app.dokku.proxima-web.com - log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} - mediaType: '{"previews": ["ant-man"]}' - state: failure - env: - GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' diff --git a/.github/workflows/review-app.yml b/.github/workflows/review-app.yml index 0f7b110..31270eb 100644 --- a/.github/workflows/review-app.yml +++ b/.github/workflows/review-app.yml @@ -3,49 +3,27 @@ name: 'Deploy Review App' # yamllint disable-line rule:truthy on: - # onl run this workflow on pull request events - pull_request + # only run this workflow on pull request events + pull_request: + types: [opened, synchronize, closed] jobs: review_app: runs-on: ubuntu-latest - # only run when a pull request is opened - if: github.event_name == 'pull_request' - environment: review + # only run when a pull request is opened or synchronized + if: github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize') + + # deploy to the review environment + environment: + name: review + url: http://github-actions-demo-app-${{ github.event.pull_request.number }}.dokku.proxima-web.com + steps: - name: Cloning repo uses: actions/checkout@v2 with: fetch-depth: 0 - - name: Create deployment - id: create_deployment - uses: octokit/request-action@v2.0.26 - with: - route: POST /repos/:repository/deployments - repository: ${{ github.repository }} - ref: ${{ github.event.pull_request.head.ref }} - environment: review - required_contexts: '[]' - production_environment: true - auto_merge: false - env: - GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' - - - name: Set deployment status to in progress - uses: octokit/request-action@v2.0.26 - with: - route: POST /repos/:repository/deployments/:deployment/statuses - repository: ${{ github.repository }} - deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }} - environment: review - environment_url: http://github-actions-demo-app-${{ github.event.pull_request.number }}.dokku.proxima-web.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: @@ -57,39 +35,6 @@ jobs: review_app_name: github-actions-demo-app-${{ github.event.pull_request.number }} ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} - - name: Set GitHub deployment status to success - id: successful_deployment - if: success() - uses: octokit/request-action@v2.0.26 - with: - route: POST /repos/:repository/deployments/:deployment/statuses - repository: ${{ github.repository }} - deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }} - environment: review - environment_url: http://github-actions-demo-app-${{ github.event.pull_request.number }}.dokku.proxima-web.com - log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} - mediaType: '{"previews": ["ant-man"]}' - state: success - auto_inactive: false - env: - GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' - - - name: Set GitHub deployment status to failure - id: failed_deployment - uses: octokit/request-action@v2.0.26 - if: failure() - with: - route: POST /repos/:repository/deployments/:deployment/statuses - repository: ${{ github.repository }} - deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }} - environment: review - environment_url: http://github-actions-demo-app-${{ github.event.pull_request.number }}.dokku.proxima-web.com - log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} - mediaType: '{"previews": ["ant-man"]}' - state: failure - env: - GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' - destroy_review_app: runs-on: ubuntu-latest # only run when a pull request is closed diff --git a/README.md b/README.md index 644cec9..0a21fbd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,40 @@ # Dokku GitHub Action Example -An example repo showing how to use the official [dokku GitHub action](https://github.com/dokku/github-action) to deploy your app with continuous delivery. +How to use the official [dokku GitHub action](https://github.com/dokku/github-action) to deploy your app using continuous delivery with GitHub Actions and GitHub Deploys. + +GitHub Deploys is still in public beta but it's stablish and is a useful mechanism to manage your deployment workflows. You can use [environment protection rules](https://docs.github.com/en/actions/reference/environments#environment-protection-rules) to give you granular control over [who can deploy](https://docs.github.com/en/actions/managing-workflow-runs/reviewing-deployments) and to where. + +## Workflows + +This repository demonstrates how to: + +- Deploy `review` apps to a `review` environment when a pull request is created or updated. +- Deploy a `production` app to a `production` environment on changes to the main/master branch. No deployment review is required. + +### Review Apps + +Each time a pull request is opened or updated a new review app is deployed. The review app will be deployed to url `http://github-actions-demo-app-${{ github.event.pull_request.number }}.dokku.proxima-web.com`. + +You'll need to create the following following environments in the repository settings: + +- production +- review + +Take advantage of the [environment protection rules](https://docs.github.com/en/actions/reference/environments#environment-protection-rules) to enable deploy restrictions. + +#### Screenshots + +Pull request created, but deploy is awaiting approval: + +GitHub Actions deploy workflow awaiting approval: + +Approving the deploy workflow: + +Deployment in progress: + +Deployment successful: + + ## GitHub Secrets @@ -29,11 +63,5 @@ Visit http://github-actions-demo-app.dokku.proxima-web.com/ to confirm the deplo ## Review Apps -Each time a pull request is opened a new review app is deployed. - -The [example workflow](./.github/workflows/review-app.yml) uses [GitHub Deploys](https://docs.github.com/en/rest/reference/repos#deployments) and requires the following [environments](https://docs.github.com/en/actions/reference/environments) to be created: -- production -- review -You can add new environments in your repo settings. You can also take advantage of [environment protection rules](https://docs.github.com/en/actions/reference/environments#environment-protection-rules) to request reviews before deployments can take place. diff --git a/html/index.html b/html/index.html index a2dc66b..a25b858 100644 --- a/html/index.html +++ b/html/index.html @@ -7,6 +7,6 @@

github-actions-demo-app

-

Version: 1

+

Version: 3