Skip to content

Commit

Permalink
feat: use custom release please script (#174)
Browse files Browse the repository at this point in the history
* feat: use custom release please script

* fix: install commitlint deps to package.json

* fix: add breaking changes to changelog notes

* chore: add tap timeout

* fix: allow git installs for required packages

* fix: use actions/checkout for pull requests and make setup deps partial

* fix: pass token to release please

* fix: check out headRefName from release please PR

* fix: allow release please to pass in branch name for testing

* fix: add node-workspace plugin

* fix: branch name typo

* feat: exclude other package commits from root

* feat: call release-test workflow after updating release PR

* fix: checkout head ref for dependabot

* feat: add change default versioning strategy

* feat: rewrite workspace deps

* fix: use release please fork

* fix: only write release test file if necessary

* fix: set release please title patterns
  • Loading branch information
lukekarrys authored Aug 31, 2022
1 parent 8e4e66d commit 7562777
Show file tree
Hide file tree
Showing 33 changed files with 1,260 additions and 128 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.local.js

This file was deleted.

6 changes: 6 additions & 0 deletions .eslintrc.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ignorePatterns": [
"lib/content/*",
"!lib/content/index.js"
]
}
2 changes: 0 additions & 2 deletions .github/settings.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
if: ${{ !startsWith(matrix.node-version, '10.') }}
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- run: npm i --ignore-scripts --no-audit --no-fund
- name: add tap problem matcher
run: echo "::add-matcher::.github/matchers/tap.json"
- run: npm i --ignore-scripts --no-audit --no-fund
- run: npm test --ignore-scripts
8 changes: 4 additions & 4 deletions .github/workflows/post-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
if: github.actor == 'dependabot[bot]'
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head_ref }}
- name: Setup git user
run: |
git config --global user.email "npm-cli+bot@github.com"
Expand All @@ -24,20 +26,18 @@ jobs:
- name: Update npm to latest
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- run: npm i --ignore-scripts --no-audit --no-fund
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.1.1
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: npm install and commit
- name: Apply @npmcli/template-oss changes and lint
if: contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr checkout ${{ github.event.pull_request.number }}
npm install --ignore-scripts --no-audit --no-fund
npm run template-oss-apply
git add .
git commit -am "chore: postinstall for dependabot template-oss PR"
git push
npm run lint
5 changes: 2 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ jobs:
- name: Update npm to latest
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- name: Install deps
run: npm i -D @commitlint/cli @commitlint/config-conventional
- name: Check commits OR PR title
- run: npm i --ignore-scripts --no-audit --no-fund
- name: Check commits or PR title
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
Expand Down
78 changes: 61 additions & 17 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,40 @@ jobs:
release-please:
runs-on: ubuntu-latest
outputs:
prs: ${{ steps.release.outputs.prs }}
pr: ${{ steps.release.outputs.pr }}
release: ${{ steps.release.outputs.release }}
steps:
- uses: google-github-actions/release-please-action@v3
id: release
- uses: actions/checkout@v3
- name: Setup git user
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- uses: actions/setup-node@v3
with:
command: manifest
node-version: 16.x
- name: Update npm to latest
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- run: npm i --ignore-scripts --no-audit --no-fund
- name: Release Please
id: release
run: npx --offline template-oss-release-please
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

