Skip to content

Commit 729af9e

Browse files
committed
feat: initial implementation of Markdown to BBCode converter
- Complete Python-based converter with support for headers, formatting, code blocks, links, images, lists, quotes, and horizontal rules - Comprehensive test suite - Docker containerization with multi-architecture support - CLI interface with flexible input/output options - Semantic-release integration for automated versioning - GPL v3 licensed open source project BREAKING CHANGE: Initial release
0 parents  commit 729af9e

19 files changed

+2898
-0
lines changed

.dockerignore

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Python
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
*.so
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# Virtual environments
28+
.env
29+
.venv
30+
env/
31+
venv/
32+
ENV/
33+
env.bak/
34+
venv.bak/
35+
36+
# IDE
37+
.vscode/
38+
.idea/
39+
*.swp
40+
*.swo
41+
*~
42+
43+
# OS
44+
.DS_Store
45+
Thumbs.db
46+
47+
# Documentation
48+
*.md
49+
!README.md
50+
51+
# Test files
52+
test/
53+
tests/
54+
*.test.py

.github/ACTIONS_REFERENCE.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# GitHub Actions Quick Reference
2+
3+
## Workflow Overview
4+
5+
This project uses two GitHub Actions workflows for CI/CD:
6+
7+
### 1. Main CI/CD Pipeline (`.github/workflows/ci-cd.yml`)
8+
9+
**Triggers:**
10+
- Push to `main` or `develop` branches
11+
- Pull requests to `main`
12+
13+
**Jobs:**
14+
1. **test** - Run tests on Python 3.8, 3.9, 3.10, 3.11, 3.12
15+
2. **docker-test** - Build and test Docker image
16+
3. **release** - Run semantic-release to determine if new version needed
17+
4. **docker-build-and-push** - Build multi-arch images and push to Docker Hub (only on new releases)
18+
5. **security-scan** - Scan published images for vulnerabilities (only on new releases)
19+
20+
### 2. Pull Request Tests (`.github/workflows/pr-test.yml`)
21+
22+
**Triggers:**
23+
- Pull requests to `main` or `develop`
24+
25+
**Jobs:**
26+
1. **test** - Quick tests on Python 3.8 and 3.11
27+
2. **docker-test** - Basic Docker build test
28+
29+
## Deployment Strategy
30+
31+
### Branch Strategy
32+
- **main** - Production releases, Docker images tagged as `latest`
33+
- **develop** - Development branch (if used)
34+
- **feature branches** - Pull request testing only
35+
36+
### Version Strategy
37+
- **Semantic Release** - Automatically determines version based on conventional commits
38+
- **Docker Tags** - Only created when semantic-release creates a new version
39+
40+
**Tags Created**:
41+
- `latest` - Latest stable release from main branch
42+
- `v1.2.3` - Specific version tags
43+
- `1.2` - Major.minor tags
44+
- `1` - Major version tags
45+
46+
## Monitoring
47+
48+
- **Actions Tab** - View workflow runs and logs
49+
- **Security Tab** - View vulnerability scan results
50+
- **Releases** - View automatically created releases
51+
- **Docker Hub** - View published images
52+
53+
## Release Process
54+
55+
1. **Conventional Commits** - Developers use conventional commit format
56+
2. **Merge to Main** - Triggers CI/CD pipeline
57+
3. **Semantic Release** - Analyzes commits and creates release if needed
58+
4. **Docker Deployment** - Only happens if new release was created
59+
5. **Security Scanning** - All published images are scanned
60+
61+
## Commit Impact on Releases
62+
63+
| Commit Type | Version Impact | Example |
64+
|-------------|----------------|---------|
65+
| `feat:` | Minor (1.0.0 → 1.1.0) | `feat: add table support` |
66+
| `fix:` | Patch (1.1.0 → 1.1.1) | `fix: resolve parsing bug` |
67+
| `feat!:` | Major (1.1.1 → 2.0.0) | `feat!: redesign API` |
68+
| `docs:` | Patch (2.0.0 → 2.0.1) | `docs: update readme` |
69+
| `test:` | No release | `test: add unit tests` |
70+
| `chore:` | No release | `chore: update deps` |
71+
72+
For detailed commit guidelines, see [CONTRIBUTING.md](../CONTRIBUTING.md).

