Skip to content

Commit 3a91fd8

Browse files
committed
refactor(initial-project-setup): initial project setup
1 parent 6d6e7ed commit 3a91fd8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+5408
-0
lines changed

.github/workflows/ci.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Python backend server tests
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review, draft]
6+
paths:
7+
- 'src/codesphere_sdk/**'
8+
- '.github/workflows/backend-app.yml'
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
14+
jobs:
15+
pytest:
16+
runs-on: ubuntu-latest
17+
18+
permissions:
19+
contents: read
20+
pull-requests: write
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Install uv package manager
27+
uses: astral-sh/setup-uv@v6
28+
with:
29+
activate-environment: true
30+
31+
- name: Install dependencies using uv
32+
run: |
33+
uv sync
34+
shell: bash
35+
36+
- name: Run Bandit security check on backend code
37+
id: bandit_check
38+
run: |
39+
echo "Running Bandit security check..."
40+
set +e
41+
bandit -r . -c pyproject.toml --format=custom --msg-template "{abspath}:{line}: {test_id}[{severity}]: {msg}" -o bandit-results.txt
42+
cat bandit-results.txt
43+
BANDIT_EXIT_CODE=$?
44+
set -e
45+
echo "Bandit scan finished. Exit code: $BANDIT_EXIT_CODE"
46+
echo "BANDIT_EXIT_CODE=${BANDIT_EXIT_CODE}" >> $GITHUB_ENV
47+
shell: bash
48+
49+
- name: Prepare Bandit comment body
50+
id: prep_bandit_comment
51+
if: github.event_name == 'pull_request'
52+
run: |
53+
echo "Preparing Bandit comment body..."
54+
COMMENT_BODY_FILE="bandit-comment-body.md"
55+
echo "COMMENT_BODY_FILE=${COMMENT_BODY_FILE}" >> $GITHUB_ENV
56+
57+
echo "### 🛡️ Bandit Security Scan Results" > $COMMENT_BODY_FILE
58+
echo "" >> $COMMENT_BODY_FILE
59+
echo "" >> $COMMENT_BODY_FILE
60+
echo "" >> $COMMENT_BODY_FILE
61+
62+
if [ -s backend/bandit-results.txt ]; then
63+
echo "\`\`\`text" >> $COMMENT_BODY_FILE
64+
cat backend/bandit-results.txt >> $COMMENT_BODY_FILE
65+
echo "\`\`\`" >> $COMMENT_BODY_FILE
66+
else
67+
echo "✅ No security issues found by Bandit." >> $COMMENT_BODY_FILE
68+
fi
69+
shell: bash
70+
71+
- name: Find Comment
72+
uses: peter-evans/find-comment@v3
73+
id: fc
74+
with:
75+
issue-number: ${{ github.event.pull_request.number }}
76+
comment-author: 'github-actions[bot]'
77+
body-includes: Bandit Security Scan Results
78+
79+
- name: Post Bandit results as PR comment
80+
if: github.event_name == 'pull_request' && always()
81+
uses: peter-evans/create-or-update-comment@v4
82+
with:
83+
token: ${{ secrets.GITHUB_TOKEN }}
84+
repository: ${{ github.repository }}
85+
issue-number: ${{ github.event.pull_request.number }}
86+
comment-id: ${{ steps.fc.outputs.comment-id }}
87+
body-file: ${{ env.COMMENT_BODY_FILE }}
88+
edit-mode: replace
89+
90+
- name: Run tests with pytest using uv
91+
run: |
92+
pytest --junitxml=junit/test-results.xml --cov-report=xml --cov-report=html --cov=. | tee pytest-coverage.txt
93+
shell: bash
94+
95+
- name: Pytest coverage comment
96+
if: github.event_name == 'pull_request' && always()
97+
uses: MishaKav/pytest-coverage-comment@main
98+
with:
99+
unique-id-for-comment: coverage-report
100+
pytest-xml-coverage-path: coverage.xml
101+
pytest-coverage-path: pytest-coverage.txt
102+
junitxml-path: junit/test-results.xml
103+
title: Pytest Coverage Report
104+
junitxml-title: Test Execution Summary
105+
106+
- name: Minimize uv cache
107+
run: uv cache prune --ci

.github/workflows/publish.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# .github/workflows/release.yml
2+
3+
name: Create Release and Publish to PyPI
4+
5+
on:
6+
push:
7+
tags:
8+
- 'v*'
9+
branches:
10+
- main
11+
12+
env:
13+
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
14+
15+
jobs:
16+
uv-example:
17+
name: python
18+
runs-on: ubuntu-latest
19+
20+
permissions:
21+
contents: write
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Install uv
27+
uses: astral-sh/setup-uv@v5
28+
29+
- name: "Set up Python"
30+
uses: actions/setup-python@v5
31+
with:
32+
python-version-file: ".python-version"
33+
34+
- name: Install the project
35+
run: uv sync --locked --all-extras --dev
36+
37+
- name: Build package
38+
run: make pypi
39+
40+
- name: Create GitHub Release
41+
uses: softprops/action-gh-release@v2
42+
with:
43+
generate_release_notes: true
44+
files: dist/*

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Python-generated files
2+
__pycache__/
3+
*.py[oc]
4+
*.pyc
5+
*.pyo
6+
*.pyd
7+
build/
8+
dist/
9+
wheels/
10+
*.egg-info
11+
12+
# Ruff cache
13+
.ruff_cache
14+
15+
# Virtual environment
16+
.venv/
17+
venv/
18+
env/

.pre-commit-config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.6.0
4+
hooks:
5+
- id: check-yaml
6+
- id: check-toml
7+
8+
- repo: https://github.com/astral-sh/ruff-pre-commit
9+
rev: v0.11.13
10+
hooks:
11+
- id: ruff-check
12+
args: [ --fix ]
13+
- id: ruff-format
14+
15+
- repo: https://github.com/commitizen-tools/commitizen
16+
rev: v4.8.3
17+
hooks:
18+
- id: commitizen
19+
- id: commitizen-branch
20+
stages: [pre-push]

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12.9

CONTRIBUTING

Whitespace-only changes.

LICENSE

Whitespace-only changes.

Makefile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
.PHONY: help install commit lint format test bump
2+
3+
.DEFAULT_GOAL := help
4+
5+
help: ## Shows a help message with all available commands
6+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
7+
8+
install: ## Sets up the development environment
9+
@echo ">>> Setting up the development environment..."
10+
@echo "1. Creating virtual environment with uv..."
11+
uv venv
12+
@echo "2. Installing all dependencies (including 'dev')..."
13+
uv pip install -e '.[dev]'
14+
@echo "3. Installing git hooks with pre-commit..."
15+
pre-commit install --hook-type commit-msg --hook-type pre-commit --hook-type pre-push
16+
@echo "\n\033[0;32mSetup complete! Please activate the virtual environment with 'source .venv/bin/activate'.\033[0m"
17+
18+
commit: ## Starts Commitizen for a guided commit message
19+
@echo ">>> Starting Commitizen for a guided commit message..."
20+
@if git diff --cached --quiet; then \
21+
echo "\033[0;33mWarning: No changes added to commit (please use 'git add ...' first).\033[0m"; \
22+
exit 1; \
23+
fi
24+
uv run cz commit
25+
uv run cz bump --changelog --allow-no-commit
26+
27+
28+
lint: ## Checks code quality with ruff
29+
@echo ">>> Checking code quality with ruff..."
30+
uv run ruff check src tests
31+
32+
format: ## Formats code with ruff
33+
@echo ">>> Formatting code with ruff..."
34+
uv run ruff format src tests
35+
36+
test: ## Runs tests with pytest
37+
@echo ">>> Running tests with pytest..."
38+
uv run pytest
39+
40+
release: ## Pushes a new tag and release
41+
@echo ">>> Starting release process..."
42+
git config --global push.followTags true
43+
44+
@echo "\n>>> Verifying tag and pushing to remote..."
45+
export VERSION=$$(uv run cz version --project); \
46+
if [ -z "$${VERSION}" ]; then \
47+
echo "\033[0;31mERROR: Could not determine version using 'cz version --project'.\033[0m"; \
48+
exit 1; \
49+
fi; \
50+
echo "--- Found project version: v$${VERSION} ---"; \
51+
if git rev-parse "v$${VERSION}" >/dev/null 2>&1; then \
52+
echo "--- Verified local tag v$${VERSION} exists. ---"; \
53+
else \
54+
echo "\033[0;31mERROR: Git tag v$${VERSION} was not found! Please check for errors.\033[0m"; \
55+
exit 1; \
56+
fi; \
57+
echo "--- Pushing commit and tag to remote... ---"; \
58+
git tag -d v$${VERSION}; \
59+
git tag -a v$${VERSION} -m "Release $${VERSION}"; \
60+
git push --follow-tags; \
61+
echo "\n\033[0;32m✅ SUCCESS: Tag v$${VERSION} pushed to GitHub. The release workflow has been triggered.\033[0m"
62+
63+
pypi: ## publishes to PyPI
64+
@echo "\n>>> Building package for distribution..."
65+
uv build
66+
@echo "\n>>> Publishing to PyPI..."
67+
uv publish
68+
@echo "\n\033[0;32mPyPI release complete! The GitHub Action will now create the GitHub Release.\033[0m"

examples/domains/create_domain.py

Whitespace-only changes.

examples/domains/delete_domain.py

Whitespace-only changes.

0 commit comments

Comments
 (0)