diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 1c307ae58..1a08930d8 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -15,7 +15,7 @@ Please note that by submitting this pull request to **Img2Num**, you confirm tha -Fixes: +Fixes: # ## Changes diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 000000000..f2b7d9b3e --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,22 @@ +c/cpp: + - "**/*.c" + - "**/*.cpp" + - "**/*.h" + - "**/*.hpp" + +docs: + - "**/*.md" + +ci: + - ".github/**" + +js/ts: + - "**/*.js" + - "**/*.jsx" + - "**/*.ts" + - "**/*.tsx" + - "vite.config.*" # Vite config files + - "vite.*.js" # optional extra patterns + - "package.json" # package manifest changes + - "package-lock.json" + - "yarn.lock" diff --git a/.github/workflows/pr-auto-label.yml b/.github/workflows/pr-auto-label.yml new file mode 100644 index 000000000..c1ae533b0 --- /dev/null +++ b/.github/workflows/pr-auto-label.yml @@ -0,0 +1,21 @@ +# This workflow will triage pull requests and apply a label based on the +# paths that are modified in the pull request. +# +# To use this workflow, you will need to set up a .github/labeler.yml +# file with configuration. For more information, see: +# https://github.com/actions/labeler + +name: Labeler +on: [pull_request_target] + +jobs: + label: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - uses: actions/labeler@v6 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml new file mode 100644 index 000000000..e7a822f19 --- /dev/null +++ b/.github/workflows/pr-check.yml @@ -0,0 +1,109 @@ +name: PR Validation + +on: + pull_request: + types: [opened, edited, reopened, synchronize] + +jobs: + title-check: + permissions: + contents: read + pull-requests: read + runs-on: ubuntu-latest + steps: + - name: Check PR title + uses: actions/github-script@v7 + with: + script: | + const pr = context.payload.pull_request; + const title = pr.title; + + const isWip = title.startsWith("WIP:"); + const isDraft = pr.draft; + + const conventionalRegex = + /^(build|ci|chore|docs|feat|fix|perf|refactor|revert|style|test)(\([^)]+\))?(!)?: .+/; + + if (isDraft || isWip) { + core.info("Draft or WIP PR detected — skipping title enforcement."); + return; + } + + if (!conventionalRegex.test(title)) { + core.setFailed( + `Invalid PR title.\n\n` + + `Expected:\n` + + `type(scope)!: description\n\n` + + `Allowed types:\n` + + `build, ci, chore, docs, feat, fix, perf, refactor, revert, style, test\n\n` + + `Examples:\n` + + `- feat: new feature\n` + + `- fix(scope): bug in scope\n` + + `- feat!: breaking change\n` + + `- chore(deps): update dependencies\n\n` + + `If this is WIP, prefix the title with "WIP:" or convert the PR to Draft.` + ); + } + + body-check: + permissions: + contents: read + pull-requests: read + needs: title-check + runs-on: ubuntu-latest + steps: + - name: Validate PR body + uses: actions/github-script@v7 + with: + script: | + const pr = context.payload.pull_request; + const body = pr.body || ""; + const title = pr.title || ""; + + const isDraft = pr.draft; + const isWip = title.startsWith("WIP:"); + + if (isDraft || isWip) { + core.info("Draft or WIP PR — skipping body enforcement."); + return; + } + + const requiredSections = [ + "## What was changed & why", + "## Changes", + "## Testing & Verification" + ]; + + const missingSections = requiredSections.filter( + section => !body.includes(section) + ); + + if (missingSections.length > 0) { + core.setFailed( + `PR body is missing the following required sections:\n` + + missingSections.join("\n") + + `\n\nPlease add these sections to your PR body.` + ); + } + + // Check for multiple issue references like "fixes #2" or "fixes: #2" + const issueReferences = [...body.matchAll(/(fixes|closes|resolves)\s*:?\s*#\d+/gi)]; + + const hasNone = /\bnone\b/i.test(body); + + // Convert matchAll result to boolean + const hasIssueKeyword = issueReferences.length > 0; + + // Fail only if neither issue references nor "none" exists + if (!hasIssueKeyword && !hasNone) { + core.setFailed( + `PR must reference an issue or explicitly state "none".\n\n` + + `Use one or more of the following keywords:\n` + + `- Fixes #\n` + + `- Closes #\n` + + `- Resolves #\n\n` + + `You can list multiple issues:\n` + + `fixes #2\nfixes: #3\n\n` + + `If no issue applies, write "none" in the PR body.` + ); + } diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 000000000..59aa4c92e --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,30 @@ +# This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time. +# +# For more information, see: +# https://github.com/actions/stale +name: Mark stale issues and pull requests + +on: + schedule: + - cron: "0 2 * * *" # every day at 02:00 UTC + workflow_dispatch: + +jobs: + stale: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + + steps: + - uses: actions/stale@v10 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-issue-message: "This issue has been inactive for 60 days. Please comment if it is still relevant or it will be closed in 14 days." + stale-pr-message: "This pull request has been inactive for 60 days. Please update it or it will be closed in 14 days." + stale-issue-label: "no-issue-activity" + stale-pr-label: "no-pr-activity" + days-before-stale: 60 + days-before-close: 14 + exempt-issue-labels: "pinned,important" + exempt-pr-labels: "pinned,important"