Skip to content

Commit 6a8d682

Browse files
Merge pull request #2 from OffendingCommit/chore/add-semver-and-ci
chore(build): add semantic versioning and CI workflow
2 parents c22cc0e + 9464d93 commit 6a8d682

File tree

15 files changed

+1646
-307
lines changed

15 files changed

+1646
-307
lines changed

.flake8

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[flake8]
2+
exclude = .git,__pycache__,build,dist,.venv,venv
3+
max-line-length = 88
4+
max-complexity = 10
5+
# These rules conflict with black
6+
ignore = E203,W503
7+
per-file-ignores =
8+
# imported but unused in __init__ files
9+
__init__.py: F401

.github/workflows/ci.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.12"]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
cache: 'pip'
24+
25+
- name: Install Poetry
26+
uses: snok/install-poetry@v1
27+
with:
28+
version: 1.8.3
29+
virtualenvs-create: true
30+
virtualenvs-in-project: true
31+
32+
- name: Cache Poetry dependencies
33+
uses: actions/cache@v4
34+
with:
35+
path: .venv
36+
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
37+
38+
- name: Install dependencies
39+
run: poetry install
40+
41+
- name: Lint with flake8
42+
run: |
43+
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=.venv,.git,__pycache__,build,dist
44+
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics --exclude=.venv,.git,__pycache__,build,dist
45+
46+
- name: Format check with black
47+
run: poetry run black --check --exclude=\.venv --extend-exclude=main.py .
48+
49+
- name: Import sorting check with isort
50+
run: poetry run isort --check --skip .venv --skip main.py .
51+
52+
- name: Test with pytest
53+
run: |
54+
if [ -d "src" ]; then
55+
poetry run pytest --cov=src
56+
else
57+
echo "No src directory yet, skipping tests"
58+
exit 0
59+
fi
60+
61+
- name: Upload coverage to Codecov
62+
uses: codecov/codecov-action@v4
63+
with:
64+
token: ${{ secrets.CODECOV_TOKEN }}
65+
fail_ci_if_error: false
66+
67+
release:
68+
needs: test
69+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
70+
runs-on: ubuntu-latest
71+
concurrency: release
72+
permissions:
73+
id-token: write
74+
contents: write
75+
76+
steps:
77+
- uses: actions/checkout@v4
78+
with:
79+
fetch-depth: 0
80+
81+
- name: Python Semantic Release
82+
uses: python-semantic-release/python-semantic-release@master
83+
with:
84+
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/docker-build-publish.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,26 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout repository
16-
uses: actions/checkout@v3
16+
uses: actions/checkout@v4
1717

1818
- name: Set up Docker Buildx
19-
uses: docker/setup-buildx-action@v2
19+
uses: docker/setup-buildx-action@v3
2020

2121
- name: Log in to GitHub Container Registry
22-
uses: docker/login-action@v2
22+
uses: docker/login-action@v3
2323
with:
2424
registry: ghcr.io
2525
username: ${{ github.actor }}
2626
password: ${{ secrets.GITHUB_TOKEN }}
2727

2828
- name: Build and push Docker image
29-
uses: docker/build-push-action@v4
29+
uses: docker/build-push-action@v5
3030
with:
3131
context: .
3232
file: ./Dockerfile
3333
push: true
34-
tags: ghcr.io/offendingcommit/bingo:latest
34+
tags: |
35+
ghcr.io/offendingcommit/bingo:latest
36+
ghcr.io/offendingcommit/bingo:${{ github.sha }}
37+
${{ github.event_name == 'release' && format('ghcr.io/offendingcommit/bingo:{0}', github.ref_name) || '' }}
3538
build-args: BUILD_ENVIRONMENT=production

.github/workflows/helm-chart.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Checkout repository
19-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
2020

2121
- name: Set up Helm
2222
uses: azure/setup-helm@v1
@@ -31,7 +31,7 @@ jobs:
3131
runs-on: ubuntu-latest
3232
steps:
3333
- name: Checkout repository
34-
uses: actions/checkout@v3
34+
uses: actions/checkout@v4
3535

3636
- name: Set up Helm
3737
uses: azure/setup-helm@v1

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ venv.bak/
4242
*.log
4343
logs/
4444
.cache/
45+
.coverage
46+
.coverage.*
47+
htmlcov/
4548

4649
# OS files
4750
.DS_Store

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
- Initial project structure
12+
- Bingo board generation functionality
13+
- Interactive UI with NiceGUI
14+
- Board synchronization between views
15+
- Testing framework with pytest
16+
- Modular architecture with separate components
17+
- Semantic versioning with python-semantic-release
18+
- CI pipeline with GitHub Actions
19+
- Developer setup script
20+
21+
## [0.1.0] - 2025-03-02
22+
23+
### Added
24+
- Initial release
25+
- Basic bingo board functionality
26+
- Home and stream views
27+
- Dynamic board generation
28+
- Win pattern detection

