generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.ts
66 lines (60 loc) · 1.69 KB
/
main.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
import * as core from '@actions/core'
import { exec } from './exec'
import path from 'path'
import fs from 'fs/promises'
import { uploadPackageJS } from './upload'
import { glob, globSync, globStream, globStreamSync, Glob } from 'glob'
/**
* The main function for the action.
* @returns {Promise<void>} Resolves when the action is complete.
*/
export async function run(): Promise<void> {
try {
const needPublish = core.getInput('publish')
if (needPublish) {
const tag = await getPublishTag()
core.debug(`publish tag is ${tag}`)
const stdout = await exec(`pnpm publish -r --tag ${tag} --no-git-checks`)
core.info(stdout)
}
const packages = core.getMultilineInput('packages')
const cwd = process.cwd()
if (packages) {
core.debug(`dirs: ${JSON.stringify(packages)}`)
await Promise.all(
packages.map(dir => uploadPackageJS(path.join(cwd, dir)))
)
} else {
const dirs = await fs.readdir(path.join(cwd, 'packages'))
core.debug(`dirs: ${JSON.stringify(dirs)}`)
await Promise.all(
dirs.map(dir => uploadPackageJS(path.join(cwd, 'packages', dir)))
)
}
} catch (error) {
core.error(JSON.stringify(error))
core.setFailed(error)
}
}
async function getPublishTag() {
try {
const pkg = JSON.parse(
await fs.readFile(path.join(process.cwd(), 'package.json'), {
encoding: 'utf-8'
})
)
const version = pkg.version
core.debug(`current version: ${version}`)
if (!version) {
return 'latest'
}
const match = version.match(/-(\w+)\./)
if (match) {
return match[1]
} else {
return 'latest'
}
} catch (e) {
core.setFailed(e)
}
}