-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a5d0895
Showing
2 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
name: pr-deployment | ||
|
||
on: | ||
issue_comment: | ||
types: [created] | ||
|
||
jobs: | ||
deploy-check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: acknowledge deployment request to commenter | ||
id: check | ||
uses: khan/pull-request-comment-trigger@master | ||
with: | ||
trigger: "/deploy" | ||
reaction: rocket | ||
env: | ||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||
outputs: | ||
triggered: ${{ steps.check.outputs.triggered }} | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: deploy-check | ||
if: needs.deploy-check.outputs.triggered == 'true' | ||
steps: | ||
- name: get pull request ref | ||
id: get_pull_request_ref | ||
uses: octokit/[email protected] | ||
with: | ||
route: GET /repos/:repository/pulls/:issue_id | ||
repository: ${{ github.repository }} | ||
issue_id: ${{ github.event.issue.number }} | ||
env: | ||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||
|
||
- name: create deployment | ||
id: create_deployment | ||
uses: octokit/[email protected] | ||
with: | ||
route: POST /repos/:repository/deployments | ||
repository: ${{ github.repository }} | ||
ref: ${{ fromJson(steps.get_pull_request_ref.outputs.data).head.ref }} | ||
environment: dev | ||
auto_merge: false | ||
env: | ||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||
|
||
- name: set deployment status to in progress | ||
id: start_deployment | ||
uses: octokit/[email protected] | ||
with: | ||
route: POST /repos/:repository/deployments/:deployment/statuses | ||
repository: ${{ github.repository }} | ||
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }} | ||
environment: dev | ||
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"]}' | ||
env: | ||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||
|
||
- name: deploy the pull request | ||
run: | | ||
# deployment logic goes here | ||
sleep 10 | ||
# instead we randomly succeed or fail the deployment | ||
exit $(( $RANDOM % 10 >= 5 )) | ||
- name: set deployment status to success | ||
id: successful_deployment | ||
uses: octokit/[email protected] | ||
with: | ||
route: POST /repos/:repository/deployments/:deployment/statuses | ||
repository: ${{ github.repository }} | ||
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }} | ||
environment: dev | ||
environment_url: https://example.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 deployment status to failure | ||
id: failed_deployment | ||
uses: octokit/[email protected] | ||
if: failure() | ||
with: | ||
route: POST /repos/:repository/deployments/:deployment/statuses | ||
repository: ${{ github.repository }} | ||
deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }} | ||
environment: dev | ||
environment_url: https://example.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 }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Pull request deployments with GitHub Actions and GitHub Deployments | ||
|
||
The workflow in this repository shows how a `/deploy` comment on a pull request can deploy the source code to an environment. In addition, the user is kept up-to-date on the deployment status using the GitHub Deployments construct. | ||
|
||
More information about this workflow can be found in my blog post: [Deploy your pull requests with GitHub Actions and GitHub Deployments](https://sanderknape.com/2020/05/deploy-pull-requests-github-actions-deployments/) |