Skip to content
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

Add Release CI & change release flow #256

Merged
merged 4 commits into from
Sep 18, 2020
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
32 changes: 32 additions & 0 deletions .github/workflows/commit-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Changelog CI

# Controls when the action will run. Triggers the workflow on a pull request
on:
pull_request:
branches:
types: [opened, reopened]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- 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
18 changes: 18 additions & 0 deletions .github/workflows/release.yml
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 }}
2 changes: 1 addition & 1 deletion CHANGELOG.md
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)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"build": "tsc",
"docs": "vuepress dev docs",
"docs:build": "vuepress build docs",
"docs:deploy": "./deploy-docs.sh",
"docs:deploy": "./scripts/deploy-docs.sh",
"generate-changelog": "ts-node ./scripts/generate-changelog.ts",
"release": "npm run build && npm publish --access public"
},
"repository": {
Expand Down
File renamed without changes.
103 changes: 103 additions & 0 deletions scripts/generate-changelog.ts
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}`
);