Skip to content

Commit cad156a

Browse files
committed
feat: set backport release from config instead of current branch
1 parent 2a5e186 commit cad156a

File tree

7 files changed

+47
-25
lines changed

7 files changed

+47
-25
lines changed

Diff for: .github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ jobs:
425425
- name: Publish
426426
env:
427427
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
428-
run: npm publish --provenance
428+
run: npm publish --provenance --tag=latest
429429

430430
post-release-integration:
431431
needs: [ release, release-integration ]

Diff for: lib/config.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const CONFIG_KEY = 'templateOSS'
1212
const getPkgConfig = (pkg) => pkg[CONFIG_KEY] || {}
1313

1414
const { name: NAME, version: LATEST_VERSION } = require('../package.json')
15-
const { minimatch } = require('minimatch')
1615
const MERGE_KEYS = [...FILE_KEYS, 'defaultContent', 'content']
1716
const DEFAULT_CONTENT = require.resolve(NAME)
1817

@@ -157,9 +156,12 @@ const getFullConfig = async ({
157156

158157
const branches = uniq([...pkgConfig.branches ?? [], pkgConfig.releaseBranch]).filter(Boolean)
159158
const gitBranches = await git.getBranches(rootPkg.path, branches)
160-
const currentBranch = await git.currentBranch(rootPkg.path)
161-
const isReleaseBranch = currentBranch ? minimatch(currentBranch, pkgConfig.releaseBranch) : false
162159
const defaultBranch = await git.defaultBranch(rootPkg.path) ?? 'main'
160+
const isReleaseBranch = !!pkgConfig.backport
161+
const publishTag = isReleaseBranch ? `next-${pkgConfig.backport}` : 'latest'
162+
const releaseBranch = isReleaseBranch
163+
? pkgConfig.releaseBranch.replace(/\*/g, pkgConfig.backport)
164+
: defaultBranch
163165

164166
// all derived keys
165167
const derived = {
@@ -179,12 +181,11 @@ const getFullConfig = async ({
179181
// controls whether we are in a monorepo with any public workspaces
180182
isMonoPublic: isMono && !!publicPkgs.filter(p => p.path !== rootPkg.path).length,
181183
// git
182-
defaultBranch,
183-
baseBranch: isReleaseBranch ? currentBranch : defaultBranch,
184184
branches: gitBranches.branches,
185185
branchPatterns: gitBranches.patterns,
186186
isReleaseBranch,
187-
// dependabot
187+
releaseBranch,
188+
publishTag,
188189
dependabot: parseDependabot(pkgConfig, defaultConfig, gitBranches.branches),
189190
// repo
190191
repoDir: rootPkg.path,

Diff for: lib/content/_job-release-integration.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ steps:
2222
- name: Publish
2323
env:
2424
PUBLISH_TOKEN: $\{{ secrets.PUBLISH_TOKEN }}
25-
run: npm publish --provenance
25+
run: npm publish --provenance --tag={{ publishTag }}
2626
{{else}}
2727
runs-on: ubuntu-latest
2828
defaults:

Diff for: lib/content/ci-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
ref:
88
required: true
99
type: string
10-
default: {{ baseBranch }}
10+
default: {{ releaseBranch }}
1111
workflow_call:
1212
inputs:
1313
ref:

Diff for: lib/content/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ module.exports = {
136136
windowsCI: true,
137137
macCI: true,
138138
branches: ['main', 'latest'],
139+
// set this to the major version to backport
140+
backport: null,
139141
releaseBranch: 'release/v*',
140142
distPaths: [
141143
'bin/',

Diff for: lib/util/git.js

-9
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,8 @@ const defaultBranch = async (path) => {
6666
}
6767
}
6868

69-
const currentBranch = async (path) => {
70-
try {
71-
return await tryGit(path, 'rev-parse', '--abbrev-ref', 'HEAD')
72-
} catch {
73-
// ignore errors
74-
}
75-
}
76-
7769
module.exports = {
7870
getUrl,
7971
getBranches,
8072
defaultBranch,
81-
currentBranch,
8273
}

Diff for: test/apply/release.js

+35-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@ const { join } = require('path')
33
const setup = require('../setup.js')
44

55
t.test('no workspace flags in commands', async (t) => {
6-
const s = await setup(t)
6+
const s = await setup(t, {
7+
package: {
8+
templateOSS: {
9+
publish: true,
10+
},
11+
},
12+
})
713
await s.apply()
814

9-
const release = await s.readFile(join('.github', 'workflows', 'ci-release.yml'))
15+
const ciRelease = await s.readFile(join('.github', 'workflows', 'ci-release.yml'))
16+
17+
t.match(ciRelease, '--ignore-scripts\n')
18+
t.notMatch(ciRelease, '--ignore-scripts -ws -iwr --if-present\n')
1019

11-
t.match(release, '--ignore-scripts\n')
12-
t.notMatch(release, '--ignore-scripts -ws -iwr --if-present\n')
20+
const release = await s.readFile(join('.github', 'workflows', 'release.yml'))
21+
t.match(release, 'npm publish --provenance --tag=latest\n')
1322
})
1423

1524
t.test('uses workspace flags in commands', async (t) => {
@@ -20,8 +29,27 @@ t.test('uses workspace flags in commands', async (t) => {
2029
})
2130
await s.apply()
2231

23-
const release = await s.readFile(join('.github', 'workflows', 'ci-release.yml'))
32+
const ciRelease = await s.readFile(join('.github', 'workflows', 'ci-release.yml'))
33+
34+
t.notMatch(ciRelease, '--ignore-scripts\n')
35+
t.match(ciRelease, '--ignore-scripts -ws -iwr --if-present\n')
36+
})
37+
38+
t.test('backport', async (t) => {
39+
const s = await setup(t, {
40+
package: {
41+
templateOSS: {
42+
backport: 8,
43+
publish: true,
44+
},
45+
},
46+
})
47+
await s.apply()
48+
49+
const ciRelease = await s.readFile(join('.github', 'workflows', 'ci-release.yml'))
50+
51+
t.match(ciRelease, 'default: release/v8\n')
2452

25-
t.notMatch(release, '--ignore-scripts\n')
26-
t.match(release, '--ignore-scripts -ws -iwr --if-present\n')
53+
const release = await s.readFile(join('.github', 'workflows', 'release.yml'))
54+
t.match(release, 'npm publish --provenance --tag=next-8\n')
2755
})

0 commit comments

Comments
 (0)