Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
chore: enforce Conventional Commits format for PR titles in workflow (#180)
Sakurab81caaa1bb16
diff --git a/.github/workflows/backen-check.yml b/.github/workflows/backen-check.ymlindex 0ea7bdb3..bb62ee3b 100644--- a/.github/workflows/backen-check.yml+++ b/.github/workflows/backen-check.yml@@ -3,8 +3,6 @@ name: AitoEarn Backend Checkon:pull_request:types: [opened, synchronize, reopened]- paths:- - 'project/backend/**'permissions:contents: read@@ -29,12 +27,29 @@ jobs:with:fetch-depth: 0+ - name: Check if backend files changed+ id: check-changes+ run: |+ if git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -q "^project/backend/"; then+ echo "changed=true" >> $GITHUB_OUTPUT+ else+ echo "changed=false" >> $GITHUB_OUTPUT+ fi++ - name: Skip if no changes+ if: steps.check-changes.outputs.changed == 'false'+ run: |+ echo "No changes in project/backend/, skipping checks"+ exit 0+- name: Install pnpm+ if: steps.check-changes.outputs.changed == 'true'uses: pnpm/action-setup@v4with:version: 10- name: Setup Node.js+ if: steps.check-changes.outputs.changed == 'true'uses: actions/setup-node@v4with:node-version: 22@@ -42,14 +57,17 @@ jobs:cache-dependency-path: ${{ env.MONOREPO_DIR }}/pnpm-lock.yaml- name: Install dependencies+ if: steps.check-changes.outputs.changed == 'true'working-directory: ${{ env.MONOREPO_DIR }}run: pnpm install --frozen-lockfile- name: Run ESLint+ if: steps.check-changes.outputs.changed == 'true'working-directory: ${{ env.MONOREPO_DIR }}run: pnpm nx run-many --target=lint --no-fix --nxBail --outputStyle=static- name: Run build+ if: steps.check-changes.outputs.changed == 'true'working-directory: ${{ env.MONOREPO_DIR }}run: pnpm nx run-many --target=build --nxBail --outputStyle=staticdiff --git a/.github/workflows/pr-issue-check.yml b/.github/workflows/pr-issue-check.ymlindex 3ba793fe..3358877b 100644--- a/.github/workflows/pr-issue-check.yml+++ b/.github/workflows/pr-issue-check.yml@@ -26,20 +26,45 @@ jobs:let prBody = context.payload.pull_request.body || '';const prTitle = context.payload.pull_request.title || '';- // 移除注释内容(HTML/Markdown 注释格式:<!-- ... -->)+ const conventionalCommitsPattern = /^(feat|fix|docs|style|refactor|perf|test|chore|ci|build)(\(.+\))?: .+$/;+ const validTypes = ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'chore', 'ci', 'build'];++ if (!conventionalCommitsPattern.test(prTitle)) {+ const errorMessage =+ '❌ PR title does not follow Conventional Commits format.\n\n' ++ 'Required format: <type>(<scope>): <description>\n\n' ++ 'Valid types:\n' ++ validTypes.map(t => ` - ${t}`).join('\n') + '\n\n' ++ 'Examples:\n' ++ ' ✅ feat: add user authentication\n' ++ ' ✅ fix(web): resolve login button issue\n' ++ ' ✅ docs: update API documentation\n' ++ ' ✅ refactor(backend): improve error handling\n' ++ ' ✅ chore: update dependencies\n\n' ++ 'Common mistakes:\n' ++ ' ❌ "Add new feature" (missing type and colon)\n' ++ ' ❌ "feat add feature" (missing colon)\n' ++ ' ❌ "feat: " (missing description)\n' ++ ' ❌ "feature: add something" (invalid type)\n\n' ++ `Current title: "${prTitle}"\n\n` ++ 'Please update your PR title to follow the Conventional Commits specification.';++ core.setFailed(errorMessage);+ return;+ }++ console.log(`✅ PR title follows Conventional Commits format: "${prTitle}"`);+prBody = prBody.replace(/<!--[\s\S]*?-->/g, '');- // 从 PR 描述和标题中提取 issue 编号const issuePattern = /(?:closes?|fixes?|resolves?|related to|refs?)\s*#(\d+)/gi;const matches = [];- // 从 body 中提取(已移除注释)const bodyMatches = prBody.matchAll(issuePattern);for (const match of bodyMatches) {matches.push(parseInt(match[1]));}- // 从 title 中提取(标题通常不包含注释,但为了安全也处理一下)const titleWithoutComments = prTitle.replace(/<!--[\s\S]*?-->/g, '');const titlePattern = /(?:closes?|fixes?|resolves?|related to|refs?)\s*#(\d+)/gi;const titleMatches = titleWithoutComments.matchAll(titlePattern);@@ -47,7 +72,6 @@ jobs:matches.push(parseInt(match[1]));}- // 去重const issueNumbers = [...new Set(matches)];if (issueNumbers.length === 0) {@@ -64,7 +88,6 @@ jobs:return;}- // 验证这些 issue 是否真实存在const owner = context.repo.owner;const repo = context.repo.repo;let validIssues = [];@@ -78,7 +101,6 @@ jobs:issue_number: issueNumber,});- // 确保是 issue 而不是 PRif (!issue.pull_request) {validIssues.push(issueNumber);console.log(`✅ Found valid issue: #${issueNumber} - "${issue.title}"`);@@ -93,8 +115,6 @@ jobs:if (error.status) {console.log(`HTTP status: ${error.status}`);}- // 如果是 404,可能是 issue 不存在或已删除- // 如果是 403,可能是权限问题if (error.status === 403) {console.log(`⚠️ Permission denied. Make sure the workflow has 'issues: read' permission.`);} else if (error.status === 404) {diff --git a/.github/workflows/web-check.yml b/.github/workflows/web-check.ymlindex 06f8c73f..dbb6c233 100644--- a/.github/workflows/web-check.yml+++ b/.github/workflows/web-check.yml@@ -3,8 +3,6 @@ name: AitoEarn Web Checkon:pull_request:types: [opened, synchronize, reopened]- paths:- - 'project/web/**'permissions:contents: read@@ -28,12 +26,29 @@ jobs:with:fetch-depth: 0+ - name: Check if web files changed+ id: check-changes+ run: |+ if git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -q "^project/web/"; then+ echo "changed=true" >> $GITHUB_OUTPUT+ else+ echo "changed=false" >> $GITHUB_OUTPUT+ fi++ - name: Skip if no changes+ if: steps.check-changes.outputs.changed == 'false'+ run: |+ echo "No changes in project/web/, skipping checks"+ exit 0+- name: Install pnpm+ if: steps.check-changes.outputs.changed == 'true'uses: pnpm/action-setup@v4with:version: 10- name: Setup Node.js+ if: steps.check-changes.outputs.changed == 'true'uses: actions/setup-node@v4with:node-version: 22@@ -41,14 +56,17 @@ jobs:cache-dependency-path: ${{ env.MONOREPO_DIR }}/pnpm-lock.yaml- name: Install dependencies+ if: steps.check-changes.outputs.changed == 'true'working-directory: ${{ env.MONOREPO_DIR }}run: pnpm install --frozen-lockfile# - name: Run ESLint+# if: steps.check-changes.outputs.changed == 'true'# working-directory: ${{ env.MONOREPO_DIR }}# run: pnpm lint- name: Run build+ if: steps.check-changes.outputs.changed == 'true'working-directory: ${{ env.MONOREPO_DIR }}run: pnpm build