Skip to content

Commit

Permalink
fix: update a few release nits after trying it on the cli
Browse files Browse the repository at this point in the history
Closes #178
  • Loading branch information
lukekarrys committed Sep 1, 2022
1 parent e851661 commit c224c7c
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 101 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release-please.yml
Expand Up @@ -49,6 +49,7 @@ jobs:
run: echo "::set-output name=branch::${{ fromJSON(needs.release-please.outputs.pr).headBranchName }}"
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ steps.ref.outputs.branch }}
- name: Setup git user
run: |
Expand Down
10 changes: 3 additions & 7 deletions lib/content/pkg.json
Expand Up @@ -6,13 +6,9 @@
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "{{npmBin}} run lint -- --fix",
"preversion": "{{npmBin}} test",
{{#if pkgPrivate}}
"postversion": "git push origin --follow-tags",
{{else}}
"postversion": "{{npmBin}} publish",
"prepublishOnly": "git push origin --follow-tags",
{{/if}}
"preversion": {{{del}}},
"postversion": {{{del}}},
"prepublishOnly": {{{del}}},
"snap": "tap",
"test": "tap",
"posttest": "{{npmBin}} run lint",
Expand Down
2 changes: 1 addition & 1 deletion lib/content/release-please.yml
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Output ref
id: ref
run: echo "::set-output name=branch::$\{{ fromJSON(needs.release-please.outputs.pr).headBranchName }}"
{{> setupGit with=(obj ref="${{ steps.ref.outputs.branch }}")}}
{{> setupGit with=(obj ref="${{ steps.ref.outputs.branch }}" fetch-depth=0)}}
{{> setupNode}}
{{> setupDeps}}
- name: Post pull request actions
Expand Down
99 changes: 61 additions & 38 deletions lib/release-please/workspace-deps.js
@@ -1,4 +1,6 @@
const { ManifestPlugin } = require('release-please/build/src/plugin')
const { Changelog } = require('release-please/build/src/updaters/changelog.js')
const { PackageJson } = require('release-please/build/src/updaters/node/package-json.js')

const matchLine = (line, re) => {
const trimmed = line.trim().replace(/^[*\s]+/, '')
Expand All @@ -10,61 +12,82 @@ const matchLine = (line, re) => {

module.exports = class WorkspaceDeps extends ManifestPlugin {
run (pullRequests) {
for (const { pullRequest } of pullRequests) {
const depLinks = pullRequest.body.releaseData.reduce((acc, release) => {
if (release.component) {
const url = matchLine(release.notes.split('\n')[0], /\[[^\]]+\]\((.*?)\)/)
if (url) {
acc[release.component] = url[1]
try {
for (const { pullRequest } of pullRequests) {
const getChangelog = (release) => pullRequest.updates.find((u) => {
const isChangelog = u.updater instanceof Changelog
const isComponent = release.component && u.path.startsWith(release.component)
const isRoot = !release.component && !u.path.includes('/')
return isChangelog && (isComponent || isRoot)
})

const getComponent = (pkgName) => pullRequest.updates.find((u) => {
const isPkg = u.updater instanceof PackageJson
return isPkg && JSON.parse(u.updater.rawContent).name === pkgName
}).path.replace(/\/package\.json$/, '')

const depLinksByComponent = pullRequest.body.releaseData.reduce((acc, release) => {
if (release.component) {
const url = matchLine(release.notes.split('\n')[0], /\[[^\]]+\]\((.*?)\)/)
if (url) {
acc[release.component] = url[1]
}
}
}
return acc
}, {})
return acc
}, {})

for (const release of pullRequest.body.releaseData) {
const lines = release.notes.split('\n')
const newLines = []
for (const release of pullRequest.body.releaseData) {
const lines = release.notes.split('\n')
const newLines = []

let inWorkspaceDeps = false
let collectWorkspaceDeps = false
let inWorkspaceDeps = false
let collectWorkspaceDeps = false

for (const line of lines) {
if (matchLine(line, 'The following workspace dependencies were updated')) {
for (const line of lines) {
if (matchLine(line, 'The following workspace dependencies were updated')) {
// We are in the section with our workspace deps
// Set the flag and discard this line since we dont want it in the final output
inWorkspaceDeps = true
} else if (inWorkspaceDeps) {
if (collectWorkspaceDeps) {
const depMatch = matchLine(line, /^(\S+) bumped from \S+ to (\S+)$/)
if (depMatch) {
inWorkspaceDeps = true
} else if (inWorkspaceDeps) {
if (collectWorkspaceDeps) {
const depMatch = matchLine(line, /^(\S+) bumped from \S+ to (\S+)$/)
if (depMatch) {
// If we have a line that is a workspace dep update, then reformat
// it and save it to the new lines
const [, depName, newVersion] = depMatch
const depSpec = `\`${depName}@${newVersion}\``
const url = depLinks[depName]
newLines.push(` * ${url ? `[${depSpec}](${url})` : depSpec}`)
} else {
const [, depName, newVersion] = depMatch
const depSpec = `\`${depName}@${newVersion}\``
const url = depLinksByComponent[getComponent(depName)]
newLines.push(` * ${url ? `[${depSpec}](${url})` : depSpec}`)
} else {
// Anything else means we are done with dependencies so ignore
// this line and dont look for any more
collectWorkspaceDeps = false
}
} else if (matchLine(line, 'dependencies')) {
collectWorkspaceDeps = false
}
} else if (matchLine(line, 'dependencies')) {
// Only collect dependencies discard dev deps and everything else
collectWorkspaceDeps = true
} else if (matchLine(line, '') || matchLine(line, /^#/)) {
inWorkspaceDeps = false
collectWorkspaceDeps = true
} else if (matchLine(line, '') || matchLine(line, /^#/)) {
inWorkspaceDeps = false
newLines.push(line)
}
} else {
newLines.push(line)
}
} else {
newLines.push(line)
}
}

const newNotes = newLines.join('\n').trim()
const emptyDeps = newNotes.match(/### Dependencies[\n]+(### .*)/m)
let newNotes = newLines.join('\n').trim()
const emptyDeps = newNotes.match(/### Dependencies[\n]+(### .*)/m)
if (emptyDeps) {
newNotes = newNotes.replace(emptyDeps[0], emptyDeps[1])
}

release.notes = emptyDeps ? newNotes.replace(emptyDeps[0], emptyDeps[1]) : newNotes
release.notes = newNotes
getChangelog(release).updater.changelogEntry = newNotes
}
}
} catch {
// Always return pull requests even if we failed so
// we dont fail the release
}

return pullRequests
Expand Down
3 changes: 0 additions & 3 deletions package.json
Expand Up @@ -12,9 +12,6 @@
"lint": "eslint \"**/*.js\"",
"lintfix": "npm run lint -- --fix",
"posttest": "npm run lint",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"preversion": "npm test",
"snap": "tap",
"test": "tap",
"template-oss-apply": "template-oss-apply --force",
Expand Down
21 changes: 3 additions & 18 deletions tap-snapshots/test/apply/full-content.js.test.cjs
Expand Up @@ -470,6 +470,7 @@ jobs:
run: echo "::set-output name=branch::\${{ fromJSON(needs.release-please.outputs.pr).headBranchName }}"
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: \${{ steps.ref.outputs.branch }}
- name: Setup git user
run: |
Expand Down Expand Up @@ -678,9 +679,6 @@ package.json
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"snap": "tap",
"test": "tap",
"posttest": "npm run lint"
Expand Down Expand Up @@ -1398,6 +1396,7 @@ jobs:
run: echo "::set-output name=branch::\${{ fromJSON(needs.release-please.outputs.pr).headBranchName }}"
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: \${{ steps.ref.outputs.branch }}
- name: Setup git user
run: |
Expand Down Expand Up @@ -1613,9 +1612,6 @@ package.json
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"snap": "tap",
"test": "tap",
"posttest": "npm run lint"
Expand Down Expand Up @@ -1737,9 +1733,6 @@ workspaces/a/package.json
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"snap": "tap",
"test": "tap",
"posttest": "npm run lint"
Expand Down Expand Up @@ -1816,9 +1809,6 @@ workspaces/b/package.json
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"snap": "tap",
"test": "tap",
"posttest": "npm run lint"
Expand Down Expand Up @@ -2117,6 +2107,7 @@ jobs:
run: echo "::set-output name=branch::\${{ fromJSON(needs.release-please.outputs.pr).headBranchName }}"
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: \${{ steps.ref.outputs.branch }}
- name: Setup git user
run: |
Expand Down Expand Up @@ -2375,9 +2366,6 @@ workspaces/a/package.json
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"snap": "tap",
"test": "tap",
"posttest": "npm run lint"
Expand Down Expand Up @@ -2450,9 +2438,6 @@ workspaces/b/package.json
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"snap": "tap",
"test": "tap",
"posttest": "npm run lint"
Expand Down
2 changes: 1 addition & 1 deletion tap-snapshots/test/check/diffs.js.test.cjs
Expand Up @@ -434,7 +434,7 @@ The module file package.json needs to be updated:
"author" is "heynow", expected "GitHub Inc."
"files[1]" is "x", expected "lib/"
"scripts.lint:fix" is "x", expected to be removed
"scripts.preversion" is "x", expected "npm test"
"scripts.preversion" is "x", expected to be removed
"standard" is {
"config": "x "
}, expected to be removed
Expand Down
12 changes: 0 additions & 12 deletions tap-snapshots/test/check/index.js.test.cjs
Expand Up @@ -61,9 +61,6 @@ The module file package.json needs to be updated:
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"snap": "tap",
"test": "tap",
"posttest": "npm run lint"
Expand Down Expand Up @@ -144,9 +141,6 @@ The module file package.json needs to be updated:
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"snap": "tap",
"test": "tap",
"posttest": "npm run lint"
Expand Down Expand Up @@ -209,9 +203,6 @@ The module file package.json needs to be updated:
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"snap": "tap",
"test": "tap",
"posttest": "npm run lint"
Expand Down Expand Up @@ -274,9 +265,6 @@ The module file package.json needs to be updated:
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"snap": "tap",
"test": "tap",
"posttest": "npm run lint"
Expand Down
9 changes: 3 additions & 6 deletions test/apply/index.js
Expand Up @@ -113,13 +113,10 @@ t.test('private workspace', async (t) => {
const rpManifest = await s.readJson('.release-please-manifest.json')
const rpConfig = await s.readJson('release-please-config.json')

t.ok(pkg.scripts.prepublishOnly)
t.ok(pkg.scripts.postversion)

t.notOk(pkg.scripts.prepublishOnly)
t.notOk(pkg.scripts.postversion)
t.notOk(privatePkg.scripts.prepublishOnly)
t.ok(privatePkg.scripts.postversion)

t.equal(pkg.scripts.prepublishOnly, privatePkg.scripts.postversion)
t.notOk(privatePkg.scripts.postversion)

t.equal(rpManifest['.'], '1.0.0')
t.equal(rpManifest['workspaces/b'], '1.0.0')
Expand Down

0 comments on commit c224c7c

Please sign in to comment.