CLAUDE.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# BINGO Project Guide
2+
3+
## Build Commands
4+
```bash
5+
# Quick setup for development
6+
./setup.sh
7+
8+
# Install dependencies
9+
poetry install
10+
11+
# Run application (old monolithic structure)
12+
poetry run python main.py
13+
14+
# Run application (new modular structure)
15+
poetry run python app.py
16+
17+
# Run tests
18+
poetry run pytest
19+
20+
# Run tests with coverage
21+
poetry run pytest --cov=src --cov-report=html
22+
23+
# Lint code
24+
poetry run flake8
25+
poetry run black --check .
26+
poetry run isort --check .
27+
28+
# Format code
29+
poetry run black .
30+
poetry run isort .
31+
32+
# Build Docker container
33+
docker build -t bingo .
34+
35+
# Run Docker container
36+
docker run -p 8080:8080 bingo
37+
38+
# Helm deployment
39+
cd helm && ./package.sh && helm install bingo ./bingo
40+
41+
# Using Makefile
42+
make install # Install dependencies
43+
make run # Run application
44+
make test # Run tests
45+
make lint # Run linters
46+
make format # Format code
47+
make build # Build package
48+
```
49+
50+
## Code Style Guidelines
51+
- **Imports**: Standard library first, third-party second, local modules last
52+
- **Formatting**: Use f-strings for string formatting
53+
- **Constants**: Defined at top of file in UPPER_CASE
54+
- **Naming**: snake_case for functions/variables, UPPER_CASE for constants
55+
- **Error Handling**: Use try/except blocks with proper logging
56+
- **UI Elements**: Define class constants for styling
57+
- **Logging**: Use Python's logging module with descriptive messages
58+
- **Comments**: Use docstrings for functions and descriptive comments
59+
- **Line Length**: Max 88 characters (Black's default)
60+
- **Code Formatting**: Use Black for code formatting and isort for import sorting
61+
62+
## Project Structure
63+
- `app.py`: Main entry point for modular application
64+
- `src/`: Source code directory
65+
- `config/`: Configuration and constants
66+
- `core/`: Core game logic
67+
- `ui/`: User interface components
68+
- `utils/`: Utility functions
69+
- `phrases.txt`: Contains customizable bingo phrases
70+
- `static/`: Static assets for fonts and styles
71+
- `tests/`: Unit and integration tests
72+
- `helm/`: Kubernetes deployment configuration
73+
- `.github/workflows/`: CI pipeline configuration
74+
- `CHANGELOG.md`: Release history tracking
75+
76+
## Git Workflow
77+
78+
### Branch Naming
79+
- Use feature branches for each change: `feature/description-of-change`
80+
- Use bugfix branches for bug fixes: `fix/description-of-bug`
81+
- Use chore branches for maintenance: `chore/description-of-task`
82+
83+
### Commit Guidelines
84+
Follow conventional changelog format:
85+
86+
```
87+
<type>(<scope>): <subject>
88+
89+
<body>
90+
91+
<footer>
92+
```
93+
94+
1. **Types**:
95+
- `feat`: A new feature
96+
- `fix`: A bug fix
97+
- `docs`: Documentation only changes
98+
- `style`: Changes that do not affect meaning (white-space, formatting)
99+
- `refactor`: Code change that neither fixes a bug nor adds a feature
100+
- `perf`: Change that improves performance
101+
- `test`: Adding missing tests or correcting existing tests
102+
- `chore`: Changes to the build process or auxiliary tools
103+
104+
2. **Scope** (optional): The module/component affected, e.g., `core`, `ui`, `board`
105+
106+
3. **Subject**: Short description in imperative, present tense (not past tense)
107+
- Good: "add feature X" (not "added feature X")
108+
- Use lowercase
109+
- No period at the end
110+
111+
4. **Body** (optional): Detailed explanation of changes
112+
- Use present tense
113+
- Include motivation and context
114+
- Explain "what" and "why" (not "how")
115+
116+
5. **Footer** (optional): Reference issues, PRs, breaking changes
117+
118+
### Example Commits:
119+
```
120+
feat(board): add color theme selector
121+
122+
Add ability for users to choose color themes for the bingo board
123+
124+
Resolves #123
125+
```
126+
127+
```
128+
fix(ui): resolve client disconnection issues
129+
130+
Handle race conditions during client disconnects to prevent
131+
server exceptions and ensure smooth reconnection
132+
133+
Fixes #456
134+
```
135+
136+
## Semantic Versioning
137+
138+
This project follows semantic versioning (SEMVER) principles:
139+
140+
- **MAJOR** version when making incompatible API changes (X.0.0)
141+
- **MINOR** version when adding functionality in a backwards compatible manner (0.X.0)
142+
- **PATCH** version when making backwards compatible bug fixes (0.0.X)
143+
144+
Version numbers are automatically updated by the CI/CD pipeline based on commit messages.
145+
The project uses python-semantic-release to analyze commit messages and determine the appropriate
146+
version bump according to the conventional commit format.
147+
148+
## CI/CD Pipeline
149+
150+
The project utilizes GitHub Actions for continuous integration and deployment:
151+
152+
1. **CI Job**:
153+
- Runs on each push to main and pull request
154+
- Installs dependencies
155+
- Runs linters (flake8, black, isort)
156+
- Runs all tests with pytest
157+
- Uploads coverage reports
158+
159+
2. **Release Job**:
160+
- Runs after successful CI job on the main branch
161+
- Determines new version based on commit messages
162+
- Updates CHANGELOG.md
163+
- Creates Git tag for the release
164+
- Publishes release on GitHub

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,17 @@ RUN --mount=type=cache,target=$POETRY_CACHE_DIR \
4343
# Copy the rest of the project
4444
COPY . /app
4545

46+
# Create a non-root user and switch to it
47+
RUN adduser --disabled-password --gecos "" appuser && \
48+
chown -R appuser:appuser /app
49+
USER appuser
50+
4651
# Expose port 8080 (if required)
4752
EXPOSE 8080
4853

54+
# Add healthcheck
55+
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
56+
CMD curl -f http://localhost:8080/ || exit 1
57+
4958
# Set the default command to run the application
5059
CMD ["python", "main.py"]

0 commit comments

Comments
 (0)