Skip to content

Commit

Permalink
chore: automate tag on release (#8366)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed May 19, 2022
1 parent b2e82ee commit f5f8d16
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish-on-tag.yml
Expand Up @@ -8,7 +8,8 @@ on:
jobs:
publish:
runs-on: ubuntu-latest
permissions: read-all
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Expand Up @@ -6,7 +6,7 @@ jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: read|write
contents: write
pull-requests: write
steps:
- name: Checkout
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/tag-on-release.yml
@@ -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 changes: 34 additions & 0 deletions utils/get_latest_changelog.js
@@ -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());
})();

0 comments on commit f5f8d16

Please sign in to comment.