@npmcli/template-oss 4.9.0 → 4.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,13 +10,19 @@ const log = (...logs) => console.error('LOG', ...logs)
10
10
  const ROOT = process.cwd()
11
11
  const pkg = require(join(ROOT, 'package.json'))
12
12
 
13
+ const args = process.argv.slice(2).reduce((acc, a) => {
14
+ const [k, v] = a.replace(/^--/g, '').split('=')
15
+ acc[k] = v === 'true'
16
+ return acc
17
+ }, {})
18
+
13
19
  /* eslint-disable max-len */
14
20
  const DEFAULT_RELEASE_PROCESS = `
15
21
  1. Checkout the release branch and test
16
22
 
17
23
  \`\`\`sh
18
24
  gh pr checkout <PR-NUMBER> --force
19
- npm i
25
+ npm ${args.lockfile ? 'ci' : 'update'}
20
26
  npm test
21
27
  gh pr checks --watch
22
28
  \`\`\`
@@ -20,12 +20,12 @@
20
20
  - name: Install npm@7
21
21
  if: startsWith(matrix.node-version, '10.')
22
22
  run: npm i --prefer-online --no-fund --no-audit -g npm@7
23
- - name: Install npm@latest
23
+ - name: Install npm@{{ npmSpec }}
24
24
  if: $\{{ !startsWith(matrix.node-version, '10.') }}
25
25
  {{else}}
26
- - name: Install npm@latest
26
+ - name: Install npm@{{ npmSpec }}
27
27
  {{/if}}
28
- run: npm i --prefer-online --no-fund --no-audit -g npm@latest
28
+ run: npm i --prefer-online --no-fund --no-audit -g npm@{{ npmSpec }}
29
29
  - name: npm Version
30
30
  run: npm -v
31
31
  {{/if}}
@@ -152,6 +152,7 @@ module.exports = {
152
152
  lockfile: false,
153
153
  npm: 'npm',
154
154
  npx: 'npx',
155
+ npmSpec: 'latest',
155
156
  dependabot: 'increase-if-necessary',
156
157
  unwantedPackages: [
157
158
  'eslint',
@@ -51,9 +51,9 @@ jobs:
51
51
  const comments = await github.paginate(github.rest.issues.listComments, issue)
52
52
  let commentId = comments?.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith(body))?.id
53
53
 
54
- body += `Release workflow run: ${workflow.html_url}\n\n#### Force CI to Rerun for This Release\n\n`
55
- body += `This PR will be updated and CI will run for every non-\`chore:\` commit that is pushed to \`main\`. `
56
- body += `To force CI to rerun, run this command:\n\n`
54
+ body += `Release workflow run: ${workflow.html_url}\n\n#### Force CI to Update This Release\n\n`
55
+ body += `This PR will be updated and CI will run for every non-\`chore:\` commit that is pushed to \`{{ defaultBranch }}\`. `
56
+ body += `To force CI to update this PR, run this command:\n\n`
57
57
  body += `\`\`\`\ngh workflow run release.yml -r ${REF_NAME}\n\`\`\``
58
58
 
59
59
  if (commentId) {
@@ -82,7 +82,7 @@ jobs:
82
82
  RELEASE_COMMENT_ID: $\{{ needs.release.outputs.comment-id }}
83
83
  GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }}
84
84
  run: |
