-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.ts
87 lines (68 loc) · 2.38 KB
/
release.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
86
87
import Bun from 'bun'
import path from 'path'
import { exit } from 'process'
// import * as u from "./";
import { deploy, npm } from 'index'
import { ulog } from './utils/ulog'
// run bun test
const testProc = Bun.spawnSync(['bun', 'test', '--coverage'], {})
const output = await deploy.logStdOutput(testProc)
if (!output) {
ulog('No output')
exit(1)
}
const NPM_TOKEN = Bun.env.NPM_TOKEN || ''
const MAX_RETRIES = Number(Bun.env.MAX_PUBLISH_RETRY) || 10 // Define a max number of retries to prevent infinite loops
const e = Bun.env
const { commitAndPush, setupGitConfig, actionsEnv } = deploy.createGitHubActionsFactory({
sshRepoUrl: 'git@github.com:brandon-schabel/bun-nook-kit.git',
})
const isBeta = actionsEnv.branch === 'main'
const isRelease = actionsEnv.branch === 'release'
const isAlpha = actionsEnv.eventName === 'pull_request'
const isLocalRun = Bun.env.LOCAL_RUN === 'true'
const { npmPublish, setupNpmAuth, updatePackageVersion } = npm.npmReleaseFactory({
maxRetries: MAX_RETRIES,
npmToken: NPM_TOKEN,
})
const corePackagePath = path.resolve(process.cwd(), 'package.json')
// todo resolve all plugin paths
const pluginReactPath = path.resolve(process.cwd(), 'plugins', 'react', 'package.json')
const pluginReactServerPath = path.resolve(process.cwd(), 'plugins', 'react-server', 'package.json')
ulog({
actor: e?.GITHUB_ACTOR,
job: e?.GITHUB_JOB,
refType: e?.GITHUB_REF_TYPE,
runner: e?.RUNNER_NAME,
gitHubAction: e.GITHUB_ACTION,
runNumber: e.GITHUB_RUN_NUMBER,
runnerEnv: e?.RUNNNER_ENVIRONMENT,
eventName: e?.GITHUB_EVENT_NAME,
isLocalRun,
isAlpha,
corePackagePath,
pluginReactPath,
})
/* Script */
if (!isLocalRun) {
setupNpmAuth()
await setupGitConfig()
}
ulog(`Updating versions to ${isAlpha ? 'alpha' : 'Release'}`)
const newVersion = await updatePackageVersion({
packagePath: corePackagePath,
isAlpha: actionsEnv.eventName === 'pull_request',
isBeta: actionsEnv.eventName === 'push',
})
await npmPublish({ packagePath: corePackagePath, isAlpha, isBeta })
await updatePackageVersion({ packagePath: pluginReactPath, isAlpha, isBeta })
await npmPublish({ packagePath: pluginReactPath, isAlpha, isBeta })
await updatePackageVersion({
packagePath: pluginReactServerPath,
isAlpha,
isBeta,
})
await npmPublish({ packagePath: pluginReactServerPath, isAlpha, isBeta })
if (!isLocalRun && !isAlpha) {
await commitAndPush(`Pushing version: ${newVersion}`)
}