From 0433e3a8a6c84128b6177fb75075195ff575b794 Mon Sep 17 00:00:00 2001 From: Ice Lam Date: Sat, 23 Jan 2021 12:58:14 +0800 Subject: [PATCH] ci: add github action for auto release --- .eslintrc | 12 ++++++++++- .github/workflows/release.yml | 33 +++++++++++++++++++++++++++++++ .versionrc | 3 +++ CHANGELOG.md | 2 -- package.json | 3 ++- scripts/extractLatestChangeLog.js | 16 +++++++++++++++ 6 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .versionrc create mode 100644 scripts/extractLatestChangeLog.js diff --git a/.eslintrc b/.eslintrc index fd9415c..23b4944 100644 --- a/.eslintrc +++ b/.eslintrc @@ -36,5 +36,15 @@ "ts": "never", } ] - } + }, + "overrides": [ + { + "files": ["scripts/*.js"], + "env": { "node": true }, + "rules": { + "@typescript-eslint/no-var-requires": ["off"], + "no-console": ["off"] + } + } + ] } diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..29611cb --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,33 @@ +name: Create release +on: + push: + tags: + - 'v*' + +jobs: + release: + name: Create release + runs-on: ubuntu-18.04 + + steps: + - name: Checkout repo + uses: actions/checkout@master + - name: Setup Node.js version + uses: actions/setup-node@master + with: + node-version: '12.16.1' + + - name: Generate release body + run: | + yarn extract-latest-change-log + - name: Create release + id: create-release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + draft: false + prerelease: false + body_path: RELEASE_BODY.md diff --git a/.versionrc b/.versionrc new file mode 100644 index 0000000..6795abe --- /dev/null +++ b/.versionrc @@ -0,0 +1,3 @@ +{ + "header": "# Changelog\n" +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 7972176..be4e40a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,5 @@ # Changelog -All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. - ### [1.0.1](https://github.com/icelam/html-inline-script-webpack-plugin/compare/v1.0.0...v1.0.1) (2021-01-22) diff --git a/package.json b/package.json index 939d2dd..1b3073a 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "lint": "eslint --ext .ts,js src", "prepare": "install-peers", "first-release": "npx standard-version --commit-all --tag-prefix v --first-release", - "release": "npx standard-version --commit-all --tag-prefix v" + "release": "npx standard-version --commit-all --tag-prefix v", + "extract-latest-change-log": "node scripts/extractLatestChangeLog.js" }, "author": "Ice Lam", "repository": { diff --git a/scripts/extractLatestChangeLog.js b/scripts/extractLatestChangeLog.js new file mode 100644 index 0000000..e36a49b --- /dev/null +++ b/scripts/extractLatestChangeLog.js @@ -0,0 +1,16 @@ +const fs = require('fs').promises; +const path = require('path'); + +const BASE_DIR = path.join(__dirname, '..'); +const CHANGELOG_PATH = path.join(BASE_DIR, 'CHANGELOG.md'); +const RELEASE_BODY_PATH = path.join(BASE_DIR, 'RELEASE_BODY.md'); + +(async () => { + try { + const file = await fs.readFile(CHANGELOG_PATH, 'utf8'); + const updated = /(#+ \[\d+\.\d+\.\d+].*?)#+ \[?\d+\.\d+\.\d+]?/s.exec(file); + await fs.writeFile(RELEASE_BODY_PATH, updated[1]); + } catch (error) { + console.error(error); + } +})();