From 6ecdea4580e00bb3fe80ca4765f055521c51d4ce Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Mon, 3 Oct 2022 17:20:08 -0700 Subject: [PATCH 01/10] fix: fallback to lower bound of range for engines check --- lib/config.js | 20 +++++++++++++++++--- lib/content/ci.yml | 2 +- lib/util/template.js | 1 - test/apply/engines.js | 12 ++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/config.js b/lib/config.js index 837a454d..1068f631 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,5 +1,6 @@ const { relative, dirname, join, extname, posix, win32 } = require('path') const { defaults, pick, omit, uniq } = require('lodash') +const semver = require('semver') const parseCIVersions = require('./util/parse-ci-versions.js') const getGitUrl = require('./util/get-git-url.js') const gitignore = require('./util/gitignore.js') @@ -222,9 +223,22 @@ const getFullConfig = async ({ versions = defaultVersions.ciVersions.slice(-1) } - const parsed = parseCIVersions(versions) - derived.ciVersions = parsed.targets - derived.engines = pkgConfig.engines || parsed.engines + const { targets, engines } = parseCIVersions(versions) + + // get just a list of the target versions (not ranges) + // these are used for the node version when doing engines checks + // since we want to test in the lowest version of each major + let targetVersions = targets.filter(t => semver.valid(t)) + // if the versions are all ranges then convert them to the lower bound of each range + if (!targetVersions.length) { + targetVersions = targets.filter(t => semver.validRange(t)).map(t => { + return new semver.Range(t).set[0][0].semver.version + }) + } + + derived.ciVersions = targets + derived.baseCiVersions = targetVersions + derived.engines = pkgConfig.engines || engines } const gitUrl = await getGitUrl(root) diff --git a/lib/content/ci.yml b/lib/content/ci.yml index 83338a9e..18908c06 100644 --- a/lib/content/ci.yml +++ b/lib/content/ci.yml @@ -10,7 +10,7 @@ jobs: jobDepFlags="--engines-strict" macCI=false windowsCI=false - ciVersions=(reject ciVersions '\.x$') + ciVersions=baseCiVersions }} lint: diff --git a/lib/util/template.js b/lib/util/template.js index e0578b76..1eb67ed7 100644 --- a/lib/util/template.js +++ b/lib/util/template.js @@ -35,7 +35,6 @@ const setupHandlebars = (baseDir, ...otherDirs) => { Handlebars.registerHelper('obj', ({ hash }) => Object.fromEntries(safeValues(hash))) Handlebars.registerHelper('join', (arr, sep) => arr.join(typeof sep === 'string' ? sep : ', ')) Handlebars.registerHelper('pluck', (arr, key) => arr.map(a => a[key])) - Handlebars.registerHelper('reject', (arr, re) => arr.filter(a => !new RegExp(re).test(a))) Handlebars.registerHelper('quote', (arr) => arr.map(a => `'${a}'`)) Handlebars.registerHelper('last', (arr) => arr[arr.length - 1]) Handlebars.registerHelper('json', (c) => JSON.stringify(c)) diff --git a/test/apply/engines.js b/test/apply/engines.js index b8fb823f..c09daa9d 100644 --- a/test/apply/engines.js +++ b/test/apply/engines.js @@ -1,7 +1,10 @@ const t = require('tap') const { join } = require('path') +const yaml = require('yaml') const setup = require('../setup.js') +const getEngines = (ci) => yaml.parse(ci).jobs.engines.strategy.matrix['node-version'] + t.test('can set engines and ci separately', async (t) => { const s = await setup(t, { package: { @@ -31,7 +34,10 @@ t.test('latest ci versions', async (t) => { await s.apply() const pkg = await s.readJson('package.json') + const ci = await s.readFile('.github/workflows/ci.yml') + t.equal(pkg.engines.node, '>=18.0.0') + t.strictSame(getEngines(ci), ['18.0.0']) }) t.test('latest ci versions in workspace', async (t) => { @@ -61,9 +67,15 @@ t.test('latest ci versions in workspace', async (t) => { }) await s.apply() + const ci = await s.readFile('.github/workflows/ci.yml') + const ciWorkspace = await s.readFile('.github/workflows/ci-a.yml') + const root = await s.readJson('target.json') const workspace = await s.readJson('target-a.json') t.equal(root.node, '^12.0.0 || ^14.0.0 || >=16.0.0') t.equal(workspace.node, '>=16.0.0') + + t.strictSame(getEngines(ci), ['12.0.0', '14.0.0', '16.0.0']) + t.strictSame(getEngines(ciWorkspace), ['16.0.0']) }) From b37c453e7eca6d2258d9c07e578286d92e0db72b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 4 Oct 2022 16:35:10 +0000 Subject: [PATCH 02/10] chore: release 4.4.5 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 6 ++++++ package.json | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index e575b70e..a7aa92e6 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.4.4" + ".": "4.4.5" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 9934d1c7..b9d8991b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [4.4.5](https://github.com/npm/template-oss/compare/v4.4.4...v4.4.5) (2022-10-04) + +### Bug Fixes + +* [`6ecdea4`](https://github.com/npm/template-oss/commit/6ecdea4580e00bb3fe80ca4765f055521c51d4ce) [#222](https://github.com/npm/template-oss/pull/222) fallback to lower bound of range for engines check (@lukekarrys) + ## [4.4.4](https://github.com/npm/template-oss/compare/v4.4.3...v4.4.4) (2022-09-30) ### Bug Fixes diff --git a/package.json b/package.json index 6df3d93a..096ec251 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@npmcli/template-oss", - "version": "4.4.4", + "version": "4.4.5", "description": "templated files used in npm CLI team oss projects", "main": "lib/content/index.js", "bin": { From aef199e300b3bb00d7631b86ca09d6d3d1b86386 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 5 Oct 2022 09:57:48 -0700 Subject: [PATCH 03/10] feat: add default release-manager script (#221) --- .github/workflows/release.yml | 1 + bin/release-manager.js | 260 ++++++++++++++++++ lib/content/release.yml | 1 + package.json | 4 +- .../test/apply/source-snapshots.js.test.cjs | 3 + 5 files changed, 268 insertions(+), 1 deletion(-) create mode 100755 bin/release-manager.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 01a8d6a9..aee93ddf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -132,6 +132,7 @@ jobs: RELEASE_COMMENT_ID: ${{ needs.release.outputs.comment-id }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | + npm exec --offline -- template-oss-release-manager npm run rp-pull-request --ignore-scripts -ws -iwr --if-present - name: Commit id: commit diff --git a/bin/release-manager.js b/bin/release-manager.js new file mode 100755 index 00000000..3e1b4830 --- /dev/null +++ b/bin/release-manager.js @@ -0,0 +1,260 @@ +#!/usr/bin/env node + +const { Octokit } = require('@octokit/rest') +const semver = require('semver') +const mapWorkspaces = require('@npmcli/map-workspaces') +const { join } = require('path') + +const log = (...logs) => console.error('LOG', ...logs) + +const ROOT = process.cwd() +const pkg = require(join(ROOT, 'package.json')) + +/* eslint-disable max-len */ +const DEFAULT_RELEASE_PROCESS = ` +1. Checkout the release branch and test + + \`\`\`sh + gh pr checkout --force + npm i + npm test + gh pr checks --watch + \`\`\` + +1. Publish workspaces + + \`\`\`sh + npm publish -w + \`\`\` + +1. Publish + + \`\`\`sh + npm publish + \`\`\` + +1. Merge release PR + + \`\`\`sh + gh pr merge --rebase + git checkout + git fetch + git reset --hard origin/ + \`\`\` + +1. Check For Release Tags + + Release Please will run on the just pushed release commit and create GitHub releases and tags for each package. + + \`\`\` + gh run watch \`gh run list -w release -b -L 1 --json databaseId -q ".[0].databaseId"\` + \`\`\` +` /* eslint-enable max-len */ + +const getReleaseProcess = async ({ owner, repo }) => { + const RELEASE_LIST_ITEM = /^\d+\.\s/gm + + log(`Fetching release process from:`, owner, repo, 'wiki') + + let releaseProcess = '' + try { + releaseProcess = await new Promise((resolve, reject) => { + require('https') + .get(`https://raw.githubusercontent.com/wiki/${owner}/${repo}/Release-Process.md`, resp => { + let d = '' + resp.on('data', c => (d += c)) + resp.on('end', () => { + if (resp.statusCode !== 200) { + reject(new Error(`${resp.req.protocol + resp.req.host + resp.req.path}: ${d}`)) + } else { + resolve(d) + } + }) + }) + .on('error', reject) + }) + } catch (e) { + log('Release wiki not found', e.message) + log('Using default release process') + releaseProcess = DEFAULT_RELEASE_PROCESS.trim() + '\n' + } + + // XXX: the release steps need to always be the last thing in the doc for this to work + const releaseLines = releaseProcess.split('\n') + const releaseStartLine = releaseLines.reduce((acc, line, index) => + line.match(/^#+\s/) ? index : acc, 0) + const section = releaseLines.slice(releaseStartLine).join('\n') + + return section.split({ + [Symbol.split] (str) { + const [, ...matches] = str.split(RELEASE_LIST_ITEM) + log(`Found ${matches.length} release items`) + return matches.map((m) => `- [ ] . ${m}`.trim()) + }, + }) +} + +const getPrReleases = async (pr) => { + const RELEASE_SEPARATOR = /
.*<\/summary>/g + const MONO_VERSIONS = /
(?:(.*?):\s)?(.*?)<\/summary>/ + const ROOT_VERSION = /\n##\s\[(.*?)\]/ + + const workspaces = [...await mapWorkspaces({ pkg: pkg, cwd: ROOT })].reduce((acc, [k]) => { + const wsComponentName = k.startsWith('@') ? k.split('/')[1] : k + acc[wsComponentName] = k + return acc + }, {}) + + const getReleaseInfo = ({ name, version: rawVersion }) => { + const version = semver.parse(rawVersion) + const prerelease = !!version.prerelease.length + const tag = `${name ? `${name}-` : ''}v${rawVersion}` + const workspace = workspaces[name] + + return { + name, + tag, + prerelease, + version: rawVersion, + major: version.major, + url: `https://github.com/${pr.base.repo.full_name}/releases/tag/${tag}`, + flags: `${name ? `-w ${workspace}` : ''} ${prerelease ? `--tag prerelease` : ''}`.trim(), + } + } + + const releases = pr.body.match(RELEASE_SEPARATOR) + + if (!releases) { + log('Found no monorepo, checking for single root version') + const [, version] = pr.body.match(ROOT_VERSION) || [] + + if (!version) { + throw new Error('Could not find version with:', ROOT_VERSION) + } + + log('Found version', version) + return [getReleaseInfo({ version })] + } + + log(`Found ${releases.length} releases`) + + return releases.reduce((acc, r) => { + const [, name, version] = r.match(MONO_VERSIONS) + const release = getReleaseInfo({ name, version }) + + if (!name) { + log('Found root', release) + acc[0] = release + } else { + log('Found workspace', release) + acc[1].push(release) + } + + return acc + }, [null, []]) +} + +const appendToComment = async ({ github, commentId, title, body }) => { + if (!commentId) { + log(`No comment id, skipping append to comment`) + return + } + + const { data: comment } = await github.rest.issues.getComment({ + ...github.repo, + comment_id: commentId, + }) + + const hasAppended = comment.body.includes(title) + + log('Found comment with id:', commentId) + log(hasAppended ? 'Comment has aready been appended, replacing' : 'Appending to comment') + + const prefix = hasAppended + ? comment.body.split(title)[0] + : comment.body + + return github.rest.issues.updateComment({ + ...github.repo, + comment_id: commentId, + body: [prefix, title, body].join('\n\n'), + }) +} + +const main = async (env) => { + // These env vars are set by the release.yml workflow from template-oss + const { + CI, + GITHUB_TOKEN, + GITHUB_REPOSITORY, + RELEASE_PR_NUMBER, + RELEASE_COMMENT_ID, // comment is optional for testing + } = env + + if (!CI || !GITHUB_TOKEN || !GITHUB_REPOSITORY || !RELEASE_PR_NUMBER) { + throw new Error('This script is designed to run in CI. If you want to test it, set the ' + + `following env vars: \`CI, GITHUB_TOKEN, GITHUB_REPOSITORY, RELEASE_PR_NUMBER\``) + } + + const [owner, repo] = GITHUB_REPOSITORY.split('/') + const github = new Octokit({ auth: GITHUB_TOKEN }) + github.repo = { owner, repo } + + const { data: pr } = await github.rest.pulls.get({ + ...github.repo, + pull_number: RELEASE_PR_NUMBER, + }) + + const [release, workspaces = []] = await getPrReleases(pr) + + const RELEASE_OMIT_PRERELEASE = '> NOT FOR PRERELEASE' + const RELEASE_OMIT_WORKSPACES = 'Publish workspaces' + const releaseItems = (await getReleaseProcess({ owner, repo })) + .filter((item) => { + if (release.prerelease && item.includes(RELEASE_OMIT_PRERELEASE)) { + return false + } + + if (!workspaces.length && item.includes(RELEASE_OMIT_WORKSPACES)) { + return false + } + + return true + }) + .map((item, index) => item.replace('', index + 1)) + + log( + `Filtered ${releaseItems.length} release process items:\n`, + releaseItems.map(r => r.split('\n')[0].replace('- [ ] ', '')).join(', ') + ) + + const releaseTitle = `### Release Checklist for ${release.tag}` + const releaseChecklist = releaseItems + .join('\n\n') + .replace(//g, RELEASE_PR_NUMBER) + .replace(//g, pr.head.ref) + .replace(//g, pr.base.ref) + .replace(//g, release.major) + .replace(//g, release.version) + .replace(//g, release.url) + .replace(//g, release.flags) + .replace(/^(\s*\S.*)(-w )$/gm, workspaces.map(w => `$1${w.flags}`).join('\n')) + .trim() + + await appendToComment({ + github, + commentId: RELEASE_COMMENT_ID, + title: releaseTitle, + body: releaseChecklist, + }) + + if (!RELEASE_COMMENT_ID) { + console.log(releaseChecklist) + } +} + +main(process.env) + // This is part of the release CI and is for posting a release manager + // comment to the issue but we dont want it to ever fail the workflow so + // just log but dont set the error code + .catch(err => console.error(err)) diff --git a/lib/content/release.yml b/lib/content/release.yml index a37b8e1e..cf6ade3f 100644 --- a/lib/content/release.yml +++ b/lib/content/release.yml @@ -77,6 +77,7 @@ jobs: RELEASE_COMMENT_ID: $\{{ needs.release.outputs.comment-id }} GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }} run: | + {{ rootNpmPath }} exec --offline -- template-oss-release-manager {{ rootNpmPath }} run rp-pull-request --ignore-scripts {{ allFlags }} - name: Commit id: commit diff --git a/package.json b/package.json index 096ec251..63fe01df 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "bin": { "template-oss-apply": "bin/apply.js", "template-oss-check": "bin/check.js", - "template-oss-release-please": "bin/release-please.js" + "template-oss-release-please": "bin/release-please.js", + "template-oss-release-manager": "bin/release-manager.js" }, "scripts": { "lint": "eslint \"**/*.js\"", @@ -37,6 +38,7 @@ "@npmcli/git": "^3.0.0", "@npmcli/map-workspaces": "^2.0.2", "@npmcli/package-json": "^2.0.0", + "@octokit/rest": "^19.0.4", "diff": "^5.0.0", "glob": "^8.0.1", "handlebars": "^4.7.7", diff --git a/tap-snapshots/test/apply/source-snapshots.js.test.cjs b/tap-snapshots/test/apply/source-snapshots.js.test.cjs index 3249cc0d..643e6833 100644 --- a/tap-snapshots/test/apply/source-snapshots.js.test.cjs +++ b/tap-snapshots/test/apply/source-snapshots.js.test.cjs @@ -872,6 +872,7 @@ jobs: RELEASE_COMMENT_ID: \${{ needs.release.outputs.comment-id }} GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} run: | + npm exec --offline -- template-oss-release-manager npm run rp-pull-request --ignore-scripts -ws -iwr --if-present - name: Commit id: commit @@ -2353,6 +2354,7 @@ jobs: RELEASE_COMMENT_ID: \${{ needs.release.outputs.comment-id }} GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} run: | + npm exec --offline -- template-oss-release-manager npm run rp-pull-request --ignore-scripts -ws -iwr --if-present - name: Commit id: commit @@ -3578,6 +3580,7 @@ jobs: RELEASE_COMMENT_ID: \${{ needs.release.outputs.comment-id }} GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} run: | + npm exec --offline -- template-oss-release-manager npm run rp-pull-request --ignore-scripts -ws -iwr --if-present - name: Commit id: commit From 298600db3509f5bab469caa95fd73ceedc42cde4 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 5 Oct 2022 09:58:08 -0700 Subject: [PATCH 04/10] fix: use head.ref for post dependabot checkout (#224) --- .github/workflows/post-dependabot.yml | 2 +- lib/content/post-dependabot.yml | 2 +- tap-snapshots/test/apply/source-snapshots.js.test.cjs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/post-dependabot.yml b/.github/workflows/post-dependabot.yml index e854e127..88ac4035 100644 --- a/.github/workflows/post-dependabot.yml +++ b/.github/workflows/post-dependabot.yml @@ -19,7 +19,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 with: - ref: ${{ github.ref_name }} + ref: ${{ github.event.pull_request.head.ref }} - name: Setup Git User run: | git config --global user.email "npm-cli+bot@github.com" diff --git a/lib/content/post-dependabot.yml b/lib/content/post-dependabot.yml index 77b21cf7..7dba72e6 100644 --- a/lib/content/post-dependabot.yml +++ b/lib/content/post-dependabot.yml @@ -11,7 +11,7 @@ jobs: {{> job jobName="template-oss" jobIf="github.actor == 'dependabot[bot]'" - jobCheckout=(obj ref="${{ github.ref_name }}") + jobCheckout=(obj ref="${{ github.event.pull_request.head.ref }}") }} - name: Fetch Dependabot Metadata id: metadata diff --git a/tap-snapshots/test/apply/source-snapshots.js.test.cjs b/tap-snapshots/test/apply/source-snapshots.js.test.cjs index 643e6833..b08f6f62 100644 --- a/tap-snapshots/test/apply/source-snapshots.js.test.cjs +++ b/tap-snapshots/test/apply/source-snapshots.js.test.cjs @@ -584,7 +584,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 with: - ref: \${{ github.ref_name }} + ref: \${{ github.event.pull_request.head.ref }} - name: Setup Git User run: | git config --global user.email "npm-cli+bot@github.com" @@ -2066,7 +2066,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 with: - ref: \${{ github.ref_name }} + ref: \${{ github.event.pull_request.head.ref }} - name: Setup Git User run: | git config --global user.email "npm-cli+bot@github.com" @@ -3343,7 +3343,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 with: - ref: \${{ github.ref_name }} + ref: \${{ github.event.pull_request.head.ref }} - name: Setup Git User run: | git config --global user.email "npm-cli+bot@github.com" From f6a02684cd5742274ac33efc6efa89707d013bcc Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 5 Oct 2022 10:03:11 -0700 Subject: [PATCH 05/10] fix: bump workspace dev deps with a deps commit (#225) --- lib/release-please/node-workspace.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/release-please/node-workspace.js b/lib/release-please/node-workspace.js index fb4f9503..31a8207c 100644 --- a/lib/release-please/node-workspace.js +++ b/lib/release-please/node-workspace.js @@ -81,9 +81,13 @@ module.exports = class extends NodeWorkspace { for (const [depName, resolved] of graphPackage.localDependencies) { const depVersion = updatedVersions.get(depName) const isNotDir = resolved.type !== 'directory' - // Changelog entries are only added for dependencies and not any other type - const isDep = Object.prototype.hasOwnProperty.call(pkg.dependencies, depName) - if (depVersion && isNotDir && isDep) { + + // Due to some bugs in release-please we need to create `deps:` commits + // for all dev and prod dependencies even though we normally would only + // do a `chore:` commit to bump a dev dep. The tradeoff is an extra + // patch release to workspaces that depend on other workspaces as dev + // dependencies. + if (depVersion && isNotDir) { commitsByPath[path].push({ message: `deps(${SCOPE}): ${depName} ${depVersion.toString()}`, }) From b313218153e55d83713c8d8830e74a1d0d412098 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 5 Oct 2022 10:04:17 -0700 Subject: [PATCH 06/10] fix: dont use -ws flags in release workflow when not necessary (#226) --- .github/workflows/ci-release.yml | 2 +- .github/workflows/release.yml | 2 +- lib/config.js | 2 +- .../test/apply/source-snapshots.js.test.cjs | 4 +-- test/apply/release.js | 27 +++++++++++++++++++ 5 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 test/apply/release.js diff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.yml index 6143296a..740d492d 100644 --- a/.github/workflows/ci-release.yml +++ b/.github/workflows/ci-release.yml @@ -144,7 +144,7 @@ jobs: - name: Add Problem Matcher run: echo "::add-matcher::.github/matchers/tap.json" - name: Test - run: npm test --ignore-scripts -ws -iwr --if-present + run: npm test --ignore-scripts --if-present - name: Conclude Check uses: LouisBrunner/checks-action@v1.3.1 if: always() diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index aee93ddf..1ed38659 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -133,7 +133,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | npm exec --offline -- template-oss-release-manager - npm run rp-pull-request --ignore-scripts -ws -iwr --if-present + npm run rp-pull-request --ignore-scripts --if-present - name: Commit id: commit env: diff --git a/lib/config.js b/lib/config.js index 1068f631..1e2f32d4 100644 --- a/lib/config.js +++ b/lib/config.js @@ -178,7 +178,7 @@ const getFullConfig = async ({ pkgDir: posixDir(pkgPath), pkgGlob: posixGlob(pkgPath), pkgFlags: isRoot ? '-iwr' : `-w ${pkgJson.name}`, - allFlags: '-ws -iwr --if-present', + allFlags: `${workspaces.length ? '-ws -iwr' : ''} --if-present`.trim(), workspacePaths, workspaceGlobs: workspacePaths.map(posixGlob), // booleans to control application of updates diff --git a/tap-snapshots/test/apply/source-snapshots.js.test.cjs b/tap-snapshots/test/apply/source-snapshots.js.test.cjs index b08f6f62..596a4d0b 100644 --- a/tap-snapshots/test/apply/source-snapshots.js.test.cjs +++ b/tap-snapshots/test/apply/source-snapshots.js.test.cjs @@ -351,7 +351,7 @@ jobs: - name: Add Problem Matcher run: echo "::add-matcher::.github/matchers/tap.json" - name: Test - run: npm test --ignore-scripts -ws -iwr --if-present + run: npm test --ignore-scripts --if-present - name: Conclude Check uses: LouisBrunner/checks-action@v1.3.1 if: always() @@ -873,7 +873,7 @@ jobs: GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} run: | npm exec --offline -- template-oss-release-manager - npm run rp-pull-request --ignore-scripts -ws -iwr --if-present + npm run rp-pull-request --ignore-scripts --if-present - name: Commit id: commit env: diff --git a/test/apply/release.js b/test/apply/release.js new file mode 100644 index 00000000..159c8300 --- /dev/null +++ b/test/apply/release.js @@ -0,0 +1,27 @@ +const t = require('tap') +const { join } = require('path') +const setup = require('../setup.js') + +t.test('no workspace flags in commands', async (t) => { + const s = await setup(t) + await s.apply() + + const release = await s.readFile(join('.github', 'workflows', 'release.yml')) + + t.match(release, '--ignore-scripts --if-present\n') + t.notMatch(release, '--ignore-scripts -ws -iwr --if-present\n') +}) + +t.test('uses workspace flags in commands', async (t) => { + const s = await setup(t, { + workspaces: { + a: 'a', + }, + }) + await s.apply() + + const release = await s.readFile(join('.github', 'workflows', 'release.yml')) + + t.notMatch(release, '--ignore-scripts --if-present\n') + t.match(release, '--ignore-scripts -ws -iwr --if-present\n') +}) From 7d7e66ca4bd37a201f2833e394268f3bdeb5dbb5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 5 Oct 2022 17:11:20 +0000 Subject: [PATCH 07/10] chore: release 4.5.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 12 ++++++++++++ package.json | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index a7aa92e6..7aa3d567 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.4.5" + ".": "4.5.0" } diff --git a/CHANGELOG.md b/CHANGELOG.md index b9d8991b..33cb08a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [4.5.0](https://github.com/npm/template-oss/compare/v4.4.5...v4.5.0) (2022-10-05) + +### Features + +* [`aef199e`](https://github.com/npm/template-oss/commit/aef199e300b3bb00d7631b86ca09d6d3d1b86386) [#221](https://github.com/npm/template-oss/pull/221) add default release-manager script (#221) (@lukekarrys) + +### Bug Fixes + +* [`b313218`](https://github.com/npm/template-oss/commit/b313218153e55d83713c8d8830e74a1d0d412098) [#226](https://github.com/npm/template-oss/pull/226) dont use -ws flags in release workflow when not necessary (#226) (@lukekarrys) +* [`f6a0268`](https://github.com/npm/template-oss/commit/f6a02684cd5742274ac33efc6efa89707d013bcc) [#225](https://github.com/npm/template-oss/pull/225) bump workspace dev deps with a deps commit (#225) (@lukekarrys) +* [`298600d`](https://github.com/npm/template-oss/commit/298600db3509f5bab469caa95fd73ceedc42cde4) [#224](https://github.com/npm/template-oss/pull/224) use head.ref for post dependabot checkout (#224) (@lukekarrys) + ## [4.4.5](https://github.com/npm/template-oss/compare/v4.4.4...v4.4.5) (2022-10-04) ### Bug Fixes diff --git a/package.json b/package.json index 63fe01df..ee892f63 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@npmcli/template-oss", - "version": "4.4.5", + "version": "4.5.0", "description": "templated files used in npm CLI team oss projects", "main": "lib/content/index.js", "bin": { From 0ccfc17f1c4033575cc66c67513baf85a9f2b047 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Thu, 6 Oct 2022 09:21:29 -0700 Subject: [PATCH 08/10] deps: @npmcli/release-please@14.2.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ee892f63..9f937b1b 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "lodash": "^4.17.21", "npm-package-arg": "^9.0.1", "proc-log": "^2.0.0", - "release-please": "npm:@npmcli/release-please@^14.2.5", + "release-please": "npm:@npmcli/release-please@^14.2.6", "semver": "^7.3.5", "yaml": "^2.1.1" }, From bc72b05884dc59cd5f45b6f29f3308aad0456e7a Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Fri, 7 Oct 2022 23:08:08 -0700 Subject: [PATCH 09/10] fix: add individual workspace flag to lint step --- .github/workflows/ci-release.yml | 2 +- .github/workflows/ci.yml | 2 +- lib/config.js | 14 +++++---- lib/content/_step-lint.yml | 4 +-- lib/content/release.yml | 2 +- .../test/apply/source-snapshots.js.test.cjs | 30 +++++++++---------- .../test/check/diff-snapshots.js.test.cjs | 2 +- test/apply/release.js | 8 ++--- 8 files changed, 34 insertions(+), 30 deletions(-) diff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.yml index 740d492d..9cc6b283 100644 --- a/.github/workflows/ci-release.yml +++ b/.github/workflows/ci-release.yml @@ -144,7 +144,7 @@ jobs: - name: Add Problem Matcher run: echo "::add-matcher::.github/matchers/tap.json" - name: Test - run: npm test --ignore-scripts --if-present + run: npm test --ignore-scripts - name: Conclude Check uses: LouisBrunner/checks-action@v1.3.1 if: always() diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aadd60a8..a6c934ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -154,4 +154,4 @@ jobs: - name: Add Problem Matcher run: echo "::add-matcher::.github/matchers/tap.json" - name: Test - run: npm test --ignore-scripts -iwr + run: npm test --ignore-scripts diff --git a/lib/config.js b/lib/config.js index 1e2f32d4..2472e733 100644 --- a/lib/config.js +++ b/lib/config.js @@ -99,6 +99,10 @@ const getFullConfig = async ({ pkgConfig: _pkgConfig, }) => { const isRoot = root === path + const isWorkspace = !isRoot + const isMono = !!workspaces.length + const isRootMono = isRoot && isMono + const isLatest = _pkgConfig.version === LATEST_VERSION const isDogFood = pkgJson.name === NAME const isForce = process.argv.includes('--force') @@ -154,14 +158,14 @@ const getFullConfig = async ({ // all derived keys const derived = { isRoot, - isWorkspace: !isRoot, + isWorkspace, // Some files are written to the base of a repo but will // include configuration for all packages within a monorepo // For these cases it is helpful to know if we are in a // monorepo since template-oss might be used only for // workspaces and not the root or vice versa. - isRootMono: isRoot && !!workspaces.length, - isMono: !!workspaces.length, + isRootMono, + isMono, // repo repoDir: root, repoFiles, @@ -177,8 +181,8 @@ const getFullConfig = async ({ pkgPath, pkgDir: posixDir(pkgPath), pkgGlob: posixGlob(pkgPath), - pkgFlags: isRoot ? '-iwr' : `-w ${pkgJson.name}`, - allFlags: `${workspaces.length ? '-ws -iwr' : ''} --if-present`.trim(), + pkgFlags: isWorkspace ? `-w ${pkgJson.name}` : '', + allFlags: isMono ? '-ws -iwr --if-present' : '', workspacePaths, workspaceGlobs: workspacePaths.map(posixGlob), // booleans to control application of updates diff --git a/lib/content/_step-lint.yml b/lib/content/_step-lint.yml index 7070daee..8c8ff7d6 100644 --- a/lib/content/_step-lint.yml +++ b/lib/content/_step-lint.yml @@ -1,4 +1,4 @@ - name: Lint - run: {{ rootNpmPath }} run lint --ignore-scripts + run: {{ rootNpmPath }} run lint --ignore-scripts {{~#if jobRunFlags}} {{ jobRunFlags }}{{/if}} - name: Post Lint - run: {{ rootNpmPath }} run postlint --ignore-scripts + run: {{ rootNpmPath }} run postlint --ignore-scripts {{~#if jobRunFlags}} {{ jobRunFlags }}{{/if}} diff --git a/lib/content/release.yml b/lib/content/release.yml index cf6ade3f..a6f51632 100644 --- a/lib/content/release.yml +++ b/lib/content/release.yml @@ -78,7 +78,7 @@ jobs: GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }} run: | {{ rootNpmPath }} exec --offline -- template-oss-release-manager - {{ rootNpmPath }} run rp-pull-request --ignore-scripts {{ allFlags }} + {{ rootNpmPath }} run rp-pull-request --ignore-scripts {{~#if allFlags}} {{ allFlags }}{{else}} --if-present{{/if}} - name: Commit id: commit env: diff --git a/tap-snapshots/test/apply/source-snapshots.js.test.cjs b/tap-snapshots/test/apply/source-snapshots.js.test.cjs index 596a4d0b..3fe3f0a3 100644 --- a/tap-snapshots/test/apply/source-snapshots.js.test.cjs +++ b/tap-snapshots/test/apply/source-snapshots.js.test.cjs @@ -351,7 +351,7 @@ jobs: - name: Add Problem Matcher run: echo "::add-matcher::.github/matchers/tap.json" - name: Test - run: npm test --ignore-scripts --if-present + run: npm test --ignore-scripts - name: Conclude Check uses: LouisBrunner/checks-action@v1.3.1 if: always() @@ -518,7 +518,7 @@ jobs: - name: Add Problem Matcher run: echo "::add-matcher::.github/matchers/tap.json" - name: Test - run: npm test --ignore-scripts -iwr + run: npm test --ignore-scripts .github/workflows/codeql-analysis.yml ======================================== @@ -1448,9 +1448,9 @@ jobs: - name: Install Dependencies run: npm i --ignore-scripts --no-audit --no-fund - name: Lint - run: npm run lint --ignore-scripts + run: npm run lint --ignore-scripts -w a - name: Post Lint - run: npm run postlint --ignore-scripts + run: npm run postlint --ignore-scripts -w a test: name: Test - \${{ matrix.platform.name }} - \${{ matrix.node-version }} @@ -1612,9 +1612,9 @@ jobs: - name: Install Dependencies run: npm i --ignore-scripts --no-audit --no-fund - name: Lint - run: npm run lint --ignore-scripts + run: npm run lint --ignore-scripts -w b - name: Post Lint - run: npm run postlint --ignore-scripts + run: npm run postlint --ignore-scripts -w b test: name: Test - \${{ matrix.platform.name }} - \${{ matrix.node-version }} @@ -1738,9 +1738,9 @@ jobs: - name: Install Dependencies run: npm i --ignore-scripts --no-audit --no-fund - name: Lint - run: npm run lint --ignore-scripts + run: npm run lint --ignore-scripts -ws -iwr --if-present - name: Post Lint - run: npm run postlint --ignore-scripts + run: npm run postlint --ignore-scripts -ws -iwr --if-present - name: Conclude Check uses: LouisBrunner/checks-action@v1.3.1 if: always() @@ -2000,7 +2000,7 @@ jobs: - name: Add Problem Matcher run: echo "::add-matcher::.github/matchers/tap.json" - name: Test - run: npm test --ignore-scripts -iwr + run: npm test --ignore-scripts .github/workflows/codeql-analysis.yml ======================================== @@ -2932,9 +2932,9 @@ jobs: - name: Install Dependencies run: npm i --ignore-scripts --no-audit --no-fund - name: Lint - run: npm run lint --ignore-scripts + run: npm run lint --ignore-scripts -w a - name: Post Lint - run: npm run postlint --ignore-scripts + run: npm run postlint --ignore-scripts -w a test: name: Test - \${{ matrix.platform.name }} - \${{ matrix.node-version }} @@ -3096,9 +3096,9 @@ jobs: - name: Install Dependencies run: npm i --ignore-scripts --no-audit --no-fund - name: Lint - run: npm run lint --ignore-scripts + run: npm run lint --ignore-scripts -w b - name: Post Lint - run: npm run postlint --ignore-scripts + run: npm run postlint --ignore-scripts -w b test: name: Test - \${{ matrix.platform.name }} - \${{ matrix.node-version }} @@ -3222,9 +3222,9 @@ jobs: - name: Install Dependencies run: npm i --ignore-scripts --no-audit --no-fund - name: Lint - run: npm run lint --ignore-scripts + run: npm run lint --ignore-scripts -ws -iwr --if-present - name: Post Lint - run: npm run postlint --ignore-scripts + run: npm run postlint --ignore-scripts -ws -iwr --if-present - name: Conclude Check uses: LouisBrunner/checks-action@v1.3.1 if: always() diff --git a/tap-snapshots/test/check/diff-snapshots.js.test.cjs b/tap-snapshots/test/check/diff-snapshots.js.test.cjs index 20d0c502..bf8c8ec3 100644 --- a/tap-snapshots/test/check/diff-snapshots.js.test.cjs +++ b/tap-snapshots/test/check/diff-snapshots.js.test.cjs @@ -197,7 +197,7 @@ The repo file ci.yml needs to be updated: + - name: Add Problem Matcher + run: echo "::add-matcher::.github/matchers/tap.json" + - name: Test - + run: npm test --ignore-scripts -iwr + + run: npm test --ignore-scripts To correct it: npx template-oss-apply --force diff --git a/test/apply/release.js b/test/apply/release.js index 159c8300..80a267b1 100644 --- a/test/apply/release.js +++ b/test/apply/release.js @@ -6,9 +6,9 @@ t.test('no workspace flags in commands', async (t) => { const s = await setup(t) await s.apply() - const release = await s.readFile(join('.github', 'workflows', 'release.yml')) + const release = await s.readFile(join('.github', 'workflows', 'ci-release.yml')) - t.match(release, '--ignore-scripts --if-present\n') + t.match(release, '--ignore-scripts\n') t.notMatch(release, '--ignore-scripts -ws -iwr --if-present\n') }) @@ -20,8 +20,8 @@ t.test('uses workspace flags in commands', async (t) => { }) await s.apply() - const release = await s.readFile(join('.github', 'workflows', 'release.yml')) + const release = await s.readFile(join('.github', 'workflows', 'ci-release.yml')) - t.notMatch(release, '--ignore-scripts --if-present\n') + t.notMatch(release, '--ignore-scripts\n') t.match(release, '--ignore-scripts -ws -iwr --if-present\n') }) From ff68fd3a4f4e1e81601bb2e6e9f82b80ad177eb2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 8 Oct 2022 06:15:22 +0000 Subject: [PATCH 10/10] chore: release 4.5.1 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 10 ++++++++++ package.json | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 7aa3d567..e91ae90f 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.5.0" + ".": "4.5.1" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 33cb08a2..9dc1b884 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [4.5.1](https://github.com/npm/template-oss/compare/v4.5.0...v4.5.1) (2022-10-08) + +### Bug Fixes + +* [`bc72b05`](https://github.com/npm/template-oss/commit/bc72b05884dc59cd5f45b6f29f3308aad0456e7a) [#230](https://github.com/npm/template-oss/pull/230) add individual workspace flag to lint step (@lukekarrys) + +### Dependencies + +* [`0ccfc17`](https://github.com/npm/template-oss/commit/0ccfc17f1c4033575cc66c67513baf85a9f2b047) [#228](https://github.com/npm/template-oss/pull/228) `@npmcli/release-please@14.2.6` + ## [4.5.0](https://github.com/npm/template-oss/compare/v4.4.5...v4.5.0) (2022-10-05) ### Features diff --git a/package.json b/package.json index 9f937b1b..1f3661c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@npmcli/template-oss", - "version": "4.5.0", + "version": "4.5.1", "description": "templated files used in npm CLI team oss projects", "main": "lib/content/index.js", "bin": {