update-prs:
post-pr:
needs: release-please
if: needs.release-please.outputs.prs
if: needs.release-please.outputs.pr
runs-on: ubuntu-latest
strategy:
matrix:
pr: ${{ fromJSON(needs.release-please.outputs.prs) }}
outputs:
ref: ${{ steps.ref.outputs.branch }}
steps:
- name: Output ref
id: ref
run: echo "::set-output name=branch::${{ fromJSON(needs.release-please.outputs.pr).headBranchName }}"
- uses: actions/checkout@v3
with:
ref: ${{ steps.ref.outputs.branch }}
- name: Setup git user
run: |
git config --global user.email "npm-cli+bot@github.com"
Expand All @@ -42,15 +60,41 @@ jobs:
- name: Update npm to latest
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- name: Update PR ${{ matrix.pr.number }} dependencies and commit
- run: npm i --ignore-scripts --no-audit --no-fund
- name: Post pull request actions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr checkout ${{ matrix.pr.number }}
npm run resetdeps
title="${{ matrix.pr.title }}"
# get the dependency spec from the pr title
# get everything after ': release ' + replace space with @
dep_spec=$(echo "${title##*: release }" | tr ' ' @)
git commit -am "deps: $dep_spec"
npm run rp-pull-request --ignore-scripts --if-present -ws -iwr
git commit -am "chore: post pull request" || true
git push
release-test:
needs: post-pr
if: needs.post-pr.outputs.ref
uses: ./.github/workflows/release-test.yml
with:
ref: ${{ needs.post-pr.outputs.ref }}

post-release:
needs: release-please
if: needs.release-please.outputs.release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup git user
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Update npm to latest
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- run: npm i --ignore-scripts --no-audit --no-fund
- name: Post release actions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm run rp-release --ignore-scripts --if-present -ws -iwr
86 changes: 86 additions & 0 deletions .github/workflows/release-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# This file is automatically added by @npmcli/template-oss. Do not edit.

name: Release

on:
workflow_call:
inputs:
ref:
required: true
type: string

jobs:
lint-all:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- name: Setup git user
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Update npm to latest
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- run: npm i --ignore-scripts --no-audit --no-fund
- run: npm run lint --if-present --workspaces --include-workspace-root

test-all:
strategy:
fail-fast: false
matrix:
node-version:
- 12.13.0
- 12.x
- 14.15.0
- 14.x
- 16.0.0
- 16.x
platform:
- os: ubuntu-latest
shell: bash
- os: macos-latest
shell: bash
- os: windows-latest
shell: cmd
runs-on: ${{ matrix.platform.os }}
defaults:
run:
shell: ${{ matrix.platform.shell }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- name: Setup git user
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Update to workable npm (windows)
# node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows
if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12.') || startsWith(matrix.node-version, '14.'))
run: |
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
tar xf npm-7.5.4.tgz
cd package
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
cd ..
rmdir /s /q package
- name: Update npm to 7
# If we do test on npm 10 it needs npm7
if: startsWith(matrix.node-version, '10.')
run: npm i --prefer-online --no-fund --no-audit -g npm@7
- name: Update npm to latest
if: ${{ !startsWith(matrix.node-version, '10.') }}
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- run: npm i --ignore-scripts --no-audit --no-fund
- name: add tap problem matcher
run: echo "::add-matcher::.github/matchers/tap.json"
- run: npm run test --if-present --workspaces --include-workspace-root
31 changes: 31 additions & 0 deletions bin/release-please.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env node

const core = require('@actions/core')
const main = require('../lib/release-please/index.js')

const dryRun = !process.env.CI
const [branch] = process.argv.slice(2)

const setOutput = (key, val) => {
if (val && (!Array.isArray(val) || val.length)) {
if (dryRun) {
console.log(key, JSON.stringify(val, null, 2))
} else {
core.setOutput(key, JSON.stringify(val))
}
}
}

main({
token: process.env.GITHUB_TOKEN,
repo: process.env.GITHUB_REPOSITORY,
dryRun,
branch,
}).then(({ pr, releases, release }) => {
setOutput('pr', pr)
setOutput('releases', releases)
setOutput('release', release)
return null
}).catch(err => {
core.setFailed(`failed: ${err}`)
})
2 changes: 1 addition & 1 deletion lib/content/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ jobs:
steps:
{{> setupGit}}
{{> setupNode}}
- run: npm i --ignore-scripts --no-audit --no-fund --package-lock
{{> setupDeps flags="--package-lock"}}
- run: npm audit
4 changes: 2 additions & 2 deletions lib/content/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
steps:
{{> setupGit}}
{{> setupNode}}
- run: npm i --ignore-scripts --no-audit --no-fund
{{> setupDeps}}
- run: npm run lint {{~#if isWorkspace}} -w {{pkgName}}{{/if}}

test:
Expand All @@ -55,7 +55,7 @@ jobs:
steps:
{{> setupGit}}
{{> setupNode useMatrix=true}}
{{> setupDeps}}
- name: add tap problem matcher
run: echo "::add-matcher::.github/matchers/tap.json"
- run: npm i --ignore-scripts --no-audit --no-fund
- run: npm test --ignore-scripts {{~#if isWorkspace}} -w {{pkgName}}{{/if}}
9 changes: 9 additions & 0 deletions lib/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const releasePlease = () => ({
file: 'release-please.yml',
filter: (o) => !o.pkg.private,
},
'.github/workflows/release-test.yml': {
file: 'release-test.yml',
filter: (o) => !o.pkg.private && o.config.releaseTest === 'release-test.yml',
},
'.release-please-manifest.json': {
file: 'release-please-manifest.json',
filter: (o) => !o.pkg.private,
Expand Down Expand Up @@ -92,6 +96,11 @@ module.exports = {
workspaceModule,
windowsCI: true,
branches: ['main', 'latest'],
defaultBranch: 'main',
// Escape hatch since we write a release test file but the
// CLI has a very custom one we dont want to overwrite. This
// setting allows us to call a workflow by any name during release
releaseTest: 'release-test.yml',
distPaths: ['bin/', 'lib/'],
ciVersions: ['12.13.0', '12.x', '14.15.0', '14.x', '16.0.0', '16.x'],
lockfile: false,
Expand Down
8 changes: 3 additions & 5 deletions lib/content/post-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@ jobs:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
{{> setupGit}}
{{> setupGit with=(obj ref="${{ github.event.pull_request.head_ref }}")}}
{{> setupNode}}
{{> setupDeps}}
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.1.1
with:
github-token: "$\{{ secrets.GITHUB_TOKEN }}"
- name: npm install and commit
- name: Apply {{__NAME__}} changes and lint
if: contains(steps.metadata.outputs.dependency-names, '{{__NAME__}}')
env:
GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }}
run: |
gh pr checkout $\{{ github.event.pull_request.number }}
npm install --ignore-scripts --no-audit --no-fund
npm run template-oss-apply
git add .
git commit -am "chore: postinstall for dependabot template-oss PR"
git push
npm run lint
7 changes: 3 additions & 4 deletions lib/content/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ jobs:
steps:
{{> setupGit with=(obj fetch-depth=0)}}
{{> setupNode}}
- name: Install deps
run: npm i -D @commitlint/cli @commitlint/config-conventional
- name: Check commits OR PR title
{{> setupDeps}}
- name: Check commits or PR title
env:
PR_TITLE: $\{{ github.event.pull_request.title }}
run: |
npx --offline commitlint -V --from origin/main --to $\{{ github.event.pull_request.head.sha }} \
npx --offline commitlint -V --from origin/{{defaultBranch}} --to $\{{ github.event.pull_request.head.sha }} \
|| echo $PR_TITLE | npx --offline commitlint -V
15 changes: 8 additions & 7 deletions lib/content/release-please-config.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"separate-pull-requests": true,
"changelog-sections": [
{"type":"feat","section":"Features","hidden":false},
{"type":"fix","section":"Bug Fixes","hidden":false},
{"type":"docs","section":"Documentation","hidden":false},
{"type":"deps","section":"Dependencies","hidden":false},
{"type":"chore","hidden":true}
"separate-pull-requests": {{{del}}},
"plugins": [
"node-workspace",
"workspace-deps"
],
"exclude-packages-from-root": true,
"group-pull-request-title-pattern": "chore: release ${version}",
"pull-request-title-pattern": "chore: release${component} ${version}",
"changelog-sections": {{{json changelogTypes}}},
"packages": {
"{{#unless pkgRelPath}}.{{/unless}}{{pkgRelPath}}": {
{{#unless pkgRelPath}}"package-name": ""{{/unless}}
Expand Down
Loading

0 comments on commit 7562777

Please sign in to comment.