From cad156a3a929ab30c5d9e595443b22f399f3941c Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Thu, 14 Sep 2023 10:58:35 -0700 Subject: [PATCH] feat: set backport release from config instead of current branch --- .github/workflows/release.yml | 2 +- lib/config.js | 13 ++++---- lib/content/_job-release-integration.yml | 2 +- lib/content/ci-release.yml | 2 +- lib/content/index.js | 2 ++ lib/util/git.js | 9 ----- test/apply/release.js | 42 ++++++++++++++++++++---- 7 files changed, 47 insertions(+), 25 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eb16e1da..f2ea1480 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 ] diff --git a/lib/config.js b/lib/config.js index 3e461a5c..dcb87e16 100644 --- a/lib/config.js +++ b/lib/config.js @@ -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) @@ -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 = { @@ -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, diff --git a/lib/content/_job-release-integration.yml b/lib/content/_job-release-integration.yml index 49ade657..136ca0a1 100644 --- a/lib/content/_job-release-integration.yml +++ b/lib/content/_job-release-integration.yml @@ -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: diff --git a/lib/content/ci-release.yml b/lib/content/ci-release.yml index c6d1c042..73bb97b8 100644 --- a/lib/content/ci-release.yml +++ b/lib/content/ci-release.yml @@ -7,7 +7,7 @@ on: ref: required: true type: string - default: {{ baseBranch }} + default: {{ releaseBranch }} workflow_call: inputs: ref: diff --git a/lib/content/index.js b/lib/content/index.js index 37b0f98e..3f3eb4dd 100644 --- a/lib/content/index.js +++ b/lib/content/index.js @@ -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/', diff --git a/lib/util/git.js b/lib/util/git.js index 68c0ca49..1b35f660 100644 --- a/lib/util/git.js +++ b/lib/util/git.js @@ -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, } diff --git a/test/apply/release.js b/test/apply/release.js index 80a267b1..622fb4bd 100644 --- a/test/apply/release.js +++ b/test/apply/release.js @@ -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) => { @@ -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') })