-
Notifications
You must be signed in to change notification settings - Fork 2
116 lines (107 loc) · 4.32 KB
/
test-deploy.yaml
File metadata and controls
116 lines (107 loc) · 4.32 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: Deploy PR
on:
pull_request_target:
types: [ labeled, closed ]
jobs:
find-old-deployments:
name: Get deployments for this PR
runs-on: ubuntu-latest
outputs:
items: ${{ steps.list_deployments.outputs.data }}
steps:
- name: list deployments
id: list_deployments
uses: octokit/request-action@v2.x
with:
route: GET /repos/:repository/deployments
repository: ${{ github.repository }}
task: 'pr${{ github.event.pull_request.number }}'
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
delete-old-deployments:
name: Inactivate deployment
runs-on: ubuntu-latest
needs:
- find-old-deployments
if: fromJSON(needs.find-old-deployments.outputs.items)[0] != null
strategy:
fail-fast: false
matrix:
item: ${{ fromJSON(needs.find-old-deployments.outputs.items) }}
steps:
- name: set deployments inactive
id: inactivate_deployments
uses: octokit/request-action@v2.x
with:
route: POST /repos/:repository/deployments/:deployment_id/statuses
repository: ${{ github.repository }}
deployment_id: ${{ matrix.item.id }}
state: inactive
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
create-deployment:
name: Create new deployment
runs-on: ubuntu-latest
needs:
- delete-old-deployments
if: ${{ always() && github.event.action == 'labeled' && github.event.pull_request.state == 'open' && contains(fromJson('["success", "error", "failure"]'),github.event.label.name)}}
steps:
- name: create deployment
id: create_deployment
uses: octokit/request-action@v2.x
with:
route: POST /repos/:repository/deployments
repository: ${{ github.repository }}
ref: ${{ github.event.pull_request.head.sha }}
environment: testing_env
required_contexts: '[]'
task: 'pr${{ github.event.pull_request.number }}'
transient_environment: true
auto_merge: false
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: set deployment status to in progress
id: in_progress_deployment
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 }}
description: "Deployment in progress"
environment: testing_env
auto_inactive: false
environment_url: https://pr${{ github.event.pull_request.number }}.ecamp3.ch/
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: in_progress
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Sleep for 10 seconds
run: sleep 10s
- name: set deployment status to ${{github.event.label.name}}
id: finish_deployment
if: ${{ contains(github.event.pull_request.labels.*.name, github.event.label.name) }}
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 }}
description: "Deployment finished"
environment: testing_env
auto_inactive: false
environment_url: https://pr${{ github.event.pull_request.number }}.ecamp3.ch/
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: ${{ github.event.label.name }}
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: remove ${{github.event.label.name}} deployment label
id: label_remove_error
if: ${{ always() && contains(github.event.pull_request.labels.*.name, github.event.label.name ) }}
uses: octokit/request-action@v2.x
continue-on-error: true
with:
route: DELETE /repos/:repository/issues/:pull_number/labels/:name
repository: ${{ github.repository }}
pull_number: ${{ github.event.pull_request.number }}
name: ${{ github.event.label.name }}
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"