diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0635bad..02e281d 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,4 +6,4 @@ updates: interval: weekly open-pull-requests-limit: 99 labels: - - 'pr: dependencies' + - 'dependencies' diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..980b1e9 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,42 @@ +name-template: 'v$RESOLVED_VERSION' +tag-template: 'v$RESOLVED_VERSION' +template: | + # What's Changed + + $CHANGES + + **Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION + +categories: + - title: 'Breaking' + label: 'breaking' + - title: 'New' + label: 'feature' + - title: 'Bug Fixes' + label: 'bug' + - title: 'Maintenance' + label: 'maintenance' + - title: 'Documentation' + label: 'docs' + - title: 'Other changes' + - title: 'Dependency Updates' + label: 'dependencies' + collapse-after: 5 + +version-resolver: + major: + labels: + - 'breaking' + minor: + labels: + - 'feature' + patch: + labels: + - 'bug' + - 'maintenance' + - 'docs' + - 'dependencies' + - 'security' + +exclude-labels: + - 'skip-changelog' \ No newline at end of file diff --git a/.github/workflows/check-pr-title.yml b/.github/workflows/check-pr-title.yml new file mode 100644 index 0000000..e0c2adb --- /dev/null +++ b/.github/workflows/check-pr-title.yml @@ -0,0 +1,18 @@ +name: "Validate PR Title" + +on: + pull_request: + types: + - opened + - edited + - synchronize + - reopened + +jobs: + check-pr-title: + name: Validate PR Title + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/draft.yml b/.github/workflows/draft.yml new file mode 100644 index 0000000..a402761 --- /dev/null +++ b/.github/workflows/draft.yml @@ -0,0 +1,16 @@ +name: Release Drafter +on: + push: + pull_request: +permissions: + contents: read +jobs: + update-release-draft: + permissions: + contents: write + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: release-drafter/release-drafter@v6 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pr-auto-label.yml b/.github/workflows/pr-auto-label.yml new file mode 100644 index 0000000..35c8918 --- /dev/null +++ b/.github/workflows/pr-auto-label.yml @@ -0,0 +1,75 @@ +name: 'Auto Label by Title' + +on: + pull_request: + types: + - opened + - edited # 注意:增加了 edited 类型,标题编辑时也会触发 + - synchronize + +jobs: + label-by-title: + runs-on: ubuntu-latest + # 添加权限配置 + permissions: + issues: write # 或者 contents: write + pull-requests: write + steps: + - name: Label PR based on title keywords + uses: actions/github-script@v7 + with: + script: | + const title = context.payload.pull_request.title.toLowerCase(); + const labelsToAdd = new Set(); // 使用 Set 避免重复添加 + + // 定义关键词与标签的映射 + const keywordMap = { + 'bug': 'bug', + 'fix': 'bug', + 'error': 'bug', + 'feat': 'feature', + 'feature': 'feature', + 'improvement': 'enhancement', + 'doc': 'documentation', + 'readme': 'documentation', + 'chore': 'chore', + 'bump': 'dependencies', + 'dependabot': 'dependencies', + 'upgrade': 'dependencies', + 'security': 'security', + 'ci':'ci' + }; + + // 检查标题是否包含关键词 + for (const [keyword, label] of Object.entries(keywordMap)) { + if (title.includes(keyword)) { + labelsToAdd.add(label); + } + } + + // 如果有匹配的标签,则先清除现有标签,再添加新标签 + if (labelsToAdd.size > 0) { + const labelsArray = Array.from(labelsToAdd); + console.log(`Clearing existing labels and adding: ${labelsArray.join(', ')}`); + + // 首先清除所有现有标签 + try { + await github.rest.issues.removeAllLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo + }); + console.log('All existing labels removed'); + } catch (error) { + console.log('Error removing labels:', error.message); + } + + // 然后添加新的标签 + await github.rest.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: labelsArray + }); + console.log('New labels added successfully'); + } \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..8ce95aa --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,7 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 # Use the ref you want to point at + hooks: + - id: check-added-large-files +# - id: trailing-whitespace +# - id: check-yaml \ No newline at end of file