infra-kit 0.1.97 → 0.1.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintcache +1 -1
- package/.turbo/turbo-eslint-check.log +4 -5
- package/.turbo/turbo-prettier-check.log +4 -5
- package/.turbo/turbo-test.log +191 -18
- package/.turbo/turbo-ts-check.log +9 -5
- package/dist/cli.js +57 -37
- package/dist/cli.js.map +4 -4
- package/dist/mcp.js +29 -28
- package/dist/mcp.js.map +4 -4
- package/package.json +1 -1
- package/src/commands/config/config.ts +125 -0
- package/src/commands/config/index.ts +1 -0
- package/src/commands/doctor/doctor.ts +27 -18
- package/src/commands/init/init.ts +54 -1
- package/src/commands/release-create/release-create.ts +123 -72
- package/src/commands/release-create-batch/release-create-batch.ts +45 -21
- package/src/entry/cli.ts +26 -5
- package/src/lib/__tests__/infra-kit-config.test.ts +3 -1
- package/src/lib/infra-kit-config/index.ts +2 -2
- package/src/lib/infra-kit-config/infra-kit-config.ts +183 -37
- package/src/lib/version-utils/__tests__/next-version.test.ts +112 -0
- package/src/lib/version-utils/index.ts +11 -0
- package/src/lib/version-utils/load-existing-versions.ts +67 -0
- package/src/lib/version-utils/next-version.ts +148 -0
- package/tsconfig.tsbuildinfo +1 -1
package/src/entry/cli.ts
CHANGED
|
@@ -2,6 +2,7 @@ import select, { Separator } from '@inquirer/select'
|
|
|
2
2
|
import { Command, Option } from 'commander'
|
|
3
3
|
import process from 'node:process'
|
|
4
4
|
|
|
5
|
+
import { configEdit, configPath } from 'src/commands/config'
|
|
5
6
|
import { doctor } from 'src/commands/doctor'
|
|
6
7
|
import { envClear } from 'src/commands/env-clear'
|
|
7
8
|
import { envList } from 'src/commands/env-list'
|
|
@@ -80,25 +81,29 @@ program
|
|
|
80
81
|
program
|
|
81
82
|
.command('release-create')
|
|
82
83
|
.description('Create a single release branch')
|
|
83
|
-
.option(
|
|
84
|
+
.option(
|
|
85
|
+
'-v, --version <version>',
|
|
86
|
+
'Version to create, e.g. "1.2.5", "next", or "next,next,1.2.7" (multi-value routes to batch)',
|
|
87
|
+
)
|
|
84
88
|
.option('-d, --description <description>', 'Optional description for the Jira version')
|
|
85
89
|
.addOption(new Option('-t, --type <type>', 'Release type (default: regular)').choices(['regular', 'hotfix']))
|
|
86
90
|
.option('-y, --yes', 'Skip confirmation prompt')
|
|
87
|
-
.option('--no-checkout', 'Do not checkout the created branch after creation (checkout is default)')
|
|
88
91
|
.action(async (options) => {
|
|
89
92
|
await releaseCreate({
|
|
90
93
|
version: options.version,
|
|
91
94
|
description: options.description,
|
|
92
95
|
type: options.type,
|
|
93
96
|
confirmedCommand: options.yes,
|
|
94
|
-
checkout: options.checkout,
|
|
95
97
|
})
|
|
96
98
|
})
|
|
97
99
|
|
|
98
100
|
program
|
|
99
101
|
.command('release-create-batch')
|
|
100
102
|
.description('Create multiple release branches (batch operation)')
|
|
101
|
-
.option(
|
|
103
|
+
.option(
|
|
104
|
+
'-v, --versions <versions>',
|
|
105
|
+
'Comma-separated versions, e.g. "1.2.5, 1.2.6", "next,next", or "next,next,1.2.7"',
|
|
106
|
+
)
|
|
102
107
|
.addOption(new Option('-t, --type <type>', 'Release type (default: regular)').choices(['regular', 'hotfix']))
|
|
103
108
|
.option('-y, --yes', 'Skip confirmation prompt')
|
|
104
109
|
.action(async (options) => {
|
|
@@ -199,6 +204,22 @@ program
|
|
|
199
204
|
await worktreesOpen()
|
|
200
205
|
})
|
|
201
206
|
|
|
207
|
+
const configCmd = program.command('config').description('Manage infra-kit configuration files')
|
|
208
|
+
|
|
209
|
+
configCmd
|
|
210
|
+
.command('path')
|
|
211
|
+
.description('Show the resolved config merge chain and file paths')
|
|
212
|
+
.action(async () => {
|
|
213
|
+
await configPath()
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
configCmd
|
|
217
|
+
.command('edit')
|
|
218
|
+
.description('Open the user-scope per-project override file in $EDITOR')
|
|
219
|
+
.action(async () => {
|
|
220
|
+
await configEdit()
|
|
221
|
+
})
|
|
222
|
+
|
|
202
223
|
program
|
|
203
224
|
.command('doctor')
|
|
204
225
|
.description('Check installation and authentication status of gh and doppler CLIs')
|
|
@@ -260,7 +281,7 @@ if (process.argv.length <= 2) {
|
|
|
260
281
|
'release-deliver',
|
|
261
282
|
]
|
|
262
283
|
const worktreeCommands = ['worktrees-add', 'worktrees-list', 'worktrees-open', 'worktrees-remove', 'worktrees-sync']
|
|
263
|
-
const envCommands = ['doctor', 'init', 'version', 'env-status', 'env-list', 'env-load', 'env-clear']
|
|
284
|
+
const envCommands = ['doctor', 'init', 'version', 'config', 'env-status', 'env-list', 'env-load', 'env-clear']
|
|
264
285
|
|
|
265
286
|
const commandMap = new Map(
|
|
266
287
|
program.commands.map((cmd) => {
|
|
@@ -4,13 +4,14 @@ import path from 'node:path'
|
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
5
|
|
|
6
6
|
// Import AFTER the mock is declared so the module picks up the mocked dep.
|
|
7
|
-
import { getProjectRoot } from 'src/lib/git-utils'
|
|
7
|
+
import { getProjectRoot, getRepoName } from 'src/lib/git-utils'
|
|
8
8
|
|
|
9
9
|
import { getInfraKitConfig, resetInfraKitConfigCache } from '../infra-kit-config'
|
|
10
10
|
|
|
11
11
|
vi.mock('src/lib/git-utils', () => {
|
|
12
12
|
return {
|
|
13
13
|
getProjectRoot: vi.fn(),
|
|
14
|
+
getRepoName: vi.fn(),
|
|
14
15
|
}
|
|
15
16
|
})
|
|
16
17
|
|
|
@@ -35,6 +36,7 @@ const withTmpRepo = async (fn: (tmp: string) => Promise<void>): Promise<void> =>
|
|
|
35
36
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'infra-kit-config-test-'))
|
|
36
37
|
|
|
37
38
|
vi.mocked(getProjectRoot).mockResolvedValue(tmp)
|
|
39
|
+
vi.mocked(getRepoName).mockResolvedValue(path.basename(tmp))
|
|
38
40
|
resetInfraKitConfigCache()
|
|
39
41
|
|
|
40
42
|
try {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { getInfraKitConfig, resetInfraKitConfigCache } from './infra-kit-config'
|
|
2
|
-
export type { InfraKitConfig } from './infra-kit-config'
|
|
1
|
+
export { getInfraKitConfig, getInfraKitConfigPaths, resetInfraKitConfigCache } from './infra-kit-config'
|
|
2
|
+
export type { InfraKitConfig, InfraKitConfigPaths } from './infra-kit-config'
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import fs from 'node:fs/promises'
|
|
2
|
+
import os from 'node:os'
|
|
2
3
|
import path from 'node:path'
|
|
3
4
|
import yaml from 'yaml'
|
|
4
5
|
import { z } from 'zod/v4'
|
|
5
6
|
|
|
6
|
-
import { getProjectRoot } from 'src/lib/git-utils'
|
|
7
|
+
import { getProjectRoot, getRepoName } from 'src/lib/git-utils'
|
|
7
8
|
|
|
8
9
|
const INFRA_KIT_CONFIG_FILE = 'infra-kit.yml'
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
const USER_CONFIG_DIR_NAME = '.infra-kit'
|
|
12
|
+
const USER_GLOBAL_CONFIG_FILE = 'config.yml'
|
|
13
|
+
const USER_PROJECTS_DIR = 'projects'
|
|
10
14
|
|
|
11
15
|
// envManagement
|
|
12
16
|
const dopplerEnvManagementSchema = z.object({
|
|
@@ -59,81 +63,148 @@ const infraKitConfigSchema = z.object({
|
|
|
59
63
|
taskManager: taskManagerSchema.optional(),
|
|
60
64
|
})
|
|
61
65
|
|
|
62
|
-
const
|
|
66
|
+
const infraKitOverrideConfigSchema = infraKitConfigSchema.partial()
|
|
63
67
|
|
|
64
68
|
export type InfraKitConfig = z.infer<typeof infraKitConfigSchema>
|
|
65
69
|
|
|
70
|
+
export interface InfraKitConfigPaths {
|
|
71
|
+
/** Committed project config (required). */
|
|
72
|
+
main: string
|
|
73
|
+
/** User-scope global overrides applied to every project. */
|
|
74
|
+
userGlobal: string
|
|
75
|
+
/** User-scope per-project overrides — `<userProjectsDir>/<projectName>/infra-kit.yml`. */
|
|
76
|
+
userProject: string
|
|
77
|
+
/** Repo basename (`path.basename(projectRoot)`) used to namespace the user-project file. */
|
|
78
|
+
projectName: string
|
|
79
|
+
}
|
|
80
|
+
|
|
66
81
|
interface CacheEntry {
|
|
67
|
-
|
|
68
|
-
localMtimeMs: number | null
|
|
82
|
+
mtimes: Record<keyof Omit<InfraKitConfigPaths, 'projectName'>, number | null>
|
|
69
83
|
value: InfraKitConfig
|
|
70
84
|
}
|
|
71
85
|
|
|
72
86
|
let cached: CacheEntry | null = null
|
|
73
87
|
|
|
74
88
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
89
|
+
* Resolve every file path that participates in the config merge chain. Always
|
|
90
|
+
* returns paths even for files that don't yet exist, so callers can use them
|
|
91
|
+
* for "where would my override go?" prompts.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* const paths = await getInfraKitConfigPaths()
|
|
95
|
+
* // {
|
|
96
|
+
* // main: '/Users/arthur/projects/api/infra-kit.yml',
|
|
97
|
+
* // userGlobal: '/Users/arthur/.infra-kit/config.yml',
|
|
98
|
+
* // userProject: '/Users/arthur/.infra-kit/projects/api/infra-kit.yml',
|
|
99
|
+
* // projectName: 'api',
|
|
100
|
+
* // }
|
|
80
101
|
*/
|
|
81
|
-
export const
|
|
102
|
+
export const getInfraKitConfigPaths = async (): Promise<InfraKitConfigPaths> => {
|
|
82
103
|
const projectRoot = await getProjectRoot()
|
|
83
|
-
const
|
|
84
|
-
const
|
|
104
|
+
const projectName = await getRepoName()
|
|
105
|
+
const userConfigDir = path.join(os.homedir(), USER_CONFIG_DIR_NAME)
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
main: path.join(projectRoot, INFRA_KIT_CONFIG_FILE),
|
|
109
|
+
userGlobal: path.join(userConfigDir, USER_GLOBAL_CONFIG_FILE),
|
|
110
|
+
userProject: path.join(userConfigDir, USER_PROJECTS_DIR, projectName, INFRA_KIT_CONFIG_FILE),
|
|
111
|
+
projectName,
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Read and validate `infra-kit.yml`, with optional override layers shallow-merged
|
|
117
|
+
* on top in this order (later wins):
|
|
118
|
+
* 1. project `infra-kit.yml` — committed source of truth
|
|
119
|
+
* 2. `~/.infra-kit/config.yml` — user-global defaults
|
|
120
|
+
* 3. `~/.infra-kit/projects/<repo-name>/infra-kit.yml` — user-scope per-project overrides
|
|
121
|
+
*
|
|
122
|
+
* Top-level keys (entire capability sections like `ide`, `envManagement`)
|
|
123
|
+
* replace wholesale. Results are cached per file mtimes so the long-running
|
|
124
|
+
* MCP server picks up edits without a restart.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* // infra-kit.yml: { environments: ['dev'], envManagement: { provider: 'doppler', config: { name: 'p' } } }
|
|
128
|
+
* // ~/.infra-kit/config.yml: { ide: { provider: 'cursor', config: { mode: 'windows' } } }
|
|
129
|
+
* const cfg = await getInfraKitConfig()
|
|
130
|
+
* // => { environments: ['dev'], envManagement: {...}, ide: { provider: 'cursor', config: { mode: 'windows' } } }
|
|
131
|
+
*/
|
|
132
|
+
export const getInfraKitConfig = async (): Promise<InfraKitConfig> => {
|
|
133
|
+
const paths = await getInfraKitConfigPaths()
|
|
85
134
|
|
|
86
135
|
let mainStat: Awaited<ReturnType<typeof fs.stat>>
|
|
87
136
|
|
|
88
137
|
try {
|
|
89
|
-
mainStat = await fs.stat(
|
|
138
|
+
mainStat = await fs.stat(paths.main)
|
|
90
139
|
} catch {
|
|
91
140
|
cached = null
|
|
92
|
-
throw new Error(`infra-kit.yml not found at ${
|
|
141
|
+
throw new Error(`infra-kit.yml not found at ${paths.main}`)
|
|
93
142
|
}
|
|
94
143
|
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
144
|
+
const [userGlobalStat, userProjectStat] = await Promise.all([
|
|
145
|
+
statIfExists(paths.userGlobal),
|
|
146
|
+
statIfExists(paths.userProject),
|
|
147
|
+
])
|
|
98
148
|
|
|
99
|
-
|
|
100
|
-
|
|
149
|
+
const mtimes = {
|
|
150
|
+
main: Number(mainStat.mtimeMs),
|
|
151
|
+
userGlobal: userGlobalStat ? Number(userGlobalStat.mtimeMs) : null,
|
|
152
|
+
userProject: userProjectStat ? Number(userProjectStat.mtimeMs) : null,
|
|
101
153
|
}
|
|
102
154
|
|
|
103
|
-
|
|
104
|
-
|
|
155
|
+
if (cached && shallowEqual(cached.mtimes, mtimes)) {
|
|
156
|
+
return cached.value
|
|
157
|
+
}
|
|
105
158
|
|
|
106
|
-
|
|
159
|
+
const layers: ConfigLayer[] = [
|
|
160
|
+
{ label: 'infra-kit.yml', path: paths.main, required: true },
|
|
161
|
+
{ label: '~/.infra-kit/config.yml', path: paths.userGlobal, required: false },
|
|
162
|
+
{
|
|
163
|
+
label: `~/.infra-kit/projects/${paths.projectName}/infra-kit.yml`,
|
|
164
|
+
path: paths.userProject,
|
|
165
|
+
required: false,
|
|
166
|
+
},
|
|
167
|
+
]
|
|
107
168
|
|
|
108
|
-
|
|
109
|
-
const localRaw = await fs.readFile(localPath, 'utf-8')
|
|
110
|
-
const localParsedRaw = yaml.parse(localRaw) ?? {}
|
|
169
|
+
let merged: Record<string, unknown> = {}
|
|
111
170
|
|
|
112
|
-
|
|
171
|
+
for (const layer of layers) {
|
|
172
|
+
const data = await loadLayer(layer)
|
|
113
173
|
|
|
114
|
-
if (
|
|
115
|
-
throw new Error(`Invalid infra-kit.local.yml at ${localPath}: ${z.prettifyError(localResult.error)}`)
|
|
116
|
-
}
|
|
174
|
+
if (data === null) continue
|
|
117
175
|
|
|
118
|
-
merged = { ...
|
|
176
|
+
merged = { ...merged, ...data }
|
|
119
177
|
}
|
|
120
178
|
|
|
121
|
-
const
|
|
179
|
+
const finalResult = infraKitConfigSchema.safeParse(merged)
|
|
122
180
|
|
|
123
|
-
if (!
|
|
124
|
-
throw new Error(`Invalid infra-kit
|
|
181
|
+
if (!finalResult.success) {
|
|
182
|
+
throw new Error(`Invalid merged infra-kit config: ${z.prettifyError(finalResult.error)}`)
|
|
125
183
|
}
|
|
126
184
|
|
|
127
|
-
cached = {
|
|
185
|
+
cached = { mtimes, value: finalResult.data }
|
|
128
186
|
|
|
129
|
-
return
|
|
187
|
+
return finalResult.data
|
|
130
188
|
}
|
|
131
189
|
|
|
132
|
-
/**
|
|
190
|
+
/**
|
|
191
|
+
* For tests — drops the in-memory cache so the next read hits disk.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* resetInfraKitConfigCache()
|
|
195
|
+
* await getInfraKitConfig() // re-reads files even if mtimes look unchanged
|
|
196
|
+
*/
|
|
133
197
|
export const resetInfraKitConfigCache = (): void => {
|
|
134
198
|
cached = null
|
|
135
199
|
}
|
|
136
200
|
|
|
201
|
+
/**
|
|
202
|
+
* `fs.stat` that returns `null` instead of throwing on ENOENT. Used so the
|
|
203
|
+
* resolver can probe optional files in the merge chain without try/catch noise.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* const stat = await statIfExists('/does/not/exist') // => null
|
|
207
|
+
*/
|
|
137
208
|
const statIfExists = async (filePath: string): Promise<Awaited<ReturnType<typeof fs.stat>> | null> => {
|
|
138
209
|
try {
|
|
139
210
|
return await fs.stat(filePath)
|
|
@@ -141,3 +212,78 @@ const statIfExists = async (filePath: string): Promise<Awaited<ReturnType<typeof
|
|
|
141
212
|
return null
|
|
142
213
|
}
|
|
143
214
|
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* `fs.readFile` that returns `null` instead of throwing on ENOENT.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* const raw = await readIfExists('/missing.yml') // => null
|
|
221
|
+
* const raw = await readIfExists('/exists.yml') // => 'environments: [dev]\n'
|
|
222
|
+
*/
|
|
223
|
+
const readIfExists = async (filePath: string): Promise<string | null> => {
|
|
224
|
+
try {
|
|
225
|
+
return await fs.readFile(filePath, 'utf-8')
|
|
226
|
+
} catch {
|
|
227
|
+
return null
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Reference-equality comparison of every key in two flat records. Used to
|
|
233
|
+
* cheaply detect whether the cached mtime fingerprint still matches.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* shallowEqual({ a: 1, b: 2 }, { a: 1, b: 2 }) // => true
|
|
237
|
+
* shallowEqual({ a: 1 }, { a: 1, b: 2 }) // => false
|
|
238
|
+
* shallowEqual({ a: 1 }, { a: 2 }) // => false
|
|
239
|
+
*/
|
|
240
|
+
const shallowEqual = <T extends Record<string, unknown>>(a: T, b: T): boolean => {
|
|
241
|
+
const keys = Object.keys(a)
|
|
242
|
+
|
|
243
|
+
if (keys.length !== Object.keys(b).length) return false
|
|
244
|
+
|
|
245
|
+
return keys.every((k) => {
|
|
246
|
+
return a[k] === b[k]
|
|
247
|
+
})
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
interface ConfigLayer {
|
|
251
|
+
label: string
|
|
252
|
+
path: string
|
|
253
|
+
required: boolean
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Read a single layer of the merge chain: parse the YAML if the file exists
|
|
258
|
+
* and validate it against the override schema. Returns `null` if an optional
|
|
259
|
+
* layer is missing; throws if the layer is required or invalid.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* await loadLayer({ label: '~/.infra-kit/config.yml', path: '/missing.yml', required: false })
|
|
263
|
+
* // => null
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* // /home/me/.infra-kit/config.yml: 'ide:\n provider: cursor\n config: { mode: windows }'
|
|
267
|
+
* await loadLayer({ label: '~/.infra-kit/config.yml', path: '/home/me/.infra-kit/config.yml', required: false })
|
|
268
|
+
* // => { ide: { provider: 'cursor', config: { mode: 'windows' } } }
|
|
269
|
+
*/
|
|
270
|
+
const loadLayer = async (layer: ConfigLayer): Promise<Record<string, unknown> | null> => {
|
|
271
|
+
const raw = await readIfExists(layer.path)
|
|
272
|
+
|
|
273
|
+
if (raw === null) {
|
|
274
|
+
if (layer.required) {
|
|
275
|
+
throw new Error(`${layer.label} not found at ${layer.path}`)
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return null
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const parsedRaw = yaml.parse(raw) ?? {}
|
|
282
|
+
const result = infraKitOverrideConfigSchema.safeParse(parsedRaw)
|
|
283
|
+
|
|
284
|
+
if (!result.success) {
|
|
285
|
+
throw new Error(`Invalid ${layer.label} at ${layer.path}: ${z.prettifyError(result.error)}`)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return result.data as Record<string, unknown>
|
|
289
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
NoPriorVersionsError,
|
|
5
|
+
collectKnownVersions,
|
|
6
|
+
computeNextVersion,
|
|
7
|
+
resolveVersionTokens,
|
|
8
|
+
splitVersionInput,
|
|
9
|
+
} from '../next-version'
|
|
10
|
+
|
|
11
|
+
describe('collectKnownVersions', () => {
|
|
12
|
+
it('parses remote branch refs and Jira version names and dedupes', () => {
|
|
13
|
+
const known = collectKnownVersions({
|
|
14
|
+
remoteBranches: ['release/v1.62.0', 'refs/heads/release/v1.63.0', 'release/v1.62.0'],
|
|
15
|
+
jiraVersions: ['v1.63.0', 'v1.64.5'],
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
expect(known).toEqual([
|
|
19
|
+
[1, 62, 0],
|
|
20
|
+
[1, 63, 0],
|
|
21
|
+
[1, 64, 5],
|
|
22
|
+
])
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('ignores non-semver inputs', () => {
|
|
26
|
+
const known = collectKnownVersions({
|
|
27
|
+
remoteBranches: ['release/v1.62.0', 'release/v-bogus', 'main'],
|
|
28
|
+
jiraVersions: ['v1.63.0', 'random-name'],
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
expect(known).toEqual([
|
|
32
|
+
[1, 62, 0],
|
|
33
|
+
[1, 63, 0],
|
|
34
|
+
])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('returns [] when sources are empty or undefined', () => {
|
|
38
|
+
expect(collectKnownVersions({})).toEqual([])
|
|
39
|
+
expect(collectKnownVersions({ remoteBranches: [], jiraVersions: [] })).toEqual([])
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
describe('computeNextVersion', () => {
|
|
44
|
+
it('regular bumps minor and resets patch', () => {
|
|
45
|
+
const known = collectKnownVersions({ remoteBranches: ['release/v1.63.5', 'release/v1.62.0'] })
|
|
46
|
+
|
|
47
|
+
expect(computeNextVersion(known, 'regular')).toBe('1.64.0')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('hotfix bumps patch on the highest minor (any patch)', () => {
|
|
51
|
+
const known = collectKnownVersions({
|
|
52
|
+
remoteBranches: ['release/v1.63.5', 'release/v1.63.0', 'release/v1.62.0'],
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
expect(computeNextVersion(known, 'hotfix')).toBe('1.63.6')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('hotfix uses the highest minor even when patch chain has gaps', () => {
|
|
59
|
+
const known = collectKnownVersions({
|
|
60
|
+
remoteBranches: ['release/v1.55.10', 'release/v1.55.20', 'release/v1.55.30'],
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
expect(computeNextVersion(known, 'hotfix')).toBe('1.55.31')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('throws NoPriorVersionsError when there are no known versions', () => {
|
|
67
|
+
expect(() => {
|
|
68
|
+
return computeNextVersion([], 'regular')
|
|
69
|
+
}).toThrow(NoPriorVersionsError)
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
describe('resolveVersionTokens', () => {
|
|
74
|
+
const known = collectKnownVersions({ remoteBranches: ['release/v1.63.0'] })
|
|
75
|
+
|
|
76
|
+
it('resolves "next,next" sequentially for regular', () => {
|
|
77
|
+
expect(resolveVersionTokens(['next', 'next'], 'regular', known)).toEqual(['1.64.0', '1.65.0'])
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('mixes literals and next, advancing running max', () => {
|
|
81
|
+
expect(resolveVersionTokens(['next', '1.70.0', 'next'], 'regular', known)).toEqual(['1.64.0', '1.70.0', '1.71.0'])
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('accepts NEXT and " next " (case + whitespace insensitive)', () => {
|
|
85
|
+
expect(resolveVersionTokens(['NEXT', ' next '], 'regular', known)).toEqual(['1.64.0', '1.65.0'])
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('strips leading v on explicit versions', () => {
|
|
89
|
+
expect(resolveVersionTokens(['v1.70.0'], 'regular', known)).toEqual(['1.70.0'])
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('throws on invalid token', () => {
|
|
93
|
+
expect(() => {
|
|
94
|
+
return resolveVersionTokens(['nope'], 'regular', known)
|
|
95
|
+
}).toThrow(/Invalid version/)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('hotfix sequence advances patch each step', () => {
|
|
99
|
+
expect(resolveVersionTokens(['next', 'next'], 'hotfix', known)).toEqual(['1.63.1', '1.63.2'])
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
describe('splitVersionInput', () => {
|
|
104
|
+
it('splits comma-separated input and trims', () => {
|
|
105
|
+
expect(splitVersionInput(' 1.2.3 , next, ,1.2.4 ')).toEqual(['1.2.3', 'next', '1.2.4'])
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('returns empty array for empty input', () => {
|
|
109
|
+
expect(splitVersionInput('')).toEqual([])
|
|
110
|
+
expect(splitVersionInput(' ')).toEqual([])
|
|
111
|
+
})
|
|
112
|
+
})
|
|
@@ -1 +1,12 @@
|
|
|
1
|
+
export { loadExistingVersions } from './load-existing-versions'
|
|
2
|
+
export {
|
|
3
|
+
collectKnownVersions,
|
|
4
|
+
computeNextVersion,
|
|
5
|
+
type ExistingVersionsSources,
|
|
6
|
+
NEXT_TOKEN,
|
|
7
|
+
NoPriorVersionsError,
|
|
8
|
+
resolveVersionTokens,
|
|
9
|
+
type SemVer,
|
|
10
|
+
splitVersionInput,
|
|
11
|
+
} from './next-version'
|
|
1
12
|
export { parseVersion, sortVersions } from './version-utils'
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { $ } from 'zx'
|
|
2
|
+
|
|
3
|
+
import { getProjectVersions, loadJiraConfigOptional } from 'src/integrations/jira'
|
|
4
|
+
import { logger } from 'src/lib/logger'
|
|
5
|
+
|
|
6
|
+
import { collectKnownVersions } from './next-version'
|
|
7
|
+
import type { SemVer } from './next-version'
|
|
8
|
+
|
|
9
|
+
const parseRemoteRefs = async (): Promise<string[]> => {
|
|
10
|
+
const previousQuiet = $.quiet
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
$.quiet = true
|
|
14
|
+
const result = await $`git ls-remote --heads origin 'release/v*'`
|
|
15
|
+
const lines = result.stdout.split('\n')
|
|
16
|
+
|
|
17
|
+
return lines
|
|
18
|
+
.map((line) => {
|
|
19
|
+
const tab = line.indexOf('\t')
|
|
20
|
+
|
|
21
|
+
if (tab === -1) return ''
|
|
22
|
+
|
|
23
|
+
return line.slice(tab + 1).replace(/^refs\/heads\//, '')
|
|
24
|
+
})
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
} finally {
|
|
27
|
+
$.quiet = previousQuiet
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const fetchJiraVersionNames = async (): Promise<string[]> => {
|
|
32
|
+
const config = await loadJiraConfigOptional()
|
|
33
|
+
|
|
34
|
+
if (!config) return []
|
|
35
|
+
|
|
36
|
+
const versions = await getProjectVersions(config)
|
|
37
|
+
|
|
38
|
+
return versions.map((v) => {
|
|
39
|
+
return v.name
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Load known release versions from the union of:
|
|
45
|
+
* - remote release branches (`release/v*` on origin)
|
|
46
|
+
* - Jira fix versions (when configured)
|
|
47
|
+
*
|
|
48
|
+
* Each source is queried in parallel; if either fails, we log a warning
|
|
49
|
+
* and continue with the other so a transient outage doesn't block release
|
|
50
|
+
* creation.
|
|
51
|
+
*/
|
|
52
|
+
export const loadExistingVersions = async (): Promise<SemVer[]> => {
|
|
53
|
+
const [branchesResult, jiraResult] = await Promise.allSettled([parseRemoteRefs(), fetchJiraVersionNames()])
|
|
54
|
+
|
|
55
|
+
if (branchesResult.status === 'rejected') {
|
|
56
|
+
logger.warn({ error: branchesResult.reason }, 'Failed to list remote release branches; continuing without them')
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (jiraResult.status === 'rejected') {
|
|
60
|
+
logger.warn({ error: jiraResult.reason }, 'Failed to fetch Jira versions; continuing without them')
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return collectKnownVersions({
|
|
64
|
+
remoteBranches: branchesResult.status === 'fulfilled' ? branchesResult.value : [],
|
|
65
|
+
jiraVersions: jiraResult.status === 'fulfilled' ? jiraResult.value : [],
|
|
66
|
+
})
|
|
67
|
+
}
|