chore: automate tag on release (#8366)

This commit is contained in:
jrandolf 2022-05-19 13:26:42 +02:00 committed by GitHub
parent b2e82eece6
commit f5f8d16947
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 4 deletions

View File

@ -8,7 +8,8 @@ on:
jobs:
publish:
runs-on: ubuntu-latest
permissions: read-all
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
@ -40,8 +41,7 @@ jobs:
needs: publish
runs-on: ubuntu-latest
permissions:
actions: read|write
contents: read|write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3

View File

@ -6,7 +6,7 @@ jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: read|write
contents: write
pull-requests: write
steps:
- name: Checkout

30
.github/workflows/tag-on-release.yml vendored Normal file
View File

@ -0,0 +1,30 @@
name: tag-on-release
on:
pull_request:
types:
- closed
branches:
- 'releases/**'
jobs:
tag:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get version
id: get-version
run: |
echo ::set-output name=VERSION::$(jq -r .version ./package.json)
- name: Generate latest changelog
run: node utils/get_latest_changelog.js > ${{ steps.get-version.outputs.VERSION }}-CHANGELOG.txt
- name: Tag and release
uses: softprops/action-gh-release@v1
with:
name: ${{ steps.get-version.outputs.VERSION }}
tag_name: v${{ steps.get-version.outputs.VERSION }}
body_path: ${{ steps.get-version.outputs.VERSION }}-CHANGELOG.txt

34
utils/get_latest_changelog.js Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env node
(async () => {
const { createReadStream } = require('fs');
const { join } = require('path');
const { createInterface } = require('readline');
const lines = [];
let isRecording = false;
for await (const line of createInterface({
input: createReadStream(join(__dirname, '../CHANGELOG.md'), {
encoding: 'utf-8',
}),
})) {
if (line.startsWith('## ')) {
if (!isRecording) {
isRecording = true;
continue;
} else {
break;
}
}
if (isRecording) {
lines.push(line);
}
}
if (lines.length === 0) {
throw new Error('Latest changelog should be non-empty.');
}
console.log(lines.join('\n').trim());
})();