| 1 | name: PR Compliance Checks |
| 2 | |
| 3 | on: |
| 4 | pull_request: |
| 5 | types: [opened, synchronize, reopened, ready_for_review] |
| 6 | branches: [main] |
| 7 | workflow_dispatch: |
| 8 | |
| 9 | concurrency: |
| 10 | group: ${{ github.workflow }}-${{ github.ref }} |
| 11 | cancel-in-progress: true |
| 12 | |
| 13 | jobs: |
| 14 | conventional-commits: |
| 15 | name: Validate Conventional Commits |
| 16 | runs-on: ubuntu-latest |
| 17 | if: ${{ !github.event.pull_request.draft }} |
| 18 | continue-on-error: true |
| 19 | permissions: |
| 20 | pull-requests: write |
| 21 | issues: write |
| 22 | contents: read |
| 23 | steps: |
| 24 | - name: Validate PR title format |
| 25 | id: pr-title-check |
| 26 | run: | |
| 27 | PR_TITLE="${{ github.event.pull_request.title }}" |
| 28 | echo "Checking PR title: $PR_TITLE" |
| 29 | |
| 30 | # Regex pattern for conventional commits |
| 31 | PATTERN="^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?!?: .+" |
| 32 | |
| 33 | if [[ $PR_TITLE =~ $PATTERN ]]; then |
| 34 | echo "✅ PR title follows conventional commit format" |
| 35 | echo "valid=true" >> $GITHUB_OUTPUT |
| 36 | else |
| 37 | echo "❌ PR title does not follow conventional commit format" |
| 38 | echo "valid=false" >> $GITHUB_OUTPUT |
| 39 | # Don't exit with failure - just mark as invalid for comment |
| 40 | fi |
| 41 | |
| 42 | - name: Add PR title guidance comment |
| 43 | if: always() && steps.pr-title-check.outputs.valid == 'false' |
| 44 | uses: actions/github-script@v8 |
| 45 | with: |
| 46 | script: | |
| 47 | const { data: comments } = await github.rest.issues.listComments({ |
| 48 | owner: context.repo.owner, |
| 49 | repo: context.repo.repo, |
| 50 | issue_number: context.issue.number, |
| 51 | }); |
| 52 | |
| 53 | const botComment = comments.find(comment => |
| 54 | comment.user.type === 'Bot' && |
| 55 | comment.body.includes('PR Title Format') |
| 56 | ); |
| 57 | |
| 58 | if (!botComment) { |
| 59 | await github.rest.issues.createComment({ |
| 60 | owner: context.repo.owner, |
| 61 | repo: context.repo.repo, |
| 62 | issue_number: context.issue.number, |
| 63 | body: [ |
| 64 | "## ⚠️ PR Title Format", |
| 65 | "", |
| 66 | "Your PR title doesn't follow the conventional commit format, but **this won't block your PR from being merged**. We recommend using this format for better project organization.", |
| 67 | "", |
| 68 | "### Expected Format:", |
| 69 | "```", |
| 70 | "<type>[optional scope]: <description>", |
| 71 | "```", |
| 72 | "", |
| 73 | "### Examples:", |
| 74 | "- `feat: add changelog generation support`", |
| 75 | "- `fix: resolve login redirect issue`", |
| 76 | "- `docs: update README with new instructions`", |
| 77 | "- `chore: update dependencies`", |
| 78 | "", |
| 79 | "### Valid Types:", |
| 80 | "`feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, `revert`", |
| 81 | "", |
| 82 | "This helps with:", |
| 83 | "- 📝 Automatic changelog generation", |
| 84 | "- 🚀 Automated semantic versioning", |
| 85 | "- 📊 Better project history tracking", |
| 86 | "", |
| 87 | "*This is a non-blocking warning - your PR can still be merged without fixing this.*" |
| 88 | ].join('\n') |
| 89 | }); |
| 90 | } |
| 91 | - name: Ensure job always succeeds |
| 92 | if: always() |
| 93 | run: echo "✅ Conventional commits check completed (warning only)" |
| 94 | |
| 95 | security-audit: |
| 96 | name: Security Audit |
| 97 | runs-on: ubuntu-latest |
| 98 | if: ${{ !github.event.pull_request.draft }} |
| 99 | permissions: |
| 100 | security-events: write |
| 101 | contents: read |
| 102 | steps: |
| 103 | - name: Checkout code |
| 104 | uses: actions/checkout@v5 |
| 105 | |
| 106 | - name: Setup Node.js |
| 107 | uses: actions/setup-node@v5 |
| 108 | with: |
| 109 | node-version-file: ".nvmrc" |
| 110 | cache: "npm" |
| 111 | |
| 112 | - name: Install dependencies |
| 113 | run: npm ci |
| 114 | |
| 115 | - name: Fix vulnerabilities |
| 116 | run: npm audit fix |
| 117 | |
| 118 | - name: Run npm audit |
| 119 | run: npm audit --audit-level=moderate |
| 120 | |
| 121 | - name: Initialize CodeQL |
| 122 | uses: github/codeql-action/init@v3 |
| 123 | with: |
| 124 | languages: javascript |
| 125 | |
| 126 | - name: Perform CodeQL Analysis |
| 127 | uses: github/codeql-action/analyze@v3 |
| 128 | |
| 129 | # Use this for any files that we want to be certain exist |
| 130 | # Basically creates a forcing function to discuss were anyone to want to remove them |
| 131 | file-validation: |
| 132 | name: Required Files Check |
| 133 | runs-on: ubuntu-latest |
| 134 | if: ${{ !github.event.pull_request.draft }} |
| 135 | steps: |
| 136 | - name: Checkout code |
| 137 | uses: actions/checkout@v5 |
| 138 | |
| 139 | - name: Check required files |
| 140 | run: | |
| 141 | required_files=( |
| 142 | "package.json" |
| 143 | "package-lock.json" |
| 144 | "README.md" |
| 145 | "LICENSE" |
| 146 | ".gitignore" |
| 147 | "tsconfig.json" |
| 148 | "SECURITY.md" |
| 149 | "CONTRIBUTING.md" |
| 150 | ".nvmrc" |
| 151 | ".prettierrc" |
| 152 | ".prettierignore" |
| 153 | ) |
| 154 | |
| 155 | missing_files=() |
| 156 | for file in "${required_files[@]}"; do |
| 157 | if [[ ! -f "$file" ]]; then |
| 158 | missing_files+=("$file") |
| 159 | fi |
| 160 | done |
| 161 | |
| 162 | if [[ ${#missing_files[@]} -gt 0 ]]; then |
| 163 | echo "❌ Missing required files:" |
| 164 | printf '%s\n' "${missing_files[@]}" |
| 165 | exit 1 |
| 166 | else |
| 167 | echo "✅ All required files present" |
| 168 | fi |
| 169 | |
| 170 | compliance-summary: |
| 171 | name: Compliance Summary |
| 172 | runs-on: ubuntu-latest |
| 173 | needs: [conventional-commits, security-audit, file-validation] |
| 174 | if: always() && !github.event.pull_request.draft |
| 175 | steps: |
| 176 | - name: Check compliance status |
| 177 | run: | |
| 178 | echo "## 🔍 Compliance Check Results" >> $GITHUB_STEP_SUMMARY |
| 179 | echo "" >> $GITHUB_STEP_SUMMARY |
| 180 | |
| 181 | if [[ "${{ needs.conventional-commits.result }}" == "success" ]]; then |
| 182 | echo "✅ Conventional Commits: PASSED" >> $GITHUB_STEP_SUMMARY |
| 183 | elif [[ "${{ needs.conventional-commits.result }}" == "failure" ]]; then |
| 184 | echo "⚠️ Conventional Commits: WARNING (non-blocking)" >> $GITHUB_STEP_SUMMARY |
| 185 | else |
| 186 | echo "❌ Conventional Commits: SKIPPED" >> $GITHUB_STEP_SUMMARY |
| 187 | fi |
| 188 | |
| 189 | if [[ "${{ needs.security-audit.result }}" == "success" ]]; then |
| 190 | echo "✅ Security Audit: PASSED" >> $GITHUB_STEP_SUMMARY |
| 191 | else |
| 192 | echo "❌ Security Audit: FAILED" >> $GITHUB_STEP_SUMMARY |
| 193 | fi |
| 194 | |
| 195 | if [[ "${{ needs.file-validation.result }}" == "success" ]]; then |
| 196 | echo "✅ File Validation: PASSED" >> $GITHUB_STEP_SUMMARY |
| 197 | else |
| 198 | echo "❌ File Validation: FAILED" >> $GITHUB_STEP_SUMMARY |
| 199 | fi |
| 200 | |
| 201 | echo "" >> $GITHUB_STEP_SUMMARY |
| 202 | echo "📊 **Overall Status**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY |