Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update release automation scripts 4.x #3824

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/scripts/highlights.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ async function pullRequestHighlights(prs) {
if (!highlights.length) return '';

highlights.unshift('## Release Notes\n\n');
return highlights.join('\n\n');

const highlight = highlights.join('\n\n');
console.log(`Total highlight is ${highlight.length} characters long`);
return highlight;
}

console.log('List of PRs to collect highlights from:', prs);
Expand Down
12 changes: 8 additions & 4 deletions .github/scripts/pr_list.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ const historyFilePath = path.join(__dirname, '..', '..', 'HISTORY.md');
*/
function parsePRList(history) {
const prRegexp = /node-mongodb-native\/issues\/(?<prNum>\d+)\)/iu;
return history
.split('\n')
.map(line => prRegexp.exec(line)?.groups?.prNum ?? '')
.filter(prNum => prNum !== '');
return Array.from(
new Set(
history
.split('\n')
.map(line => prRegexp.exec(line)?.groups?.prNum ?? '')
.filter(prNum => prNum !== '')
)
);
}

const historyContents = await fs.readFile(historyFilePath, { encoding: 'utf8' });
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/release-4.x.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
on:
push:
branches: [4.x]
workflow_dispatch: {}

permissions:
contents: write
pull-requests: write
id-token: write

name: release-4x

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- id: release
uses: google-github-actions/release-please-action@v3
with:
release-type: node
package-name: mongodb
# Example: chore(main): release 5.7.0 [skip-ci]
# ${scope} - parenthesis included, base branch name
pull-request-title-pattern: 'chore${scope}: release ${version} [skip-ci]'
pull-request-header: 'Please run the release_notes action before releasing to generate release highlights'
changelog-path: HISTORY.md
default-branch: 4.x

# If release-please created a release, publish to npm
- if: ${{ steps.release.outputs.release_created }}
uses: actions/checkout@v3
- if: ${{ steps.release.outputs.release_created }}
name: actions/setup
uses: ./.github/actions/setup
- if: ${{ steps.release.outputs.release_created }}
run: npm publish --provenance --tag=4x
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
48 changes: 48 additions & 0 deletions .github/workflows/release_notes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: release_notes

on:
workflow_dispatch:
inputs:
releasePr:
description: 'Enter release PR number'
required: true
type: number

jobs:
release_notes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: actions/setup
uses: ./.github/actions/setup

# See: https://github.com/googleapis/release-please/issues/1274

# Get the PRs that are in this release
# Outputs a list of comma seperated PR numbers, parsed from HISTORY.md
- id: pr_list
run: node .github/scripts/pr_list.mjs
env:
GITHUB_TOKEN: ${{ github.token }}

# From the list of PRs, gather the highlight sections of the PR body
# output JSON with "highlights" key (to preserve newlines)
- id: highlights
run: node .github/scripts/highlights.mjs
env:
GITHUB_TOKEN: ${{ github.token }}
PR_LIST: ${{ steps.pr_list.outputs.pr_list }}

# The combined output is available
- id: release_notes
run: node .github/scripts/release_notes.mjs
env:
GITHUB_TOKEN: ${{ github.token }}
HIGHLIGHTS: ${{ steps.highlights.outputs.highlights }}

# Update the release PR body
- run: gh pr edit ${{ inputs.releasePr }} --body-file ${{ steps.release_notes.outputs.release_notes_path }}
shell: bash
env:
GITHUB_TOKEN: ${{ github.token }}