forked from testdriverai/quickstart-web
-
Notifications
You must be signed in to change notification settings - Fork 3
174 lines (158 loc) · 5.32 KB
/
generate.yml
File metadata and controls
174 lines (158 loc) · 5.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
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
name: Main Workflow
permissions:
actions: write
contents: write
statuses: write
pull-requests: write
on:
workflow_dispatch:
inputs:
dispatchId:
type: string
depth:
type: number
default: 1
max-depth:
type: number
default: 1
website-url:
type: string
required: true
previous-file:
type: string
description: Previous test yaml file to use as a base
login_username:
type: string
description: Username
login_password:
type: string
description: Username
workflow_call:
inputs:
dispatchId:
type: string
depth:
type: number
default: 1
max-depth:
type: number
default: 1
website-url:
type: string
required: true
previous-file:
type: string
description: Previous test yaml file to use as a base
login_username:
type: string
description: Username
login_password:
type: string
description: Username
secrets:
TESTDRIVER_API_KEY:
required: true
GH_TOKEN:
required: true
jobs:
match-dispatchId:
if: ${{ inputs.dispatchId }}
runs-on: [ubuntu-latest]
steps:
- id: dispatch-id
name: dispatchId:${{ inputs.dispatchId }}
run: echo "💁 The dispatch ID is ${{ github.event.inputs.dispatchId }}"
- name: Mask secret
run: echo "::add-mask::${{ inputs.login_password }}"
generate-exploratory:
needs: match-dispatchId
uses: ./.github/workflows/generate-exploratory.yml
with:
depth: ${{ fromJson(inputs.depth) }}
max-depth: ${{ fromJson(inputs.max-depth) }}
website-url: ${{ inputs.website-url }}
base-branch: ${{ github.ref_name }}
previous-file: ${{ inputs.previous-file }}
secrets:
TESTDRIVER_API_KEY: ${{ secrets.TESTDRIVER_API_KEY }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LOGIN_USERNAME: ${{ inputs.login_username }}
LOGIN_PASSWORD: ${{ inputs.login_password }}
generate-regression:
needs: generate-exploratory
uses: ./.github/workflows/generate-regressions.yml
with:
depth: ${{ fromJson(inputs.depth) }}
max-depth: ${{ fromJson(inputs.max-depth) }}
website-url: ${{ inputs.website-url }}
base-branch: ${{ needs.generate-exploratory.outputs.pr-branch }}
secrets:
TESTDRIVER_API_KEY: ${{ secrets.TESTDRIVER_API_KEY }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LOGIN_USERNAME: ${{ inputs.login_username }}
LOGIN_PASSWORD: ${{ inputs.login_password }}
generate-next-depth:
if: ${{inputs.depth != inputs.max-depth}}
name: Trigger Next Level
needs: generate-regression
runs-on: ubuntu-latest
steps:
- name: Trigger Next Depth of Workflows
if: ${{ inputs.depth != inputs.max-depth }}
uses: actions/github-script@v6
env:
RESULTS: ${{ needs.generate-regression.outputs.results }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const results = [];
for (const item of JSON.parse(process.env.RESULTS)) {
// Check if branch exists
const branchExists = await github.rest.repos.getBranch({
owner: context.repo.owner,
repo: context.repo.repo,
branch: item.branch
})
.then(()=>true)
.catch(()=>false)
console.log(context.repo.owner);
console.log(context.repo.repo);
console.log(item.branch);
if(!branchExists) {
console.log(`Branch ${item.branch} does not exist, skipping workflow dispatch`);
continue
}
const dispatchId = Math.random().toString(36).substring(2, 15);
// Branch exists, dispatch workflow
const response = await fetch(`https://api.github.com/repos/${context.repo.owner}/${context.repo.repo}/actions/workflows/generate.yml/dispatches`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.TOKEN ?? github.token}`,
'Accept': 'application/vnd.github.v3+json'
},
body: JSON.stringify({
ref: item.branch,
inputs: {
"dispatchId": dispatchId,
"depth": "" + (${{ inputs.depth }} + 1),
"max-depth": "" + ${{ inputs.max-depth }},
"previous-file": item.filename,
"website-url": "${{ inputs.website-url }}",
}
})
});
console.log("----------------------------------")
console.log(response.status, await response.text());
console.log(`Dispatched workflow for branch: ${item.branch}`);
results.push({
...item,
dispatchId: dispatchId
});
}
require('fs').writeFileSync('results.json', JSON.stringify(results, null, 2));
- name: Upload Results
uses: actions/upload-artifact@v4
with:
name: results.json
path: results.json