-
Notifications
You must be signed in to change notification settings - Fork 6
81 lines (80 loc) · 2.63 KB
/
createDeployment.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
name: CreateDeployment
on:
issue_comment:
type: [created]
jobs:
deploy-check:
runs-on: ubuntu-latest
steps:
- id: check
name: check for deployment command
uses: khan/pull-request-comment-trigger@master
with:
trigger: '/deploy'
reaction: rocket
prefix_only: true
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
outputs:
triggered: ${{ steps.check.outputs.triggered }}
comment_body: ${{ steps.check.outputs.comment_body }}
deployment:
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/request-action@v2.x
with:
route: GET /repos/:repository/pulls/:issue_id
repository: ${{ github.repository }}
issue_id: ${{ github.event.issue.number }}
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- name: get environment
run: |
commit=$COMMENT_BODY
echo "commit message is: $commit"
environment=cicd
case "$commit" in
*dev1*)
environment=dev1
;;
*test*)
environment=test
;;
**)
echo "unknown environment. defaulting to cicd"
environment=cicd
esac
echo environment=$environment
echo DEPLOY_ENVIRONMENT=$environment >> $GITHUB_ENV
env:
COMMENT_BODY: ${{ github.event.comment.body }}
- name: create deployment
id: create_deployment
uses: octokit/request-action@v2.x
with:
route: POST /repos/:repository/deployments
repository: ${{ github.repository }}
ref: ${{ fromJson(steps.get_pull_request_ref.outputs.data).head.ref }}
environment: ${{ env.DEPLOY_ENVIRONMENT }}
auto_merge: false
required_contexts: '[]'
payload: |
prNumber: ${{ github.event.issue.number }}
prName: ${{ fromJson(steps.get_pull_request_ref.outputs.data).head.ref }}
env:
GITHUB_TOKEN: '${{ secrets.GH_TOKEN }}'
- name: write failed comment on failure
id: failed_deployment
uses: octokit/request-action@v2.x
if: failure()
with:
route: PATCH /repos/:repository/issues/comments/:comment_id
repository: ${{ github.repository }}
comment_id: ${{ github.event.comment.id }}
body: 'Failed to create deployment'
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'