forked from getsentry/sentry
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetsentry-dispatch.js
More file actions
96 lines (86 loc) · 2.76 KB
/
getsentry-dispatch.js
File metadata and controls
96 lines (86 loc) · 2.76 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
/**
* List of workflows to dispatch to `getsentry`
*
* `pathFilterName` refers to the path filters in `.github/file-filters.yml` (`getsentry/paths-filter` action)
*
* TODO(billy): Refactor workflow files to be an enum so that we can integration test them. Otherwise if they are
* deleted/renamed in `getsentry`, this will fail
*/
const DISPATCHES = [
{
workflow: 'backend.yml',
pathFilterName: 'backend_all',
},
{
workflow: 'acceptance.yml',
pathFilterName: 'gsapp',
},
];
const RETRY_DELAYS_MS = [5000, 15000, 30000, 60000];
async function dispatchWithRetry({github, core, workflow, inputs}) {
const maxAttempts = RETRY_DELAYS_MS.length + 1;
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try {
await github.rest.actions.createWorkflowDispatch({
owner: 'getsentry',
repo: 'getsentry',
workflow_id: workflow,
ref: 'master',
inputs,
});
return;
} catch (err) {
if (attempt === maxAttempts) {
throw err;
}
const delay = RETRY_DELAYS_MS[attempt - 1];
core.warning(
`Dispatch for '${workflow}' failed (attempt ${attempt}/${maxAttempts}): ${err.message}. Retrying in ${delay / 1000}s...`
);
await new Promise(resolve => setTimeout(resolve, delay));
}
}
}
export async function dispatch({
github,
context,
core,
fileChanges,
mergeCommitSha,
sentryChangedFiles,
sentryPreviousFilenames,
targetWorkflow,
}) {
core.startGroup('Dispatching request to getsentry.');
const dispatches =
targetWorkflow !== undefined
? [
{
workflow: targetWorkflow,
pathFilterName:
DISPATCHES.find(d => d.workflow === targetWorkflow)?.pathFilterName ??
'backend_all',
},
]
: DISPATCHES;
await Promise.all(
dispatches.map(({workflow, pathFilterName}) => {
const inputs = {
pull_request_number: `${context.payload.pull_request.number}`, // needs to be string
skip: `${fileChanges[pathFilterName] !== 'true'}`, // even though this is a boolean, it must be cast to a string
// sentrySHA is the sha getsentry should run against.
'sentry-sha': mergeCommitSha,
// prSHA is the sha actions should post commit statuses too.
'sentry-pr-sha': context.payload.pull_request.head.sha,
// Changed files for selective testing. Empty string means full suite.
'sentry-changed-files': sentryChangedFiles || '',
'sentry-previous-filenames': sentryPreviousFilenames || '',
};
core.info(
`Sending dispatch for '${workflow}':\n${JSON.stringify(inputs, null, 2)}`
);
return dispatchWithRetry({github, core, workflow, inputs});
})
);
core.endGroup();
}