.github/workflows/ci-cd.yml

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
DOCKER_IMAGE: md-to-bbcode
11+
DOCKER_REGISTRY: docker.io
12+
13+
jobs:
14+
test:
15+
name: Run Tests
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
python-version: [3.8, 3.9, '3.10', 3.11, 3.12]
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
30+
- name: Cache pip dependencies
31+
uses: actions/cache@v3
32+
with:
33+
path: ~/.cache/pip
34+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
35+
restore-keys: |
36+
${{ runner.os }}-pip-
37+
38+
- name: Install dependencies
39+
run: |
40+
python -m pip install --upgrade pip
41+
pip install -r requirements.txt
42+
43+
- name: Run tests
44+
run: |
45+
python test_converter.py
46+
47+
- name: Test CLI functionality
48+
run: |
49+
# Test version command
50+
python md_to_bbcode.py --version
51+
52+
# Test basic conversion
53+
echo "# Test **bold** and *italic*" | python md_to_bbcode.py > output.bbcode
54+
cat output.bbcode
55+
56+
# Test file conversion
57+
python md_to_bbcode.py -f sample.md -o sample_output.bbcode
58+
ls -la *.bbcode
59+
60+
docker-test:
61+
name: Docker Tests
62+
runs-on: ubuntu-latest
63+
needs: test
64+
65+
steps:
66+
- name: Checkout code
67+
uses: actions/checkout@v4
68+
69+
- name: Set up Docker Buildx
70+
uses: docker/setup-buildx-action@v3
71+
72+
- name: Build Docker image for testing
73+
run: |
74+
docker build -t ${{ env.DOCKER_IMAGE }}:test .
75+
76+
- name: Test Docker image
77+
run: |
78+
# Test basic functionality
79+
echo "# Docker Test **works**" | docker run --rm -i ${{ env.DOCKER_IMAGE }}:test
80+
81+
# Test file conversion
82+
docker run --rm -v $(pwd):/data ${{ env.DOCKER_IMAGE }}:test -f /data/sample.md
83+
84+
# Test version
85+
docker run --rm ${{ env.DOCKER_IMAGE }}:test --version
86+
87+
# Test help
88+
docker run --rm ${{ env.DOCKER_IMAGE }}:test --help
89+
90+
release:
91+
name: Semantic Release
92+
runs-on: ubuntu-latest
93+
needs: [test, docker-test]
94+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
95+
outputs:
96+
new-release-published: ${{ steps.semantic.outputs.new-release-published }}
97+
new-release-version: ${{ steps.semantic.outputs.new-release-version }}
98+
99+
steps:
100+
- name: Checkout code
101+
uses: actions/checkout@v4
102+
with:
103+
fetch-depth: 0
104+
105+
- name: Setup Node.js
106+
uses: actions/setup-node@v4
107+
with:
108+
node-version: 20
109+
cache: npm
110+
111+
- name: Install semantic-release dependencies
112+
run: npm ci
113+
114+
- name: Run semantic-release
115+
id: semantic
116+
env:
117+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
118+
run: npx semantic-release
119+
120+
docker-build-and-push:
121+
name: Build and Push Docker Image
122+
runs-on: ubuntu-latest
123+
needs: release
124+
if: needs.release.outputs.new-release-published == 'true'
125+
126+
steps:
127+
- name: Checkout code
128+
uses: actions/checkout@v4
129+
with:
130+
ref: main
131+
fetch-depth: 0
132+
133+
- name: Set up Docker Buildx
134+
uses: docker/setup-buildx-action@v3
135+
136+
- name: Log in to Docker Hub
137+
uses: docker/login-action@v3
138+
with:
139+
username: ${{ secrets.DOCKER_USERNAME }}
140+
password: ${{ secrets.DOCKER_PASSWORD }}
141+
142+
- name: Extract metadata
143+
id: meta
144+
uses: docker/metadata-action@v5
145+
with:
146+
images: ${{ secrets.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGE }}
147+
tags: |
148+
type=semver,pattern={{version}},value=v${{ needs.release.outputs.new-release-version }}
149+
type=semver,pattern={{major}}.{{minor}},value=v${{ needs.release.outputs.new-release-version }}
150+
type=semver,pattern={{major}},value=v${{ needs.release.outputs.new-release-version }}
151+
type=raw,value=latest
152+
153+
- name: Build and push Docker image
154+
uses: docker/build-push-action@v5
155+
with:
156+
context: .
157+
platforms: linux/amd64,linux/arm64
158+
push: true
159+
tags: ${{ steps.meta.outputs.tags }}
160+
labels: ${{ steps.meta.outputs.labels }}
161+
cache-from: type=gha
162+
cache-to: type=gha,mode=max
163+
164+
- name: Test published image
165+
run: |
166+
# Wait a moment for the image to be available
167+
sleep 10
168+
169+
# Test the published image
170+
echo "# Published Test v${{ needs.release.outputs.new-release-version }} **success**" | docker run --rm -i ${{ secrets.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGE }}:${{ needs.release.outputs.new-release-version }}
171+
172+
security-scan:
173+
name: Security Scan
174+
runs-on: ubuntu-latest
175+
needs: [release, docker-build-and-push]
176+
if: needs.release.outputs.new-release-published == 'true'
177+
178+
steps:
179+
- name: Checkout code
180+
uses: actions/checkout@v4
181+
182+
- name: Run Trivy vulnerability scanner
183+
uses: aquasecurity/trivy-action@master
184+
with:
185+
image-ref: ${{ secrets.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGE }}:${{ needs.release.outputs.new-release-version }}
186+
format: 'sarif'
187+
output: 'trivy-results.sarif'
188+
189+
- name: Upload Trivy scan results to GitHub Security tab
190+
uses: github/codeql-action/upload-sarif@v3
191+
if: always()
192+
with:
193+
sarif_file: 'trivy-results.sarif'

.github/workflows/pr-test.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Pull Request Tests
2+
3+
on:
4+
pull_request:
5+
branches: [ main, develop ]
6+
types: [opened, synchronize, reopened]
7+
8+
jobs:
9+
test:
10+
name: Test on Python ${{ matrix.python-version }}
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: [3.8, 3.11] # Test on minimum and latest supported versions
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install -r requirements.txt
29+
30+
- name: Run tests
31+
run: |
32+
python test_converter.py
33+
34+
- name: Test CLI
35+
run: |
36+
echo "# PR Test **bold** and *italic*" | python md_to_bbcode.py
37+
python md_to_bbcode.py -f sample.md
38+
39+
docker-test:
40+
name: Docker Build Test
41+
runs-on: ubuntu-latest
42+
43+
steps:
44+
- name: Checkout code
45+
uses: actions/checkout@v4
46+
47+
- name: Build Docker image
48+
run: |
49+
docker build -t md-to-bbcode:pr-test .
50+
51+
- name: Test Docker image
52+
run: |
53+
echo "# Docker PR Test" | docker run --rm -i md-to-bbcode:pr-test
54+
docker run --rm -v $(pwd):/data md-to-bbcode:pr-test -f /data/sample.md

0 commit comments

Comments
 (0)