Elffuss BraidHub

kikocis/continue public

627d7d0d1f85 · 6.6 KiBRawPermalink
1name: PR Compliance Checks
2
3on:
4 pull_request:
5 types: [opened, synchronize, reopened, ready_for_review]
6 branches: [main]
7 workflow_dispatch:
8
9concurrency:
10 group: ${{ github.workflow }}-${{ github.ref }}
11 cancel-in-progress: true
12
13jobs:
14 conventional-commits:
15 name: Validate Conventional Commits (Warning Only)
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: Checkout code
25 uses: actions/checkout@v4
26 with:
27 fetch-depth: 0
28
29 - name: Validate conventional commits
30 id: commitlint
31 uses: wagoid/commitlint-github-action@v6
32 with:
33 configFile: .commitlintrc.warning.json
34 # Only check the last commit instead of all commits in the PR
35 commitDepth: 1
36 continue-on-error: true
37
38 - name: Add commit message guidance comment
39 if: steps.commitlint.outcome == 'failure'
40 uses: actions/github-script@v7
41 with:
42 script: |
43 const { data: comments } = await github.rest.issues.listComments({
44 owner: context.repo.owner,
45 repo: context.repo.repo,
46 issue_number: context.issue.number,
47 });
48
49 const botComment = comments.find(comment =>
50 comment.user.type === 'Bot' &&
51 comment.body.includes('Conventional Commit Format')
52 );
53
54 if (!botComment) {
55 await github.rest.issues.createComment({
56 owner: context.repo.owner,
57 repo: context.repo.repo,
58 issue_number: context.issue.number,
59 body: [
60 "## ⚠️ Conventional Commit Format",
61 "",
62 "Your latest commit message doesn't follow the conventional commit format, but **this won't block your PR from being merged**. We recommend downloading [this extension](https://marketplace.visualstudio.com/items?itemName=vivaxy.vscode-conventional-commits) if you are using VS Code.",
63 "",
64 "### Expected Format:",
65 "```",
66 "<type>[optional scope]: <description>",
67 "",
68 "[optional body]",
69 "",
70 "[optional footer(s)]",
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
92 security-audit:
93 name: Security Audit
94 runs-on: ubuntu-latest
95 if: ${{ !github.event.pull_request.draft }}
96 permissions:
97 security-events: write
98 contents: read
99 steps:
100 - name: Checkout code
101 uses: actions/checkout@v4
102
103 - name: Setup Node.js
104 uses: actions/setup-node@v4
105 with:
106 node-version-file: ".nvmrc"
107 cache: "npm"
108
109 - name: Install dependencies
110 run: npm ci
111
112 - name: Fix vulnerabilities
113 run: npm audit fix
114
115 - name: Run npm audit
116 run: npm audit --audit-level=moderate
117
118 - name: Initialize CodeQL
119 uses: github/codeql-action/init@v3
120 with:
121 languages: javascript
122
123 - name: Perform CodeQL Analysis
124 uses: github/codeql-action/analyze@v3
125
126 # Use this for any files that we want to be certain exist
127 # Basically creates a forcing function to discuss were anyone to want to remove them
128 file-validation:
129 name: Required Files Check
130 runs-on: ubuntu-latest
131 if: ${{ !github.event.pull_request.draft }}
132 steps:
133 - name: Checkout code
134 uses: actions/checkout@v4
135
136 - name: Check required files
137 run: |
138 required_files=(
139 "package.json"
140 "package-lock.json"
141 "README.md"
142 "LICENSE"
143 ".gitignore"
144 "tsconfig.json"
145 "SECURITY.md"
146 "CONTRIBUTING.md"
147 ".nvmrc"
148 ".prettierrc"
149 ".prettierignore"
150 )
151
152 missing_files=()
153 for file in "${required_files[@]}"; do
154 if [[ ! -f "$file" ]]; then
155 missing_files+=("$file")
156 fi
157 done
158
159 if [[ ${#missing_files[@]} -gt 0 ]]; then
160 echo "❌ Missing required files:"
161 printf '%s\n' "${missing_files[@]}"
162 exit 1
163 else
164 echo "✅ All required files present"
165 fi
166
167 compliance-summary:
168 name: Compliance Summary
169 runs-on: ubuntu-latest
170 needs: [conventional-commits, security-audit, file-validation]
171 if: always() && !github.event.pull_request.draft
172 steps:
173 - name: Check compliance status
174 run: |
175 echo "## 🔍 Compliance Check Results" >> $GITHUB_STEP_SUMMARY
176 echo "" >> $GITHUB_STEP_SUMMARY
177
178 if [[ "${{ needs.conventional-commits.result }}" == "success" ]]; then
179 echo "✅ Conventional Commits: PASSED" >> $GITHUB_STEP_SUMMARY
180 elif [[ "${{ needs.conventional-commits.result }}" == "failure" ]]; then
181 echo "⚠️ Conventional Commits: WARNING (non-blocking)" >> $GITHUB_STEP_SUMMARY
182 else
183 echo "❌ Conventional Commits: SKIPPED" >> $GITHUB_STEP_SUMMARY
184 fi
185
186 if [[ "${{ needs.security-audit.result }}" == "success" ]]; then
187 echo "✅ Security Audit: PASSED" >> $GITHUB_STEP_SUMMARY
188 else
189 echo "❌ Security Audit: FAILED" >> $GITHUB_STEP_SUMMARY
190 fi
191
192 if [[ "${{ needs.file-validation.result }}" == "success" ]]; then
193 echo "✅ File Validation: PASSED" >> $GITHUB_STEP_SUMMARY
194 else
195 echo "❌ File Validation: FAILED" >> $GITHUB_STEP_SUMMARY
196 fi
197
198 echo "" >> $GITHUB_STEP_SUMMARY
199 echo "📊 **Overall Status**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY