Skip to content

Commit

Permalink
feat: set backport release from config instead of current branch
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Sep 14, 2023
1 parent 2a5e186 commit 9c14575
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
10 changes: 4 additions & 6 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const CONFIG_KEY = 'templateOSS'
const getPkgConfig = (pkg) => pkg[CONFIG_KEY] || {}

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

Expand Down Expand Up @@ -157,9 +156,9 @@ const getFullConfig = async ({

const branches = uniq([...pkgConfig.branches ?? [], pkgConfig.releaseBranch]).filter(Boolean)
const gitBranches = await git.getBranches(rootPkg.path, branches)
const currentBranch = await git.currentBranch(rootPkg.path)
const isReleaseBranch = currentBranch ? minimatch(currentBranch, pkgConfig.releaseBranch) : false
const defaultBranch = await git.defaultBranch(rootPkg.path) ?? 'main'
const releaseBranch = pkgConfig.backport &&
pkgConfig.releaseBranch.replace('*', pkgConfig.backport)

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This replaces only the first occurrence of '*'.

// all derived keys
const derived = {
Expand All @@ -179,11 +178,10 @@ const getFullConfig = async ({
// controls whether we are in a monorepo with any public workspaces
isMonoPublic: isMono && !!publicPkgs.filter(p => p.path !== rootPkg.path).length,
// git
defaultBranch,
baseBranch: isReleaseBranch ? currentBranch : defaultBranch,
branches: gitBranches.branches,
branchPatterns: gitBranches.patterns,
isReleaseBranch,
releaseBranch: releaseBranch ?? defaultBranch,
isReleaseBranch: !!releaseBranch,
// dependabot
dependabot: parseDependabot(pkgConfig, defaultConfig, gitBranches.branches),
// repo
Expand Down
2 changes: 1 addition & 1 deletion lib/content/ci-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
ref:
required: true
type: string
default: {{ baseBranch }}
default: {{ releaseBranch }}
workflow_call:
inputs:
ref:
Expand Down
2 changes: 2 additions & 0 deletions lib/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ module.exports = {
windowsCI: true,
macCI: true,
branches: ['main', 'latest'],
// set this to the major version to backport
backport: null,
releaseBranch: 'release/v*',
distPaths: [
'bin/',
Expand Down
9 changes: 0 additions & 9 deletions lib/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,8 @@ const defaultBranch = async (path) => {
}
}

const currentBranch = async (path) => {
try {
return await tryGit(path, 'rev-parse', '--abbrev-ref', 'HEAD')
} catch {
// ignore errors
}
}

module.exports = {
getUrl,
getBranches,
defaultBranch,
currentBranch,
}
15 changes: 15 additions & 0 deletions test/apply/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,18 @@ t.test('uses workspace flags in commands', async (t) => {
t.notMatch(release, '--ignore-scripts\n')
t.match(release, '--ignore-scripts -ws -iwr --if-present\n')
})

t.test('backport', async (t) => {
const s = await setup(t, {
package: {
templateOSS: {
backport: 8,
},
},
})
await s.apply()

const release = await s.readFile(join('.github', 'workflows', 'ci-release.yml'))

t.match(release, 'default: release/v8\n')
})

0 comments on commit 9c14575

Please sign in to comment.