-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Release CI & change release flow (#256)
* add release ci test changelog ci add changelog ci add release ci * fix typo & add npm i * set config before run changelog ci * fix git push error
- Loading branch information
Showing
6 changed files
with
158 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Changelog CI | ||
|
||
# Controls when the action will run. Triggers the workflow on a pull request | ||
on: | ||
pull_request: | ||
# types: [opened, reopened] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.event.pull_request.head.ref }} | ||
fetch-depth: 0 | ||
- name: Install Dependency | ||
run: npm i | ||
|
||
- name: Config Internal Git | ||
run: | | ||
git config --global user.email "action@github.com" | ||
git config --global user.name "GitHub Action" | ||
- name: Run Changelog CI & Bump npm version | ||
if: ${{ startsWith(github.event.pull_request.title, 'Release') }} | ||
run: npm run generate-changelog | ||
|
||
- name: Copy & Deploy | ||
if: ${{ startsWith(github.event.pull_request.title, 'Release') }} | ||
run: | | ||
git add -A | ||
git commit -m '(Changelog CI) Added Changelog' | ||
git push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Release Node.js Package | ||
on: | ||
release: | ||
types: [created] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
# Setup .npmrc file to publish to GitHub Packages | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14 | ||
registry-url: 'https://registry.npmjs.org' | ||
- run: npm install | ||
- run: npm run release | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
## 7.0.0 (15 June 202) | ||
## 7.0.0 (15 June 2020) | ||
|
||
### Breaking Changes | ||
* Node.js: drop 8 & adopt 14 (#222) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { execSync } from "child_process"; | ||
import { readFileSync, writeFileSync } from "fs"; | ||
import { resolve } from "path"; | ||
const { version: lastVersion } = require("../package.json"); | ||
|
||
const changeLogPath = resolve(__dirname, "../CHANGELOG.md"); | ||
|
||
let newVersion = lastVersion; | ||
|
||
console.log("Gets Release Version from GITHUB_EVENT_PATH"); | ||
if (process.env.GITHUB_EVENT_PATH) { | ||
const { | ||
pull_request: { title }, | ||
} = require(process.env.GITHUB_EVENT_PATH); | ||
|
||
if (/^release/i.test(title)) | ||
newVersion = (title as string).match(/release ([\d\.]+)/i)[1]; | ||
else { | ||
console.log("Not target pull request, exiting"); | ||
process.exit(0); | ||
} | ||
} | ||
console.log(`New Version: ${newVersion}`); | ||
|
||
console.log("Bump Version"); | ||
execSync(`npm version ${newVersion}`); | ||
|
||
const gitLogOutput = execSync( | ||
`git log v${lastVersion}... --format=%s` | ||
).toString("utf-8"); | ||
|
||
const commitsArray = gitLogOutput | ||
.split("\n") | ||
.filter((message) => message && message !== ""); | ||
|
||
const category = { | ||
miscs: [] as string[], | ||
features: [] as string[], | ||
bugFixes: [] as string[], | ||
}; | ||
|
||
commitsArray.forEach((message) => { | ||
let cat: keyof typeof category; | ||
if (message.includes("test")) { | ||
cat = "miscs"; | ||
} else if (/(add)|(support)/i.test(message)) { | ||
cat = "features"; | ||
} else if (/fix/i.test(message)) { | ||
cat = "bugFixes"; | ||
} else { | ||
cat = "miscs"; | ||
} | ||
category[cat].push(`* ${message}`); | ||
}); | ||
|
||
const now = new Date(); | ||
const MonthText = [ | ||
"Jan", | ||
"Feb", | ||
"Mar", | ||
"Apr", | ||
"May", | ||
"Jun", | ||
"Jul", | ||
"Aug", | ||
"Sep", | ||
"Oct", | ||
"Nov", | ||
"Dec", | ||
]; | ||
let newChangelog = `## ${newVersion} (${now.getDate()} ${ | ||
MonthText[now.getMonth()] | ||
} ${now.getFullYear()}) | ||
`; | ||
|
||
if (category.features.length > 0) { | ||
newChangelog += ` | ||
### Feature | ||
${category.features.join("\n")} | ||
`; | ||
} | ||
|
||
if (category.bugFixes.length > 0) { | ||
newChangelog += ` | ||
### Bug fix | ||
${category.bugFixes.join("\n")} | ||
`; | ||
} | ||
|
||
if (category.miscs.length > 0) { | ||
newChangelog += ` | ||
### Misc | ||
${category.miscs.join("\n")} | ||
`; | ||
} | ||
|
||
const currentChangelog = readFileSync(changeLogPath, "utf-8"); | ||
|
||
writeFileSync( | ||
changeLogPath, | ||
`${newChangelog} | ||
${currentChangelog}` | ||
); |