/
ci-tests.ts
executable file
·85 lines (72 loc) · 2.34 KB
/
ci-tests.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
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
#!/usr/bin/env -S ENV_DIR=${PWD}/tests/fixtures node --no-warnings --experimental-specifier-resolution=node --loader ts-node/esm
import { existsSync, symlinkSync } from 'fs'
import { fileURLToPath } from 'url'
import yargs, { Argv } from 'yargs'
import { hf } from './cmd/hf'
import { validateTemplates } from './cmd/validate-templates'
import { validateValues } from './cmd/validate-values'
import { x } from './cmd/x'
import { prepareEnvironment } from './common/setup'
import {
BasicArguments,
getFilename,
getParsedArgs,
OtomiDebugger,
rootDir,
setParsedArgs,
terminal,
} from './common/utils'
import { basicOptions } from './common/yargs-opts'
const cmdName = getFilename(import.meta.url)
const debug: OtomiDebugger = terminal(cmdName)
process.env.CI = '1'
process.env.IN_DOCKER = '1'
export type Arguments = BasicArguments
const setup = (): void => {
process.env.AZURE_CLIENT_ID = 'somevalue'
process.env.AZURE_CLIENT_SECRET = 'somesecret'
}
export const ciTests = async (): Promise<void> => {
const argv: Arguments = getParsedArgs()
if (!existsSync(`${rootDir}/env`)) symlinkSync(`${rootDir}/tests/fixtures`, `${rootDir}/env`)
debug.log(`Running CI tests with values from ${`${rootDir}/tests/fixtures/`}`)
const xCommand = 'opa test policies -v'
debug.info(xCommand)
const opaExitCode = await x({ ...argv, _: ['x', ...xCommand.split(' ')] })
if (opaExitCode !== 0) {
debug.error('Opa policies failed')
process.exit(1)
}
await validateValues()
debug.info('Running hf lint')
await hf({ ...argv, args: ['lint'] })
debug.info('Running validate-templates')
await validateTemplates()
// TODO: checkPolicies is disabled until it works again
// debug.info('Check policies')
// await checkPolicies(argv)
}
export const module = {
command: cmdName,
describe: 'CI tests',
builder: (parser: Argv): Argv => parser,
handler: async (argv: Arguments): Promise<void> => {
setParsedArgs(argv)
await prepareEnvironment({ skipAllPreChecks: true })
setup()
try {
await ciTests()
} catch (error) {
debug.error(error)
process.exit(1)
}
},
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {
await yargs([...process.argv].slice(1))
.scriptName(cmdName)
.option(basicOptions)
.command({ ...module, command: [module.command, '$0'] })
.env('OTOMI')
.parseAsync()
}