generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 21
/
main.ts
70 lines (60 loc) · 2.44 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
67
68
69
70
import {getInput, info, setFailed, warning} from '@actions/core'
import {ExecOptions, exec} from '@actions/exec'
import {checkPackages, findPackages, sortPackages} from './package'
import {awaitCrateVersion} from './crates'
import {githubHandle} from './github'
interface EnvVars {
[name: string]: string
}
async function run(): Promise<void> {
const token = getInput('token')
const path = getInput('path')
const args = getInput('args')
.split(/[\n\s]+/)
.filter(arg => arg.length > 0)
const registry_token = getInput('registry-token')
const dry_run = getInput('dry-run') === 'true'
const env: EnvVars = {...(process.env as EnvVars)}
if (registry_token) {
env.CARGO_REGISTRY_TOKEN = registry_token
}
const github = githubHandle(token)
try {
info(`Searching cargo packages at '${path}'`)
const packages = await findPackages(path)
const package_names = Object.keys(packages).join(', ')
info(`Found packages: ${package_names}`)
info(`Checking packages consistency`)
await checkPackages(packages, github)
info(`Sorting packages according dependencies`)
const sorted_packages = sortPackages(packages)
for (const package_name of sorted_packages) {
const package_info = packages[package_name]
if (!package_info.published) {
const exec_args = ['publish', ...args]
const exec_opts: ExecOptions = {
cwd: package_info.path,
env
}
if (dry_run) {
const args_str = exec_args.join(' ')
warning(
`Skipping exec 'cargo ${args_str}' in '${package_info.path}' due to 'dry-run: true'`
)
warning(
`Skipping awaiting when '${package_name} ${package_info.version}' will be available due to 'dry-run: true'`
)
} else {
info(`Publishing package '${package_name}'`)
await exec('cargo', exec_args, exec_opts)
await awaitCrateVersion(package_name, package_info.version)
await exec('cargo', ['update'], exec_opts)
info(`Package '${package_name}' published successfully`)
}
}
}
} catch (error) {
setFailed(error.message)
}
}
run()