11 Commits

Author SHA1 Message Date
Gitea CI
d0dafec4cb Bump version: 0.1.2 → 0.1.3 2025-11-25 10:06:03 +00:00
075041f371 Update pyproject.toml 2025-11-25 10:00:51 +00:00
981d5211b6 Merge pull request 'Add new env variable to use prefixes in url [release-patch]' (#8) from dev into main
Reviewed-on: #8
2025-11-25 09:57:16 +00:00
e0988cf23b lint
Some checks failed
PR tests / build-image (pull_request) Successful in 2m44s
PR tests / smoke-tests (pull_request) Successful in 34s
/ build (pull_request) Failing after 42s
2025-11-25 10:52:59 +01:00
22813bab65 feat: add API prefix for prefixes in url 2025-11-25 10:52:21 +01:00
d5cf0a8636 Merge pull request 'dev' (#7) from dev into main
Reviewed-on: #7
2025-11-25 09:51:05 +00:00
d6aeabc0a9 new download image
All checks were successful
PR tests / build-image (pull_request) Successful in 1m15s
PR tests / smoke-tests (pull_request) Successful in 37s
/ build (pull_request) Has been skipped
2025-11-25 10:48:41 +01:00
5456f8e740 new upload artifact image
Some checks failed
PR tests / build-image (pull_request) Successful in 1m15s
PR tests / smoke-tests (pull_request) Failing after 31s
2025-11-25 10:46:21 +01:00
26ebe3b40e increase version of upload-artifact
Some checks failed
PR tests / build-image (pull_request) Failing after 1m27s
PR tests / smoke-tests (pull_request) Has been skipped
2025-11-25 10:41:24 +01:00
25bc94dfa5 test: split workflow into parts
Some checks failed
PR tests / build-image (pull_request) Failing after 2m19s
PR tests / smoke-tests (pull_request) Has been skipped
2025-11-25 10:21:23 +01:00
0c251ac807 feat: only install bibapi catalogue dependencies 2025-11-25 10:20:45 +01:00
4 changed files with 93 additions and 38 deletions

View File

@@ -75,6 +75,18 @@ jobs:
run: | run: |
git config user.name "Gitea CI" git config user.name "Gitea CI"
git config user.email "ci@git.theprivateserver.de" git config user.email "ci@git.theprivateserver.de"
- name: Determine branch to push to
id: push_branch
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
# workflow_dispatch runs on a branch ref like refs/heads/main
BRANCH=${GITHUB_REF#refs/heads/}
else
# for a merged PR use the PR base ref (target branch)
BRANCH=${{ github.event.pull_request.base.ref }}
fi
echo "PUSH_BRANCH=$BRANCH" >> $GITHUB_ENV
- name: Bump version - name: Bump version
id: bump id: bump
run: | run: |
@@ -133,7 +145,7 @@ jobs:
uses: ad-m/github-push-action@master uses: ad-m/github-push-action@master
with: with:
github_token: ${{ secrets.GITHUB_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }} branch: ${{ env.PUSH_BRANCH }}
- name: Build Changelog - name: Build Changelog
id: build_changelog id: build_changelog
uses: https://github.com/mikepenz/release-changelog-builder-action@v5 uses: https://github.com/mikepenz/release-changelog-builder-action@v5

View File

@@ -5,7 +5,7 @@ on:
types: [opened, synchronize, edited, reopened] types: [opened, synchronize, edited, reopened]
jobs: jobs:
build-and-smoke: build-image:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@@ -17,24 +17,48 @@ jobs:
- name: Install uv - name: Install uv
uses: astral-sh/setup-uv@v5 uses: astral-sh/setup-uv@v5
- name: Set up Python
run: uv python install - name: (optional) Prepare dependencies
with:
python-version-file: "pyproject.toml"
- name: Install the project dependencies
run: | run: |
uv sync --all-groups uv python install --python-version-file pyproject.toml || true
uv add pip uv sync --all-groups || true
uv export --format requirements.txt -o requirements.txt uv add pip || true
# uv run python -m pip install --upgrade pip uv export --format requirements.txt -o requirements.txt || true
# uv run python -m pip install -r requirements.txt
- name: Build image - name: Build image
run: | run: |
docker build -t semapform-api:test-pr . docker build -t semapform-api:test-pr .
- name: Save image artifact
run: |
docker save semapform-api:test-pr -o semapform-api.tar
- name: Upload image artifact
uses: https://github.com/christopherHX/gitea-upload-artifact@v4
with:
name: semapform-image
path: semapform-api.tar
retention-days: 1
smoke-tests:
needs: build-image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download image artifact
uses: christopherhx/gitea-download-artifact@v4
with:
name: semapform-image
- name: Restore image
run: |
docker load -i semapform-api.tar
- name: Start container (background) - name: Start container (background)
run: | run: |
# do NOT bind the container port to the host to avoid port conflicts on the runner
docker run -d --name semapform-test semapform-api:test-pr sleep infinity docker run -d --name semapform-test semapform-api:test-pr sleep infinity
- name: Start server in container and smoke test HTTP (in-container) - name: Start server in container and smoke test HTTP (in-container)
@@ -46,7 +70,6 @@ jobs:
# show container status to aid debugging # show container status to aid debugging
docker ps -a --filter name=semapform-test || true docker ps -a --filter name=semapform-test || true
# perform a readiness loop (try container-local /health) using small execs
echo "waiting for service to become ready inside container" echo "waiting for service to become ready inside container"
set -e set -e
READY=0 READY=0
@@ -64,11 +87,9 @@ jobs:
exit 1 exit 1
fi fi
# Run the repository smoke-test script inside the container and surface its output
echo "running test_api.py inside container" echo "running test_api.py inside container"
docker exec semapform-test python test_api.py || true docker exec semapform-test python test_api.py || true
# dump the last 200 lines of logs so this step always displays useful output
docker logs semapform-test --tail 200 || true docker logs semapform-test --tail 200 || true
- name: Cleanup container - name: Cleanup container

View File

@@ -12,6 +12,28 @@ from fastapi.responses import JSONResponse
app = FastAPI(title="Signature Validation API") app = FastAPI(title="Signature Validation API")
# Optional path prefix support: when behind a reverse-proxy that uses a
# URL prefix (eg. `https://api.example.tld/library/...`) set `API_PREFIX` to
# that prefix (example: `/library`) so incoming requests are rewritten to the
# application root. This keeps route definitions unchanged while supporting
# both proxied and direct deployments.
_api_prefix_raw = os.getenv("API_PREFIX", "").strip()
api_prefix = ""
if _api_prefix_raw:
if not _api_prefix_raw.startswith("/"):
_api_prefix_raw = "/" + _api_prefix_raw
api_prefix = _api_prefix_raw.rstrip("/")
@app.middleware("http")
async def _strip_api_prefix(request, call_next):
if api_prefix and request.url.path.startswith(api_prefix):
new_path = request.url.path[len(api_prefix) :]
request.scope["path"] = new_path or "/"
request.scope["root_path"] = api_prefix
return await call_next(request)
# Allow PHP application to call this API # Allow PHP application to call this API
app.add_middleware( app.add_middleware(
CORSMiddleware, CORSMiddleware,

View File

@@ -1,11 +1,11 @@
[project] [project]
name = "semapform-api" name = "semapform-api"
version = "0.1.2" version = "0.1.3"
description = "Add your description here" description = "Add your description here"
readme = "README.md" readme = "README.md"
requires-python = ">=3.13" requires-python = ">=3.13"
dependencies = [ dependencies = [
"bibapi>=0.0.5", "bibapi[catalogue]>=0.0.6",
"fastapi>=0.122.0", "fastapi>=0.122.0",
"pip>=25.3", "pip>=25.3",
"uvicorn>=0.38.0", "uvicorn>=0.38.0",
@@ -15,7 +15,7 @@ name = "gitea"
url = "https://git.theprivateserver.de/api/packages/PHB/pypi/simple/" url = "https://git.theprivateserver.de/api/packages/PHB/pypi/simple/"
[tool.bumpversion] [tool.bumpversion]
current_version = "0.1.2" current_version = "0.1.3"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)" parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"] serialize = ["{major}.{minor}.{patch}"]
search = "{current_version}" search = "{current_version}"