Skip to content

Prepare for release #1

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

Merged
merged 3 commits into from
Oct 19, 2022
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
73 changes: 73 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -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<<EOF" >> $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 }}
6 changes: 3 additions & 3 deletions .github/workflows/release-insiders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions scripts/release-notes.js
Original file line number Diff line number Diff line change
@@ -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}`)
}