-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathvalidate-stable-release.ts
More file actions
41 lines (38 loc) · 1.17 KB
/
validate-stable-release.ts
File metadata and controls
41 lines (38 loc) · 1.17 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
import type { AsyncFunctionArguments } from 'github-script';
/**
* 1. Validate input version.
* 2. Check if given tag/release is already promoted to stable. If so, crash.
*/
export default async ({ github, context }: AsyncFunctionArguments) => {
if (context.ref !== 'refs/heads/main') {
throw new Error('This action only works on main branch');
}
const { owner, repo } = context.repo;
const previewVersionTag = process.env.INPUT_VERSION;
if (!previewVersionTag) {
throw new Error('Missing env.INPUT_VERSION');
}
if (!previewVersionTag.match(/^v[0-9]+\.[0-9]+\.[0-9]+-preview$/)) {
throw new Error('Input "version" must match vX.X.X-preview');
}
const versionTag = previewVersionTag.replace('-preview', '');
try {
await github.rest.repos.getReleaseByTag({
owner,
repo,
tag: versionTag,
});
throw new Error('Release already promoted to stable');
} catch (error) {
if (!('status' in error) || typeof error.status !== 'number') {
throw error;
}
if (error.status === 404) {
// do nothing
} else {
throw new Error(`Failed to check: HTTP ${error.status}`, {
cause: error,
});
}
}
};