-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrelease-pkgs-next.js
116 lines (98 loc) · 3.5 KB
/
release-pkgs-next.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env node
/**
* Custom release script for semantic-release (pkgs packages only) on the next branch
* This script handles the packages in pkgs directory with independent versioning
* and publishes them with the next dist-tag
*/
import { execSync } from 'child_process'
import path from 'path'
import fs from 'fs'
const DRY_RUN = process.argv.includes('--dry-run')
console.log(`Running pkgs-only next release script in ${DRY_RUN ? 'dry run' : 'release'} mode`)
const getPackagePaths = () => {
const pkgPaths = []
const pkgsDir = path.resolve(process.cwd(), 'pkgs')
if (fs.existsSync(pkgsDir)) {
const pkgDirs = fs.readdirSync(pkgsDir)
for (const dir of pkgDirs) {
const fullPath = path.join(pkgsDir, dir)
if (fs.statSync(fullPath).isDirectory() && fs.existsSync(path.join(fullPath, 'package.json'))) {
pkgPaths.push(fullPath)
}
}
}
return pkgPaths
}
const runSemanticRelease = (packagePath) => {
const packageJson = JSON.parse(fs.readFileSync(path.join(packagePath, 'package.json'), 'utf8'))
if (packageJson.private) {
console.log(`Skipping private package: ${packageJson.name}`)
return
}
console.log(`Processing package: ${packageJson.name}`)
try {
const tempConfigPath = path.resolve(process.cwd(), 'temp-semantic-release-config.cjs')
const configContent = `
module.exports = {
branches: [
{name: 'next', prerelease: 'next', channel: 'next'}
],
ignorePrivatePackages: true,
repositoryUrl: 'https://github.com/drivly/ai.git',
tagFormat: '\${name}@\${version}',
plugins: [
['@semantic-release/commit-analyzer', {
preset: 'angular',
releaseRules: [
{type: 'feat', release: 'patch'},
{type: 'fix', release: 'patch'},
{type: 'docs', release: 'patch'},
{type: 'style', release: 'patch'},
{type: 'refactor', release: 'patch'},
{type: 'perf', release: 'patch'},
{type: 'test', release: 'patch'},
{type: 'build', release: 'patch'},
{type: 'ci', release: 'patch'},
{type: 'chore', release: 'patch'}
]
}],
'@semantic-release/release-notes-generator',
['@semantic-release/npm', {
npmPublish: true,
pkgRoot: '.',
npmTag: 'next'
}],
'@semantic-release/github'
]
};
`
fs.writeFileSync(tempConfigPath, configContent, 'utf8')
const cmd = `npx semantic-release ${DRY_RUN ? '--dry-run' : ''} --extends=${tempConfigPath}`
console.log(`Running: ${cmd} in ${packagePath}`)
if (!DRY_RUN) {
execSync(cmd, {
cwd: packagePath,
stdio: 'inherit',
env: {
...process.env,
FORCE_PATCH_RELEASE: 'true',
},
})
if (fs.existsSync(tempConfigPath)) {
fs.unlinkSync(tempConfigPath)
}
} else {
console.log(`[DRY RUN] Would run semantic-release in ${packagePath}`)
}
} catch (error) {
console.error(`Error processing ${packageJson.name}:`, error.message)
}
}
const packagePaths = getPackagePaths()
console.log(`Found ${packagePaths.length} packages to process`)
const otherPaths = packagePaths.filter((p) => !p.includes('/sdks/'))
console.log(`Processing ${otherPaths.length} other packages with independent versioning`)
for (const pkgPath of otherPaths) {
runSemanticRelease(pkgPath)
}
console.log('Package release process completed')