-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Expand file tree
/
Copy pathset-preview-version.js
More file actions
65 lines (57 loc) · 1.8 KB
/
Copy pathset-preview-version.js
File metadata and controls
65 lines (57 loc) · 1.8 KB
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
// @ts-check
const execa = require('execa')
const fs = require('node:fs/promises')
const path = require('node:path')
async function main() {
const [githubSha] = process.argv.slice(2)
if (!githubSha) {
throw new Error('Usage: set-preview-version.js <githubSha>')
}
const repoRoot = path.resolve(__dirname, '..')
const [{ stdout: shortSha }, { stdout: dateString }] = await Promise.all([
execa('git', ['rev-parse', '--short', githubSha]),
// Source: https://github.com/facebook/react/blob/767f52237cf7892ad07726f21e3e8bacfc8af839/scripts/release/utils.js#L114
execa('git', [
'show',
'-s',
'--no-show-signature',
'--format=%cd',
'--date=format:%Y%m%d',
githubSha,
]),
])
const lernaConfigPath = path.join(repoRoot, 'lerna.json')
const lernaConfig = JSON.parse(await fs.readFile(lernaConfigPath, 'utf8'))
// 15.0.0-canary.17 -> 15.0.0
// 15.0.0 -> 15.0.0
const [semverStableVersion] = lernaConfig.version.split('-')
// This can create colliding versions between different forks which should be incredibly rare.
// Preview builds are installed by URL anyway which is unique between forks by
// controlling the repo var setting the preview builds base url.
const version = `${semverStableVersion}-preview-${shortSha}-${dateString}`
//
// Lerna version requires a non-detached HEAD
await execa('git', ['checkout', '-B', `preview/${shortSha}`, githubSha], {
cwd: repoRoot,
stdio: 'inherit',
})
await execa(
'pnpm',
[
'lerna',
'version',
version,
'--no-git-tag-version',
'--no-push',
'--allow-branch',
'**',
'--yes',
],
{ cwd: repoRoot, stdio: 'inherit' }
)
console.info(`Set preview version: ${version}`)
}
main().catch((err) => {
console.error(err)
process.exit(1)
})