From d082e8cc1cb630080db4616ec4cda017b68fce29 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 19 Oct 2022 14:47:20 +0200 Subject: [PATCH 1/3] add script to get the release notes Usage: ```sh npm run release-notes # Gets notes for current version npm run release-notes 1.2.3 # Gets notes for explicit version ``` --- package.json | 3 ++- scripts/release-notes.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 scripts/release-notes.js diff --git a/package.json b/package.json index 57c0b13..d3c2861 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "build": "npm run swcify", "dev": "npm run swcify -- --watch", "postbuild": "tsc --emitDeclarationOnly", - "prepublishOnly": "npm run build" + "prepublishOnly": "npm run build", + "release-notes": "node ./scripts/release-notes.js" }, "prettier": { "printWidth": 100, diff --git a/scripts/release-notes.js b/scripts/release-notes.js new file mode 100644 index 0000000..97feef8 --- /dev/null +++ b/scripts/release-notes.js @@ -0,0 +1,16 @@ +let path = require('path') +let fs = require('fs') + +let version = process.argv[2] || require('../package.json').version +let changelog = fs.readFileSync(path.resolve(__dirname, '..', 'CHANGELOG.md'), 'utf8') +let match = new RegExp( + `## \\[${version}\\] - (.*)\\n\\n([\\s\\S]*?)\\n(?:(?:##\\s)|(?:\\[))`, + 'g' +).exec(changelog) + +if (match) { + let [, date, notes] = match + console.log(notes.trim()) +} else { + console.log(`Placeholder release notes for version: v${version}`) +} From f019d29b2a183e01dbb7a1a5a088f72a852ddf08 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 19 Oct 2022 14:48:36 +0200 Subject: [PATCH 2/3] add actions for preparing a release, and releasing a release The `prepare release` will be executed when a tag is pushed. It does the following things: 1. Checks out the repo 2. Installs the dependencies 3. Runs the tests 4. Creates a draft release on GitHub with the release notes pre-filled based on the `CHANGELOG.md` file of the current version. Once you publish the actual release on GitHub, the `release` action will run. This will execute the following steps: 1. Checks out the repo 2. Installs the dependencies 3. Runs the tests as a sanity check 4. Published the current version to npm --- .github/workflows/prepare-release.yml | 73 +++++++++++++++++++++++++++ .github/workflows/release.yml | 56 ++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 .github/workflows/prepare-release.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml new file mode 100644 index 0000000..0ec76a4 --- /dev/null +++ b/.github/workflows/prepare-release.yml @@ -0,0 +1,73 @@ +name: Prepare Release + +on: + workflow_dispatch: + push: + tags: + - 'v*' + +env: + CI: true + +permissions: + contents: read + +jobs: + prepare: + permissions: + contents: write # for softprops/action-gh-release to create GitHub release + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14] + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + registry-url: 'https://registry.npmjs.org' + # cache: 'npm' + # + # - name: Use cached node_modules + # id: cache + # uses: actions/cache@v3 + # with: + # path: node_modules + # key: nodeModules-${{ hashFiles('**/package-lock.json') }}-${{ matrix.node-version }} + # restore-keys: | + # nodeModules- + + - name: Resolve version + id: vars + run: | + echo "TAG_NAME=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV + + - name: Get release notes + run: | + RELEASE_NOTES=$(npm run release-notes --silent) + echo "RELEASE_NOTES<> $GITHUB_ENV + echo "$RELEASE_NOTES" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - name: Install dependencies + # if: steps.cache.outputs.cache-hit != 'true' + run: npm install + env: + CI: true + + - name: Test + run: npm test + env: + CI: true + + - name: Release + uses: softprops/action-gh-release@v1 + with: + draft: true + tag_name: ${{ env.TAG_NAME }} + body: ${{ env.RELEASE_NOTES }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3b2d786 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +name: Release + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14] + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + registry-url: 'https://registry.npmjs.org' + # cache: 'npm' + # + # - name: Use cached node_modules + # id: cache + # uses: actions/cache@v3 + # with: + # path: node_modules + # key: nodeModules-${{ hashFiles('**/package-lock.json') }}-${{ matrix.node-version }} + # restore-keys: | + # nodeModules- + + - name: Install dependencies + # if: steps.cache.outputs.cache-hit != 'true' + run: npm install + env: + CI: true + + - name: Test + run: npm test + env: + CI: true + + - name: Calculate environment variables + run: | + echo "TAG_NAME=$(npm run calculate-tag-name --silent)" >> $GITHUB_ENV + + - name: Publish + run: npm publish --tag ${{ env.TAG_NAME }} + env: + CI: true + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} From c71c9cf5e9b83e7a1e3943ab536dc9db8a347f0d Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 19 Oct 2022 15:02:21 +0200 Subject: [PATCH 3/3] use `SHA_SHORT` for env variables --- .github/workflows/release-insiders.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release-insiders.yml b/.github/workflows/release-insiders.yml index bd8daee..c6ced95 100644 --- a/.github/workflows/release-insiders.yml +++ b/.github/workflows/release-insiders.yml @@ -39,10 +39,10 @@ jobs: - name: Resolve version id: vars run: | - echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - - name: "Version based on commit: 0.0.0-insiders.${{ env.sha_short }}" - run: npm version 0.0.0-insiders.${{ env.sha_short }} --force --no-git-tag-version + - name: "Version based on commit: 0.0.0-insiders.${{ env.SHA_SHORT }}" + run: npm version 0.0.0-insiders.${{ env.SHA_SHORT }} --force --no-git-tag-version - name: Publish run: npm publish --tag insiders