forked from DevExpress/testcafe
-
Notifications
You must be signed in to change notification settings - Fork 1
215 lines (199 loc) · 7.73 KB
/
deploy-to-artifacts.yml
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: Deploy To Artifacts
on:
workflow_dispatch:
inputs:
sha:
description: 'The commit ref or SHA'
required: true
default: 'master'
merged_sha:
description: 'The merge commit SHA'
base_sha:
description: 'The base commit SHA'
jobs:
build:
runs-on: ubuntu-latest
outputs:
sha: ${{steps.prep.outputs.sha}}
steps:
- name: Build Info
run: |
echo "SHA: ${{ github.event.inputs.sha }}"
echo "Merged SHA: ${{ github.event.inputs.merged_sha }}"
echo "Deployment run ID: ${{ github.run_id }}"
- uses: actions/github-script@v3
with:
github-token: ${{secrets.ACTIVE_TOKEN}}
script: |
await github.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.inputs.sha,
context: context.workflow,
state: 'pending',
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
});
- id: prep
uses: actions/github-script@v3
with:
github-token: ${{ secrets.ACTIVE_TOKEN }}
script: |
core.setOutput('sha', context.payload.inputs.merged_sha || context.payload.inputs.sha);
- uses: actions/checkout@v2
with:
ref: ${{steps.prep.outputs.sha}}
- run: |
npm i
npx gulp build
npm pack
- id: package-name
uses: actions/github-script@v3
with:
script: |
const { name, version } = require(require('path').join(process.env.GITHUB_WORKSPACE, 'package.json'));
core.setOutput('packageName', `${name}-${version}`);
core.setOutput('imageName', `${name}/${name}:${version}`);
- uses: actions/upload-artifact@v2
with:
name: npm
path: |
${{steps.package-name.outputs.packageName}}.tgz
package-lock.json
- run: |
npx gulp docker-build
docker save -o ${{steps.package-name.outputs.packageName}}.tar ${{steps.package-name.outputs.imageName}}
- uses: actions/upload-artifact@v2
with:
name: docker
path: ${{steps.package-name.outputs.packageName}}.tar
- uses: actions/github-script@v3
if: failure() || cancelled()
with:
github-token: ${{secrets.ACTIVE_TOKEN}}
script: |
await github.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.inputs.sha,
context: context.workflow,
state: 'failure',
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
});
changes:
# TODO: currently cannot generate a list of changes after rebase
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v3
with:
github-token: ${{secrets.ACTIVE_TOKEN}}
script: |
await github.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.inputs.sha,
context: context.workflow,
state: 'pending',
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
});
- uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.sha }}
fetch-depth: 0
- run: |
git reset --soft `git merge-base "${{github.event.inputs.base_sha}}" HEAD`
git diff --name-only --cached > changes.txt
- uses: actions/upload-artifact@v2
with:
name: changes
path: changes.txt
- uses: actions/github-script@v3
if: failure() || cancelled()
with:
github-token: ${{secrets.ACTIVE_TOKEN}}
script: |
await github.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.inputs.sha,
context: context.workflow,
state: 'failure',
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
});
test:
runs-on: ubuntu-latest
needs: [build, changes]
environment: CI
steps:
- uses: actions/download-artifact@v2
with:
name: changes
- uses: actions/github-script@v3
with:
github-token: ${{secrets.ACTIVE_TOKEN}}
script: |
function getInputs () {
const { sha, merged_sha } = context.payload.inputs;
return {
...merged_sha ? { merged_sha } : {},
sha,
deploy_run_id: '${{github.run_id}}'
}
}
async function dispatchWorkflow (workflowName) {
await github.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'master',
workflow_id: workflowName,
inputs: getInputs()
});
}
// TODO: Optimize by running only necessary tests for corresponding changes
const fileList = require('fs').readFileSync('changes.txt').toString().split('\n').filter(line => line);
const tasks = [];
tasks.push('test-client-desktop.yml');
tasks.push('test-client-mobile.yml');
tasks.push('test-functional-docker.yml');
tasks.push('test-functional-local-chrome.yml');
tasks.push('test-functional-local-esm.yml');
tasks.push('test-functional-local-debug-1.yml');
tasks.push('test-functional-local-debug-2.yml');
tasks.push('test-functional-local-firefox.yml');
tasks.push('test-functional-local-multiple-windows.yml');
tasks.push('test-functional-local-proxyless.yml');
tasks.push('test-functional-local-headed-browsers.yml');
tasks.push('test-functional-local-legacy.yml');
tasks.push('test-functional-local-safari.yml');
tasks.push('test-functional-remote-macos.yml');
tasks.push('test-functional-remote-mobile.yml');
tasks.push('test-server-docker.yml');
tasks.push('test-server-lts.yml');
tasks.push('test-server-stable.yml');
// Temporary disable
// tasks.push('test-cdp.yml');
await Promise.all(tasks.map(task => dispatchWorkflow(task)));
- uses: actions/github-script@v3
with:
github-token: ${{secrets.ACTIVE_TOKEN}}
script: |
await github.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.inputs.sha,
context: context.workflow,
state: 'success',
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}#artifacts`
});
- uses: actions/github-script@v3
if: failure() || cancelled()
with:
github-token: ${{secrets.ACTIVE_TOKEN}}
script: |
await github.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.inputs.sha,
context: context.workflow,
state: 'failure',
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
});