85
- {{ rootNpmPath }} exec --offline -- template-oss-release-manager
85
+ {{ rootNpmPath }} exec --offline -- template-oss-release-manager --lockfile={{ lockfile }}
86
86
  {{ rootNpmPath }} run rp-pull-request --ignore-scripts {{~#if allFlags}} {{ allFlags }}{{else}} --if-present{{/if}}
87
87
  - name: Commit
88
88
  id: commit
@@ -52,5 +52,6 @@ module.exports = (gh) => {
52
52
  pull: (number) => url('pull', number),
53
53
  commit: (sha) => url('commit', sha),
54
54
  compare: (a, b) => a ? url('compare', `${a.toString()}...${b.toString()}`) : null,
55
+ release: (tag) => url('releases', 'tag', tag.toString()),
55
56
  }
56
57
  }
@@ -29,42 +29,47 @@ const main = async ({ repo: fullRepo, token, dryRun, branch, force }) => {
29
29
  .filter(([k, v]) => k.startsWith('RELEASE_PLEASE_') && v != null)
30
30
  .map(([k, v]) => [k.replace('RELEASE_PLEASE_', ''), v])
31
31
 
32
+ const baseBranch = branch ?? github.repository.defaultBranch
33
+
32
34
  const manifest = await RP.Manifest.fromManifest(
33
35
  github,
34
- branch ?? github.repository.defaultBranch,
36
+ baseBranch,
35
37
  undefined,
36
38
  undefined,
37
39
  Object.fromEntries(manifestOverrides)
38
40
  )
39
41
 
40
- let pullRequests = []
41
- let allReleases = []
42
42
  if (force) {
43
- // If we are forcing the release CI to run again, then we get
44
- // the release PR from the repo and return it, which will trigger
45
- // the rest of the steps in the workflow to run
46
- const prNumber = await github.octokit.issues.listForRepo({
43
+ const { data: releasePrs } = await github.octokit.pulls.list({
47
44
  owner,
48
45
  repo,
49
- labels: 'autorelease: pending',
50
- per_page: 1,
51
- }).then(res => res.data[0]?.number)
52
- if (prNumber) {
53
- pullRequests = await github.octokit.pulls.get({
54
- owner,
55
- repo,
56
- pull_number: prNumber,
57
- }).then(res => [{
58
- ...res.data,
59
- headBranchName: res.data.head.ref,
60
- updates: [],
61
- }])
46
+ head: `release-please--branches--${baseBranch}`,
47
+ })
48
+
49
+ if (releasePrs.length !== 1) {
50
+ throw new Error(`Found ${releasePrs.length} matching PRs, expected 1`)
62
51
  }
63
- } else {
64
- pullRequests = await (dryRun ? manifest.buildPullRequests() : manifest.createPullRequests())
65
- allReleases = await (dryRun ? manifest.buildReleases() : manifest.createReleases())
52
+
53
+ const [releasePr] = releasePrs
54
+ const id = process.env.GITHUB_RUN_ID
55
+ ? `by https://github.com/${owner}/${repo}/actions/runs/${process.env.GITHUB_RUN_ID}`
56
+ : `manually starting at ${new Date().toJSON()}`
57
+
58
+ // XXX(hack): to get release please to recreate a pull request it needs
59
+ // to have a different body string so we append a message a message that CI
60
+ // is running. This will force release-please to rebase the PR but it
61
+ // wont update the body again, so we only append to it.
62
+ await github.octokit.pulls.update({
63
+ owner,
64
+ repo,
65
+ pull_number: releasePr.number,
66
+ body: `${releasePr.body.trim()}\n- This PR is being recreated ${id}`,
67
+ })
66
68
  }
67
69
 
70
+ const pullRequests = await (dryRun ? manifest.buildPullRequests() : manifest.createPullRequests())
71
+ const allReleases = await (dryRun ? manifest.buildReleases() : manifest.createReleases())
72
+
68
73
  // We only ever get a single pull request with our current release-please settings
69
74
  const rootPr = pullRequests.filter(Boolean)?.[0]
70
75
  if (rootPr?.number) {
@@ -99,7 +99,6 @@ module.exports = class extends NodeWorkspace {
99
99
  this.releasesByPackage.set(packageName, {
100
100
  path,
101
101
  component,
102
- currentTag: releasesByPath[path]?.tag,
103
102
  })
104
103
  }
105
104
 
@@ -139,9 +138,9 @@ module.exports = class extends NodeWorkspace {
139
138
  // Update notes with a link to each workspaces release notes
140
139
  // now that we have all of the releases in a single pull request
141
140
  release.notes = release.notes.replace(WORKSPACE_DEP, (_, depName, depVersion) => {
142
- const { currentTag, path, component } = this.releasesByPackage.get(depName)
141
+ const { path, component } = this.releasesByPackage.get(depName)
143
142
 
144
- const url = this.gh.compare(currentTag, new TagName(
143
+ const url = this.gh.release(new TagName(
145
144
  depVersion,
146
145
  component,
147
146
  this.repositoryConfig[path].tagSeparator,
@@ -5,6 +5,7 @@ const NpmPackageJson = require('@npmcli/package-json')
5
5
  const jsonParse = require('json-parse-even-better-errors')
6
6
  const Diff = require('diff')
7
7
  const { unset } = require('lodash')
8
+ const ini = require('ini')
8
9
  const template = require('./template.js')
9
10
  const jsonDiff = require('./json-diff')
10
11
  const merge = require('./merge.js')
@@ -176,9 +177,33 @@ class Js extends Base {
176
177
  }
177
178
 
178
179
  class Ini extends Base {
179
- // XXX: add merge mode for updating ini files
180
- static types = ['npmrc']
180
+ static types = ['ini']
181
181
  comment = (c) => `; ${c}`
182
+
183
+ toString (s) {
184
+ return typeof s === 'string' ? s : ini.stringify(s)
185
+ }
186
+
187
+ parse (s) {
188
+ return typeof s === 'string' ? ini.parse(s) : s
189
+ }
190
+
191
+ prepare (s, t) {
192
+ let source = s
193
+ if (typeof this.merge === 'function' && t) {
194
+ source = this.merge(t, s)
195
+ }
196
+ return super.prepare(this.toString(source))
197
+ }
198
+
199
+ diff (t, s) {
200
+ return jsonDiff(this.parse(t), this.parse(s), this.DELETE)
201
+ }
202
+ }
203
+
204
+ class IniMerge extends Ini {
205
+ static types = ['npmrc']
206
+ merge = (t, s) => merge(t, s)
182
207
  }
183
208
 
184
209
  class Markdown extends Base {
@@ -314,6 +339,7 @@ const Parsers = {
314
339
  Gitignore,
315
340
  Js,
316
341
  Ini,
342
+ IniMerge,
317
343
  Markdown,
318
344
  Yml,
319
345
  YmlMerge,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/template-oss",
3
- "version": "4.9.0",
3
+ "version": "4.11.0",
4
4
  "description": "templated files used in npm CLI team oss projects",
5
5
  "main": "lib/content/index.js",
6
6
  "bin": {
@@ -45,6 +45,7 @@
45
45
  "glob": "^8.0.1",
46
46
  "handlebars": "^4.7.7",
47
47
  "hosted-git-info": "^6.0.0",
48
+ "ini": "^3.0.1",
48
49
  "json-parse-even-better-errors": "^3.0.0",
49
50
  "just-deep-map-values": "^1.1.1",
50
51
  "just-diff": "^5.0.1",