Skip to content

Commit

Permalink
fix: dont release specific apply changes based on public/private
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Oct 25, 2022
1 parent 3d7e5e8 commit 9bdad61
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 19 deletions.
13 changes: 12 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,28 @@ const getFullConfig = async ({
// some cases. the workspaces passed in have already been run through map workspaces
const workspacePaths = (pkgJson.workspaces || []).map(deglob)

const isPrivate = !!pkgJson.private
const isPublic = !isPrivate
const publicPkgs = pkgs.filter(p => !p.pkgJson.private)
const allPrivate = pkgs.every(p => p.pkgJson.private)

// all derived keys
const derived = {
isRoot,
isWorkspace,
isMono,
// 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,
isMono,
// public/private
isPublic,
isPrivate,
allPrivate,
// controls whether we are in a monorepo with any public workspaces
isMonoPublic: isMono && !!publicPkgs.filter(p => p.path !== root).length,
// repo
repoDir: root,
repoFiles,
Expand Down
36 changes: 24 additions & 12 deletions lib/content/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { name: NAME, version: LATEST_VERSION } = require('../../package.json')

const isPublic = (p) => !p.pkg.private
const isPublic = (p) => p.config.isPublic

const sharedRoot = (name) => ({
const sharedRootAdd = (name) => ({
// release
'.github/workflows/release.yml': {
file: 'release.yml',
Expand All @@ -26,6 +26,11 @@ const sharedRoot = (name) => ({
comment = null
},
},
// this lint commits which is only necessary for releases
'.github/workflows/pull-request.yml': {
file: 'pull-request.yml',
filter: isPublic,
},
// ci
'.github/matchers/tap.json': 'tap.json',
[`.github/workflows/ci${name ? `-${name}` : ''}.yml`]: 'ci.yml',
Expand All @@ -46,6 +51,12 @@ const sharedRoot = (name) => ({
},
})

const sharedRootRm = () => ({
'.github/workflows/pull-request.yml': {
filter: (p) => p.config.allPrivate,
},
})

// Changes applied to the root of the repo
const rootRepo = {
add: {
Expand All @@ -55,13 +66,13 @@ const rootRepo = {
'.github/CODEOWNERS': 'CODEOWNERS',
'.github/workflows/audit.yml': 'audit.yml',
'.github/workflows/codeql-analysis.yml': 'codeql-analysis.yml',
'.github/workflows/pull-request.yml': 'pull-request.yml',
...sharedRoot(),
...sharedRootAdd(),
},
rm: {
'.github/workflows/release-test.yml': true,
'.github/workflows/release-please.yml': true,
...sharedRootRm(),
},
rm: [
'.github/workflows/release-test.yml',
'.github/workflows/release-please.yml',
],
}

// These are also applied to the root of the repo
Expand All @@ -86,12 +97,13 @@ const rootModule = {
// Changes for each workspace but applied to the root of the repo
const workspaceRepo = {
add: {
...sharedRoot('{{ pkgNameFs }}'),
...sharedRootAdd('{{ pkgNameFs }}'),
},
rm: [
rm: {
// These are the old release please files that should be removed now
'.github/workflows/release-please-{{ pkgNameFs }}.yml',
],
'.github/workflows/release-please-{{ pkgNameFs }}.yml': true,
...sharedRootRm(),
},
}

// Changes for each workspace but applied to the relative workspace dir
Expand Down
2 changes: 1 addition & 1 deletion lib/content/release-please-config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"separate-pull-requests": {{{ del }}},
"plugins": {{#if isMono }}["node-workspace"]{{ else }}{{{ del }}}{{/if}},
"plugins": {{#if isMonoPublic }}["node-workspace"]{{ else }}{{{ del }}}{{/if}},
"exclude-packages-from-root": true,
"group-pull-request-title-pattern": "chore: release ${version}",
"pull-request-title-pattern": "chore: release${component} ${version}",
Expand Down
9 changes: 8 additions & 1 deletion lib/util/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ const getParsers = (dir, files, options) => {
}

const getRemovals = async (dir, files, options) => {
const targets = fileEntries(dir, files, options).map(([t]) => globify(t))
const targets = fileEntries(dir, files, options)
.filter(([, source]) => {
if (typeof source === 'object' && typeof source.filter === 'function') {
return source.filter(options)
}
return true
})
.map(([t]) => globify(t))
const globs = await Promise.all(targets.map(t => glob(t, { cwd: dir })))
return globs.flat()
}
Expand Down
5 changes: 1 addition & 4 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@
},
"exclude-packages-from-root": true,
"group-pull-request-title-pattern": "chore: release ${version}",
"pull-request-title-pattern": "chore: release${component} ${version}",
"plugins": [
"node-workspace"
]
"pull-request-title-pattern": "chore: release${component} ${version}"
}
2 changes: 2 additions & 0 deletions tap-snapshots/test/apply/files-snapshots.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ exports[`test/apply/files-snapshots.js TAP workspaces > expect resolving Promise
.github/workflows/ci-d.yml
.github/workflows/ci-release.yml
.github/workflows/post-dependabot.yml
.github/workflows/pull-request.yml
.github/workflows/release.yml
.release-please-manifest.json
package.json
Expand All @@ -141,6 +142,7 @@ exports[`test/apply/files-snapshots.js TAP workspaces only (like npm/cli) > expe
.github/workflows/ci-b.yml
.github/workflows/ci-release.yml
.github/workflows/post-dependabot.yml
.github/workflows/pull-request.yml
.github/workflows/release.yml
.release-please-manifest.json
package.json
Expand Down
51 changes: 51 additions & 0 deletions tap-snapshots/test/apply/source-snapshots.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3758,6 +3758,57 @@ jobs:
echo "for more information on how to fix this with a BREAKING CHANGE footer."
exit 1
.github/workflows/pull-request.yml
========================================
# This file is automatically added by @npmcli/template-oss. Do not edit.
name: Pull Request
on:
pull_request:
types:
- opened
- reopened
- edited
- synchronize
jobs:
commitlint:
name: Lint Commits
if: github.repository_owner == 'npm'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Install npm@latest
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- name: npm Version
run: npm -v
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Run Commitlint on Commits
id: commit
continue-on-error: true
run: |
npx --offline commitlint -V --from origin/\${{ github.base_ref }} --to \${{ github.event.pull_request.head.sha }}
- name: Run Commitlint on PR Title
if: steps.commit.outcome == 'failure'
run: |
echo \${{ github.event.pull_request.title }} | npx --offline commitlint -V
.github/workflows/release.yml
========================================
# This file is automatically added by @npmcli/template-oss. Do not edit.
Expand Down
2 changes: 2 additions & 0 deletions tap-snapshots/test/check/snapshots.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ The following repo files need to be added:
.github/workflows/ci-name-aaaa.yml
.github/workflows/ci-release.yml
.github/workflows/post-dependabot.yml
.github/workflows/pull-request.yml
.github/workflows/release.yml
.release-please-manifest.json
release-please-config.json
Expand Down Expand Up @@ -438,6 +439,7 @@ The following repo files need to be added:
.github/workflows/ci-bbb.yml
.github/workflows/ci-release.yml
.github/workflows/post-dependabot.yml
.github/workflows/pull-request.yml
.github/workflows/release.yml
.release-please-manifest.json
release-please-config.json
Expand Down
36 changes: 36 additions & 0 deletions test/apply/release-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const t = require('tap')
const setup = require('../setup.js')

t.test('no plugin for root only', async (t) => {
const s = await setup(t)
await s.apply()

const releaseConfig = await s.readJson('release-please-config.json')
t.equal(releaseConfig.plugins, undefined)
})

t.test('has plugin for workspace', async (t) => {
const s = await setup(t, {
workspaces: {
a: 'a',
},
})
await s.apply()

const releaseConfig = await s.readJson('release-please-config.json')
t.strictSame(releaseConfig.plugins, ['node-workspace'])
})

t.test('no plugin for private workspace', async (t) => {
const s = await setup(t, {
workspaces: {
a: {
private: true,
},
},
})
await s.apply()

const releaseConfig = await s.readJson('release-please-config.json')
t.equal(releaseConfig.plugins, undefined)
})

0 comments on commit 9bdad61

Please sign in to comment.