-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
verifyConditions.ts
36 lines (32 loc) · 1.07 KB
/
verifyConditions.ts
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
import SemanticReleaseError from '@semantic-release/error';
import { execa } from 'execa';
import { VerifyConditionsContext } from 'semantic-release';
import { PluginConfig } from './types.js';
import { getConfig, getGoogleIdentityToken } from './utils.js';
export const verifyConditions = async (
pluginConfig: PluginConfig,
{ logger }: VerifyConditionsContext
) => {
const { cli, publishPub } = getConfig(pluginConfig);
const { GOOGLE_SERVICE_ACCOUNT_KEY } = process.env;
if (publishPub) {
if (!GOOGLE_SERVICE_ACCOUNT_KEY) {
throw new SemanticReleaseError(
'Environment variable not found: GOOGLE_SERVICE_ACCOUNT_KEY'
);
}
await getGoogleIdentityToken(GOOGLE_SERVICE_ACCOUNT_KEY);
await verifyCommand(cli);
} else {
logger.log(
`Skipping Google service account key and ${cli} CLI verification as publishPub is ${publishPub}`
);
}
};
const verifyCommand = async (command: string) => {
try {
await execa(command);
} catch (error) {
throw new SemanticReleaseError(`${command} returned an error: ${error}`);
}
};