Skip to content

Commit

Permalink
ci: commitlint
Browse files Browse the repository at this point in the history
  • Loading branch information
ocean-gao committed Dec 20, 2024
1 parent 4b4fe29 commit 3198bf5
Show file tree
Hide file tree
Showing 9 changed files with 2,500 additions and 56 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/release-notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env node

import { readFileSync, writeFileSync } from 'node:fs';
import process from 'node:process';

const tag = process.argv[2].replace('v', '');
const log = readFileSync('./CHANGELOG.md', { encoding: 'utf-8' }).split('\n');
let result = '';
let inScope = false;
const regex = new RegExp(`^#+ \\[${tag}`);
for (let i = 0; i < log.length; i++) {
if (regex.test(log[i])) {
inScope = true;
result += log[i];
continue;
}
if (inScope && /^#+ \[/.test(log[i])) {
inScope = false;
break;
}
if (inScope) {
result += `\n${log[i]}`;
}
}
writeFileSync(`notes-v${tag}.md`, result);
37 changes: 37 additions & 0 deletions .github/workflows/release-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

name: Create Release

# https://docs.github.com/en/actions/learn-github-actions/contexts#env-context
env:
RELEASE_VERSION: ''

jobs:
build:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@master

- name: Get the release version from the tag
shell: bash
if: env.RELEASE_VERSION == ''
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Generate Release Notes
run: |
./.github/workflows/release-notes.js ${{ env.RELEASE_VERSION }}
cat notes-${{ env.RELEASE_VERSION }}.md
- name: Create Release for Tag
id: release_tag
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body_path: notes-${{ env.RELEASE_VERSION }}.md
10 changes: 0 additions & 10 deletions .prettierrc.js

This file was deleted.

748 changes: 748 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions bump.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'bumpp';

export default defineConfig({
files: [
'package.json',
],
all: true,
recursive: true,
execute: 'node scripts/release.js',
});
16 changes: 16 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#type
*/
export default {
'extends': ['@commitlint/config-conventional'],
'rules': {
'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore', 'revert', 'release', 'build', 'ci']],
},
'type-case': [0],
'type-empty': [0],
'scope-empty': [0],
'scope-case': [0],
'subject-full-stop': [0, 'never'],
'subject-case': [0, 'never'],
'header-max-length': [0, 'always', 72],
};
20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"lint": "eslint --fix",
"export": "pnpm mask && cross-env BUILD_MODE=export BUILD_APP=1 next build",
"export:dev": "concurrently -r \"pnpm mask:watch\" \"cross-env BUILD_MODE=export BUILD_APP=1 next dev\"",
"prompts": "node ./scripts/fetch-prompts.mjs"
"prompts": "node ./scripts/fetch-prompts.mjs",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"changelog:versions": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"
},
"dependencies": {
"@fortaine/fetch-event-source": "^3.0.6",
Expand Down Expand Up @@ -60,6 +62,8 @@
},
"devDependencies": {
"@antfu/eslint-config": "3.9.1",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@eslint-react/eslint-plugin": "^1.21.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/react": "^16.0.1",
Expand All @@ -70,12 +74,18 @@
"@types/react-dom": "^18.2.7",
"@types/react-katex": "^3.0.0",
"@types/spark-md5": "^3.0.4",
"bumpp": "9.8.1",
"chalk": "5.3.0",
"commitizen": "4.3.1",
"concurrently": "^8.2.2",
"conventional-changelog-cli": "5.0.0",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "3.3.0",
"eslint": "^9.14.0",
"eslint-plugin-format": "^0.1.3",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-react-refresh": "^0.4.16",
"execa": "9.5.1",
"lint-staged": "^15.2.10",
"simple-git-hooks": "2.11.1",
"ts-node": "^10.9.2",
Expand All @@ -85,11 +95,17 @@
"webpack": "^5.88.1"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
"pre-commit": "npx lint-staged",
"commit-msg": "npx commitlint --edit $1"
},
"lint-staged": {
"*.{js,jsx,vue,ts,tsx,css,html}": [
"npm run lint"
]
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
Loading

0 comments on commit 3198bf5

Please sign in to comment.