-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: add example with github deployments #7
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you turn this into appname.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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are flash and ant-man? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's totally weird when you first see it 😆 As GitHub deploys is still in beta/preview these media types are required to set certain properties. From the docs:
And:
|
||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Steps will only run when previous steps are successful so no need to specify |
||
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 }}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to change the environment based on whether its a PR or not? Might be good to make this whole example something that uses review-apps when not master as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll see what I can do 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've setup an example repo to play with the workflow for review apps, see badsyntax/dokku-github-actions-demo#4
The problem with using environments for review apps is you can only have one deployment per environment. So this needs some more thought. I'm still looking into this and I'll update this PR if/when I can find a solution for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs mention:
So this could be the solution, although when i tried this without the environment existing, i was getting 404's, but I could have been missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another approach is to use 1 environment (eg
review
) and setauto_inactive
to false to keep existing deploys active. https://docs.github.com/en/rest/reference/repos#inactive-deploymentsI like this approach more than creating new environments "on the fly" as it means we can utilise the environment deploy rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made some good progress with this and GitHub Deploys are pretty awesome! We can use GitHub Deploys to request reviews before deployment, which is especially useful for review apps, as we might not want a deploy on every PR (as this open for abuse for public repos).
I'm getting close to updating this PR.