-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbump.config.ts
More file actions
51 lines (44 loc) · 1.73 KB
/
bump.config.ts
File metadata and controls
51 lines (44 loc) · 1.73 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
import { readFile, writeFile } from 'node:fs/promises'
import { join } from 'node:path'
import { cwd } from 'node:process'
import { defineConfig } from 'bumpp'
import { parse, stringify } from 'smol-toml'
import { x } from 'tinyexec'
async function syncCargoToml() {
const cargoTomlFile = await readFile(join(cwd(), 'Cargo.toml'))
const cargoToml = parse(cargoTomlFile.toString('utf-8')) as {
workspace?: {
package?: {
version?: string
}
}
}
if (typeof cargoToml !== 'object' || cargoToml === null) {
throw new TypeError('Cargo.toml does not contain a valid object')
}
if (typeof cargoToml.workspace?.package?.version !== 'string') {
throw new TypeError('Cargo.toml does not contain a valid version in workspace.package.version')
}
const packageJSONFile = join(cwd(), 'package.json')
const packageJSON = JSON.parse(await readFile(packageJSONFile, 'utf-8'))
if (typeof packageJSON?.version !== 'string' || packageJSON?.version === null) {
throw new TypeError('package.json does not contain a valid version')
}
cargoToml.workspace.package.version = packageJSON.version
console.info(`Bumping Cargo.toml version to ${cargoToml.workspace.package.version} (from package.json, ${packageJSON.version})`)
await writeFile(join(cwd(), 'Cargo.toml'), stringify(cargoToml))
}
export default defineConfig({
recursive: true,
commit: 'release: v%s',
sign: false,
push: false,
all: true,
execute: async (operation) => {
await x('pnpm', ['publish', '-r', '--access', 'public', '--no-git-checks', '--dry-run'])
const nextVersion = operation.state.newVersion
await syncCargoToml()
console.info(`Bumping workspace version to ${nextVersion}`)
await x('cargo', ['generate-lockfile'])
},
})