-
Notifications
You must be signed in to change notification settings - Fork 7
/
action.js
57 lines (53 loc) · 1.43 KB
/
action.js
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
// @ts-check
const fs = require('fs')
const path = require('path')
const { spawnSync } = require('child_process')
// Duplicate code from action/repository, keep this until
// found a better way to include typescript without transpiles
function runCommand(
/** @type {string[]} */ commands,
/** @type {string} */ cwd
) {
return spawnSync(commands[0], commands.slice(1), {
stdio: 'inherit',
cwd
})
}
function getGithubActionPath() {
const workSpace = process.env['GITHUB_WORKSPACE']
if (!workSpace) {
return ''
}
const actionPath = '/home/runner/work/_actions/llun/feeds'
try {
const files = fs.readdirSync(actionPath)
const version = files.filter((file) => {
const stat = fs.statSync(path.join(actionPath, file))
return stat.isDirectory()
})
return path.join(actionPath, version.pop() || 'main')
} catch (error) {
return path.join(actionPath, 'main')
}
}
// Main
console.log('Action: ', process.env['GITHUB_ACTION'])
if (
process.env['GITHUB_ACTION'] === 'llunfeeds' ||
process.env['GITHUB_ACTION'] === '__llun_feeds'
) {
const dependenciesResult = runCommand(
['yarn', 'install'],
getGithubActionPath()
)
if (dependenciesResult.error) {
throw new Error('Fail to run setup')
}
const executeResult = runCommand(
['node', '-r', '@swc-node/register', 'index.ts'],
getGithubActionPath()
)
if (executeResult.error) {
throw new Error('Fail to site builder')
}
}