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 cad156a
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Expand Up @@ -425,7 +425,7 @@ jobs:
- name: Publish
env:
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
run: npm publish --provenance
run: npm publish --provenance --tag=latest

post-release-integration:
needs: [ release, release-integration ]
Expand Down
13 changes: 7 additions & 6 deletions lib/config.js
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,12 @@ 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 isReleaseBranch = !!pkgConfig.backport
const publishTag = isReleaseBranch ? `next-${pkgConfig.backport}` : 'latest'
const releaseBranch = isReleaseBranch
? pkgConfig.releaseBranch.replace(/\*/g, pkgConfig.backport)
: defaultBranch

// all derived keys
const derived = {
Expand All @@ -179,12 +181,11 @@ 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,
// dependabot
releaseBranch,
publishTag,
dependabot: parseDependabot(pkgConfig, defaultConfig, gitBranches.branches),
// repo
repoDir: rootPkg.path,
Expand Down
2 changes: 1 addition & 1 deletion lib/content/_job-release-integration.yml
Expand Up @@ -22,7 +22,7 @@ steps:
- name: Publish
env:
PUBLISH_TOKEN: $\{{ secrets.PUBLISH_TOKEN }}
run: npm publish --provenance
run: npm publish --provenance --tag={{ publishTag }}
{{else}}
runs-on: ubuntu-latest
defaults:
Expand Down
2 changes: 1 addition & 1 deletion lib/content/ci-release.yml
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
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
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,
}
42 changes: 35 additions & 7 deletions test/apply/release.js
Expand Up @@ -3,13 +3,22 @@ const { join } = require('path')
const setup = require('../setup.js')

t.test('no workspace flags in commands', async (t) => {
const s = await setup(t)
const s = await setup(t, {
package: {
templateOSS: {
publish: true,
},
},
})
await s.apply()

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

t.match(ciRelease, '--ignore-scripts\n')
t.notMatch(ciRelease, '--ignore-scripts -ws -iwr --if-present\n')

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

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

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

t.notMatch(ciRelease, '--ignore-scripts\n')
t.match(ciRelease, '--ignore-scripts -ws -iwr --if-present\n')
})

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

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

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

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

0 comments on commit cad156a

Please sign in to comment.