Skip to content

Commit 4031bf2

Browse files
authored
add-pre-commit-hook (#7)
* add-pre-commit-hook * change-readme
1 parent 62d65af commit 4031bf2

File tree

3 files changed

+333
-1
lines changed

3 files changed

+333
-1
lines changed

.DS_Store

-6 KB
Binary file not shown.

.pre-commit-config.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
repos:
2+
- repo: https://github.com/Yelp/detect-secrets
3+
rev: v1.5.0
4+
hooks:
5+
- id: detect-secrets
6+
args: ['--baseline', '.secrets.baseline']
7+
exclude: package-lock.json|yarn.lock|pnpm-lock.yaml
8+
9+
- repo: https://github.com/pre-commit/mirrors-eslint
10+
rev: v9.15.0
11+
hooks:
12+
- id: eslint
13+
types_or: [javascript, jsx, ts, tsx]
14+
args: ['--fix']
15+
16+
- repo: https://github.com/pre-commit/mirrors-prettier
17+
rev: v4.0.0-alpha.8
18+
hooks:
19+
- id: prettier
20+
types_or: [javascript, jsx, json, ts, tsx, css, scss, markdown, yaml, yml]
21+
args: ['--write']
22+
23+
- repo: https://github.com/pre-commit/mirrors-pylint
24+
rev: v3.3.1
25+
hooks:
26+
- id: pylint
27+
args: ['--max-line-length=120']
28+
29+
- repo: https://github.com/pre-commit/pre-commit-hooks
30+
rev: v4.6.0
31+
hooks:
32+
- id: trailing-whitespace
33+
- id: end-of-file-fixer
34+
- id: check-yaml
35+
- id: check-json
36+
- id: check-added-large-files
37+
args: ['--maxkb=1000']
38+
- id: check-merge-conflict
39+
- id: check-case-conflict
40+
- id: mixed-line-ending
41+
args: ['--fix=lf']
42+
43+
44+
- repo: local
45+
hooks:
46+
- id: npm-test
47+
name: npm test
48+
entry: bash -c 'if [ -f package.json ]; then npm test; fi'
49+
language: system
50+
types: [file]
51+
pass_filenames: false
52+
always_run: false

README.md

Lines changed: 281 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,281 @@
1-
Please read `/profile/README.md` for more details.
1+
# GitHub Actions Workflow Templates
2+
3+
This repository contains reusable GitHub Actions workflow templates for consistent CI/CD across projects. These templates ensure code quality, security, and testing standards are enforced automatically.
4+
5+
## 📋 Table of Contents
6+
7+
- [Overview](#overview)
8+
- [Available Workflows](#available-workflows)
9+
- [Quick Start](#quick-start)
10+
- [Workflow Details](#workflow-details)
11+
- [Usage Guidelines](#usage-guidelines)
12+
13+
## Overview
14+
15+
The workflow templates in this repository provide standardized CI/CD checks that can be easily integrated into any project. Each workflow includes:
16+
17+
- **Workflow file** (`.yml`) - The GitHub Actions workflow definition
18+
- **Documentation** (`.md`) - Detailed setup and configuration instructions
19+
20+
All workflows are designed to be:
21+
- ✅ Easy to integrate
22+
- ✅ Well-documented
23+
- ✅ Configurable
24+
- ✅ Consistent across projects
25+
26+
## Available Workflows
27+
28+
### 1. 🔒 Detect Secrets
29+
30+
**File:** `workflow-templates/detect-secrets.yml`
31+
32+
Scans repositories for potential secrets (API keys, passwords, tokens, etc.) using `detect-secrets` to prevent accidental commits of sensitive information.
33+
34+
**Key Features:**
35+
- Uses `detect-secrets[gibberish]==1.5.0`
36+
- Requires `.secrets.baseline` file
37+
- Runs on pushes and pull requests to `main`
38+
- Python 3.11 environment
39+
40+
**Triggers:** `push`, `pull_request` (to `main` branch)
41+
42+
**See:** [detect-secrets.md](workflow-templates/detect-secrets.md) for detailed documentation
43+
44+
---
45+
46+
### 2. 🧹 ESLint & Prettier
47+
48+
**File:** `workflow-templates/eslint.yml`
49+
50+
Runs ESLint and Prettier to ensure code quality and consistent formatting for JavaScript/TypeScript projects.
51+
52+
**Key Features:**
53+
- ESLint with auto-fix
54+
- Prettier code formatting
55+
- Uses Yarn as package manager
56+
- Node.js 22
57+
- Supports manual workflow dispatch
58+
59+
**Triggers:** `push`, `pull_request` (to `main` branch), `workflow_dispatch`
60+
61+
**Commands:**
62+
- `yarn run fix .` - ESLint with auto-fix
63+
- `yarn prettier --write .` - Prettier formatting
64+
65+
**See:** [eslint.md](workflow-templates/eslint.md) for detailed documentation
66+
67+
---
68+
69+
### 3. 🧪 NPM Test Suite
70+
71+
**File:** `workflow-templates/npm-test.yml`
72+
73+
Comprehensive test suite for Node.js projects including unit tests, coverage, and E2E tests.
74+
75+
**Key Features:**
76+
- Build verification
77+
- Unit tests
78+
- Test coverage collection
79+
- E2E tests
80+
- Codecov integration (optional)
81+
- Node.js 22.x with npm caching
82+
83+
**Triggers:** `push`, `pull_request` (to `main` branch)
84+
85+
**Required npm Scripts:**
86+
- `npm run build` - Build the project
87+
- `npm test` - Run unit tests
88+
- `npm run test:cov` - Run tests with coverage
89+
- `npm run test:e2e` - Run E2E tests
90+
91+
**See:** [npm-test.md](workflow-templates/npm-test.md) for detailed documentation
92+
93+
---
94+
95+
### 4. 🐍 Pylint
96+
97+
**File:** `workflow-templates/pylint.yml`
98+
99+
Analyzes Python code quality and enforces coding standards using Pylint.
100+
101+
**Key Features:**
102+
- Multi-version Python testing (3.8, 3.9, 3.10)
103+
- Scans all Python files tracked by git
104+
- Configurable via `.pylintrc`, `pyproject.toml`, or `setup.cfg`
105+
- Matrix strategy for version compatibility
106+
107+
**Triggers:** `push` (all branches)
108+
109+
**Command:**
110+
- `pylint $(git ls-files '*.py')` - Lint all Python files
111+
112+
**See:** [pylint.md](workflow-templates/pylint.md) for detailed documentation
113+
114+
---
115+
116+
## Quick Start
117+
118+
### Using a Workflow Template
119+
120+
1. **Copy the workflow file** to your repository:
121+
```bash
122+
cp .github/workflow-templates/[workflow-name].yml .github/workflows/[workflow-name].yml
123+
```
124+
125+
2. **Read the documentation** for prerequisites and setup:
126+
```bash
127+
cat .github/workflow-templates/[workflow-name].md
128+
```
129+
130+
3. **Configure prerequisites** (e.g., create `.secrets.baseline`, set up ESLint config, etc.)
131+
132+
4. **Customize the workflow** (optional):
133+
- Adjust trigger branches
134+
- Modify versions (Node.js, Python, etc.)
135+
- Update paths or commands
136+
137+
5. **Commit and push** - The workflow will run automatically based on its triggers
138+
139+
### Example: Adding ESLint Workflow
140+
141+
```bash
142+
# Copy the workflow
143+
cp .github/workflow-templates/eslint.yml .github/workflows/eslint.yml
144+
145+
# Ensure your project has ESLint and Prettier configured
146+
# (see eslint.md for details)
147+
148+
# Commit and push
149+
git add .github/workflows/eslint.yml
150+
git commit -m "Add ESLint workflow"
151+
git push
152+
```
153+
154+
## Workflow Details
155+
156+
### Workflow Comparison
157+
158+
| Workflow | Language | Package Manager | Trigger Events | Key Tools |
159+
|----------|----------|----------------|----------------|-----------|
160+
| **detect-secrets** | Python | pip | push, PR | detect-secrets 1.5.0 |
161+
| **eslint** | JavaScript/TypeScript | Yarn | push, PR, manual | ESLint, Prettier |
162+
| **npm-test** | JavaScript/TypeScript | npm | push, PR | npm, Codecov |
163+
| **pylint** | Python | pip | push | Pylint |
164+
165+
### Common Prerequisites
166+
167+
Most workflows require:
168+
169+
1. **Repository access** - Workflows run in the repository context
170+
2. **Configuration files** - Each workflow may need specific config files
171+
3. **Dependencies** - Project dependencies must be installable
172+
4. **Secrets** (optional) - Some workflows may need GitHub secrets (e.g., `CODECOV_TOKEN`)
173+
174+
### Trigger Configuration
175+
176+
Workflows can be customized to trigger on different events:
177+
178+
```yaml
179+
on:
180+
push:
181+
branches: [main, develop] # Customize branches
182+
pull_request:
183+
branches: [main]
184+
workflow_dispatch: # Allow manual triggers
185+
```
186+
187+
## Usage Guidelines
188+
189+
### Best Practices
190+
191+
1. **Start with one workflow** - Don't add all workflows at once. Start with the most critical for your project.
192+
193+
2. **Read the documentation** - Each workflow has detailed `.md` documentation with setup instructions.
194+
195+
3. **Test locally first** - Run the tools locally before adding the workflow to ensure they work.
196+
197+
4. **Customize appropriately** - Adjust versions, branches, and paths to match your project needs.
198+
199+
5. **Monitor workflow runs** - Check the Actions tab to ensure workflows run successfully.
200+
201+
### Workflow Selection Guide
202+
203+
**Choose `detect-secrets` if:**
204+
- Your project handles sensitive data
205+
- You want to prevent secret leaks
206+
- You need security scanning
207+
208+
**Choose `eslint` if:**
209+
- You have JavaScript/TypeScript code
210+
- You want consistent code style
211+
- You need automatic formatting
212+
213+
**Choose `npm-test` if:**
214+
- You have a Node.js project
215+
- You want automated testing
216+
- You need coverage reporting
217+
218+
**Choose `pylint` if:**
219+
- You have Python code
220+
- You want code quality checks
221+
- You need style enforcement
222+
223+
### Combining Workflows
224+
225+
You can use multiple workflows together:
226+
227+
```bash
228+
# Example: Full-stack project with Python backend and JS frontend
229+
cp .github/workflow-templates/detect-secrets.yml .github/workflows/
230+
cp .github/workflow-templates/pylint.yml .github/workflows/
231+
cp .github/workflow-templates/eslint.yml .github/workflows/
232+
cp .github/workflow-templates/npm-test.yml .github/workflows/
233+
```
234+
235+
## Documentation
236+
237+
Each workflow template includes comprehensive documentation:
238+
239+
- **[detect-secrets.md](workflow-templates/detect-secrets.md)** - Secret detection setup
240+
- **[eslint.md](workflow-templates/eslint.md)** - ESLint & Prettier configuration
241+
- **[npm-test.md](workflow-templates/npm-test.md)** - Test suite setup
242+
- **[pylint.md](workflow-templates/pylint.md)** - Python linting configuration
243+
244+
## Troubleshooting
245+
246+
### Common Issues
247+
248+
**Workflow not running:**
249+
- Check that the workflow file is in `.github/workflows/`
250+
- Verify trigger conditions (branches, events)
251+
- Ensure the workflow file has valid YAML syntax
252+
253+
**Workflow failing:**
254+
- Check the Actions tab for error messages
255+
- Verify all prerequisites are met
256+
- Review the workflow's documentation for troubleshooting tips
257+
258+
**Configuration issues:**
259+
- Ensure required config files exist (`.secrets.baseline`, `.eslintrc`, etc.)
260+
- Verify package.json scripts match workflow expectations
261+
- Check that dependencies are properly installed
262+
263+
## Contributing
264+
265+
When adding or modifying workflow templates:
266+
267+
1. Update both the `.yml` and `.md` files
268+
2. Test the workflow in a sample repository
269+
3. Document any prerequisites clearly
270+
4. Include troubleshooting tips
271+
5. Keep versions up to date
272+
273+
## Additional Resources
274+
275+
- [GitHub Actions Documentation](https://docs.github.com/en/actions)
276+
- [Workflow Syntax Reference](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions)
277+
- [Profile README](profile/README.md) - Organization profile information
278+
279+
---
280+
281+
**Note:** These workflow templates are designed to be copied into individual repositories. They are not meant to be used directly from this repository.

0 commit comments

Comments
 (0)