Initial commit

This commit is contained in:
florian committed 2026-11-20 15:09:18 +00:00
commit 1b0358c8c0
20 files changed
+835

No files matched your search

+94
View File
@@ -0,0 +1,94 @@
name: Build & Publish to GHCR
on:
workflow_dispatch:
env:
GHCR_ORG: gansejunge
IMAGE_NAME: app-notifications-GENERIC
IMAGE_PATH: ghcr.io/gansejunge/app-notifications-GENERIC
OPS_ORG: notifier
OPS_REPO: ops-deployment
OPS_BRANCH_BASE: main
OPS_PATH: GENERIC/deployment.yaml
jobs:
select-runner:
runs-on: ubuntu-latest
outputs:
runner: ${{ steps.pick.outputs.runner }}
steps:
- name: Check if local runner is online
id: pick
env:
API_TOKEN: ${{ secrets.GET_AVAILABLE_RUNNERS_API_TOKEN }}
API_URL: ${{ github.server_url }}/api/v1/admin/actions/runners
run: |
RUNNER="ubuntu-latest"
RESPONSE=$(curl -fsS --max-time 15 \
-H "Authorization: token ${API_TOKEN}" \
"${API_URL}" || echo "")
if [ -n "$RESPONSE" ]; then
ONLINE=$(echo "$RESPONSE" | jq '[.runners[]?
| select(.status != "offline")
| select(any(.labels[]?; .name == "local"))] | length')
if [ "${ONLINE:-0}" -gt 0 ]; then
RUNNER="local"
fi
else
echo "Runner API not reachable, falling back to ubuntu-latest"
fi
echo "Selected runner: $RUNNER"
echo "runner=$RUNNER" >> "$GITHUB_OUTPUT"
build:
needs: select-runner
runs-on: ${{ needs.select-runner.outputs.runner }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Log in to GHCR
run: echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin
- name: Get Latest Tag
id: get_tag
run: |
BASE64_TOKEN=$(echo "${{ secrets.GHCR_TOKEN }}" | base64)
LATEST_TAG=$(curl -s -H "Authorization: Bearer $BASE64_TOKEN" \
https://ghcr.io/v2/${{ env.GHCR_ORG }}/${{ env.IMAGE_NAME }}/tags/list \
| jq -r '.tags | map(select(test("^[0-9]+$"))) | map(tonumber) | max // 0')
NEXT_TAG=$((LATEST_TAG + 1))
echo "latest=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "next=$NEXT_TAG" >> $GITHUB_OUTPUT
- name: Build and Push Docker Image
run: |
docker build \
--build-arg COMMIT_ID=$(echo "${{ github.sha }}" | cut -c1-7) \
-t ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }} .
docker push ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }}
- name: Clone ops-deployment repo
uses: actions/checkout@v4
with:
repository: notifier/ops-deployment
path: ./ops-deployment
token: ${{ secrets.BOT_TOKEN }}
- name: Update ${{ github.repository }} deployment
working-directory: ./ops-deployment
run: |
NEW_TAG=${{ steps.get_tag.outputs.next }}
NEW_IMAGE="${{ env.IMAGE_PATH }}:$NEW_TAG"
git config user.name "automation-bot"
git config user.email "dev@gansejunge.com"
sed -i "s|ghcr.io/$GHCR_ORG/$IMAGE_NAME:[0-9]\+|$NEW_IMAGE|g" "$OPS_PATH"
COMMIT_URL="https://git.gansejunge.com/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}"
git add $OPS_PATH
git commit -m "Update ${GITHUB_REPOSITORY} image to version $NEW_TAG" -m "Linked build commit: $COMMIT_URL"
git push origin $OPS_BRANCH_BASE
@@ -0,0 +1,60 @@
name: Generate openapi.json
on:
push:
branches: [main]
workflow_dispatch:
env:
TITLE: GENERIC
OUTPUT: GENERIC-openapi.json
DOCS_BRANCH_BASE: main
jobs:
generate-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Generate openapi.json
shell: bash
run: |
pip install -r requirements.txt
python scripts/dump_openapi.py --out "${{ env.OUTPUT }}" --title "${{ env.TITLE }}"
- name: Clone openapi-gateway-docs repo
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/openapi-gateway-docs
path: ./openapi-gateway-docs
ref: ${{ env.DOCS_BRANCH_BASE }}
token: ${{ secrets.BOT_TOKEN }}
- name: Move generated openapi.json
run: |
mkdir -p openapi-gateway-docs/sources
mv "${{ env.OUTPUT }}" "openapi-gateway-docs/sources/${{ env.OUTPUT }}"
- name: Generate markdown
working-directory: ./openapi-gateway-docs
run: python gen_docs.py
- name: Update openapi-gateway-docs
working-directory: ./openapi-gateway-docs
run: |
git config user.name "automation-bot"
git config user.email "dev@gansejunge.com"
git add sources API-*.md
if git diff --cached --quiet; then
echo "No documentation changes to commit"
exit 0
fi
COMMIT_URL="https://git.gansejunge.com/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}"
git commit -m "Updated docs for ${GITHUB_REPOSITORY}" -m "Linked build commit: $COMMIT_URL"
git pull --rebase origin "$DOCS_BRANCH_BASE"
git push origin "HEAD:$DOCS_BRANCH_BASE"
+78
View File
@@ -0,0 +1,78 @@
name: pip-audit
on:
schedule:
- cron: "35 1 * * *"
push:
branches: [main]
paths: [requirements.txt, scripts/filter_requirements.py]
workflow_dispatch:
jobs:
audit:
runs-on: ubuntu-latest
outputs:
report_b64: ${{ steps.audit.outputs.report_b64 }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Audit dependencies
id: audit
shell: bash
run: |
pip install pip-audit
python3 scripts/filter_requirements.py requirements.txt requirements.audit.txt
# Don't let a non-zero exit abort the step, so the report is saved first
set +e
pip-audit -r requirements.audit.txt --no-deps --disable-pip > audit.txt 2>&1
echo $? > audit.exit
set -e
cat audit.txt
echo "report_b64=$(head -c 100000 audit.txt | base64 -w0)" >> "$GITHUB_OUTPUT"
- name: Fail if the audit failed
shell: bash
run: exit "$(cat audit.exit)"
notify:
needs: audit
if: ${{ always() && needs.audit.result == 'failure' }}
runs-on: host
steps:
- name: Send mail via local postfix
env:
MAIL_FROM: ${{ vars.MAIL_FROM }}
MAIL_TO: ${{ vars.MAIL_TO }}
REPO: ${{ gitea.repository }}
RUN_URL: ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_number }}
REPORT_B64: ${{ needs.audit.outputs.report_b64 }}
run: |
python3 - <<'EOF'
import base64, os, smtplib
from email.message import EmailMessage
b64 = os.environ.get("REPORT_B64", "")
report = (
base64.b64decode(b64).decode("utf-8", errors="replace")
if b64 else
"(no audit output, the job failed before pip-audit finished)"
)
msg = EmailMessage()
msg["Subject"] = f"[pip-audit] Problem in {os.environ['REPO']}"
msg["From"] = os.environ["MAIL_FROM"]
msg["To"] = os.environ["MAIL_TO"]
msg.set_content(
f"pip-audit result for {os.environ['REPO']}:\n\n"
f"{report}\n\n"
f"Run: {os.environ['RUN_URL']}\n"
)
with smtplib.SMTP("127.0.0.1", 25, timeout=30) as s:
s.send_message(msg)
EOF