From b746cfc555df4af4ae37c202b90810759405bff1 Mon Sep 17 00:00:00 2001 From: Andrew Kettel Date: Thu, 26 Mar 2026 12:50:01 -0700 Subject: [PATCH 1/2] Adding Gitea CI/CD --- .gitea/workflows/ci.yml | 69 ++++++++++++++++++++++++++ .gitea/workflows/dependency_update.yml | 46 +++++++++++++++++ scripts/create_pr_gitea.sh | 42 ++++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 .gitea/workflows/ci.yml create mode 100644 .gitea/workflows/dependency_update.yml create mode 100755 scripts/create_pr_gitea.sh diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..7192a2b --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,69 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + - cron: "0 9 * * 1" # weekly Monday 9am + +jobs: + install: + runs-on: ubuntu-latest + container: python:3.13-slim + steps: + - uses: actions/checkout@v3 + + - name: Install system dependencies + run: apt-get update -qq && apt-get install -y -qq libcap-dev + + - name: Install Poetry + run: pip install poetry==2.1.1 + + - name: Install dependencies + run: poetry install --without pi --no-interaction + + - name: Cache venv + uses: actions/cache@v3 + with: + path: .venv + key: venv-${{ hashFiles('pyproject.toml') }} + + black: + runs-on: ubuntu-latest + container: python:3.13-slim + needs: install + steps: + - uses: actions/checkout@v3 + - run: pip install poetry==2.1.1 + - run: poetry run black --check src/ tests/ + + ruff: + runs-on: ubuntu-latest + container: python:3.13-slim + needs: install + steps: + - uses: actions/checkout@v3 + - run: pip install poetry==2.1.1 + - run: poetry run ruff check src/ tests/ + + mypy: + runs-on: ubuntu-latest + container: python:3.13-slim + needs: install + steps: + - uses: actions/checkout@v3 + - run: pip install poetry==2.1.1 + - run: poetry run mypy src/ + + pytest: + runs-on: ubuntu-latest + container: python:3.13-slim + needs: install + steps: + - uses: actions/checkout@v3 + - run: apt-get update -qq && apt-get install -y -qq libcap-dev + - run: pip install poetry==2.1.1 + - run: poetry install --without pi --no-interaction + - run: poetry run pytest diff --git a/.gitea/workflows/dependency_update.yml b/.gitea/workflows/dependency_update.yml new file mode 100644 index 0000000..c18b21c --- /dev/null +++ b/.gitea/workflows/dependency_update.yml @@ -0,0 +1,46 @@ +name: Dependency update + +on: + push: + branches: [main] + schedule: + - cron: "0 9 * * 1" + +jobs: + dependency-update: + runs-on: ubuntu-latest + container: python:3.13-slim + # skip if this is already a dependency update branch + if: "!startsWith(github.ref, 'refs/heads/dependency-updates-')" + steps: + - uses: actions/checkout@v3 + with: + token: ${{ secrets.CI_TOKEN }} + + - name: Install system dependencies + run: apt-get update -qq && apt-get install -y -qq libcap-dev git curl + + - name: Install Poetry + run: pip install poetry==2.1.1 + + - name: Install dependencies + run: poetry install --without pi --no-interaction + + - name: Run dependency update check + id: update + run: | + chmod +x scripts/dependency_update.sh + set +e + bash scripts/dependency_update.sh + echo "changes=$?" >> $GITHUB_OUTPUT + + - name: Create pull request + if: steps.update.outputs.changes == '1' + env: + CI_TOKEN: ${{ secrets.CI_TOKEN }} + CI_SERVER_URL: ${{ secrets.CI_SERVER_URL }} + REPO: ${{ github.repository }} + ASSIGNEE_ID: ${{ secrets.CI_ASSIGNEE_ID }} + run: | + chmod +x scripts/create_pr_gitea.sh + bash scripts/create_pr_gitea.sh diff --git a/scripts/create_pr_gitea.sh b/scripts/create_pr_gitea.sh new file mode 100755 index 0000000..d2e1f7e --- /dev/null +++ b/scripts/create_pr_gitea.sh @@ -0,0 +1,42 @@ +#!/bin/bash +set -e + +BRANCH="dependency-updates-$(date +%Y%m%d)" +SUMMARY_FILE="/tmp/update_summary.md" + +git config user.email "ci@gitea.com" +git config user.name "Gitea CI" + +git checkout -b "$BRANCH" +git add pyproject.toml poetry.lock +git commit -m "chore: update dependencies $(date +%Y-%m-%d)" +git push "https://oauth2:${CI_TOKEN}@${CI_SERVER_URL#https://}/${REPO}.git" "$BRANCH" + +DESCRIPTION=$(cat "$SUMMARY_FILE") + +HTTP_RESPONSE=$(curl --silent --show-error \ + --write-out "HTTPSTATUS:%{http_code}" \ + --request POST \ + --header "Authorization: token ${CI_TOKEN}" \ + --header "Content-Type: application/json" \ + --data "{ + \"head\": \"${BRANCH}\", + \"base\": \"main\", + \"title\": \"chore: dependency updates $(date +%Y-%m-%d)\", + \"body\": $(echo "$DESCRIPTION" | python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()))'), + \"assignees\": [${CI_ASSIGNEE_ID}] + }" \ + "${CI_SERVER_URL}/api/v1/repos/${REPO}/pulls") + +HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS:.*//g') +HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') + +echo "API response status: $HTTP_STATUS" +echo "API response body: $HTTP_BODY" + +if [ "$HTTP_STATUS" -ne 201 ]; then + echo "Failed to create pull request" + exit 1 +fi + +echo "Pull request created for branch: $BRANCH" \ No newline at end of file From 637766a9463f1878101358b0fd032873cd791c1c Mon Sep 17 00:00:00 2001 From: Andrew Kettel Date: Thu, 26 Mar 2026 13:08:02 -0700 Subject: [PATCH 2/2] Updating runners to checkout --- .gitea/workflows/ci.yml | 105 +++++++++++++++---------- .gitea/workflows/dependency_update.yml | 22 +++--- 2 files changed, 76 insertions(+), 51 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 7192a2b..6619b31 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -6,64 +6,89 @@ on: pull_request: branches: [main] schedule: - - cron: "0 9 * * 1" # weekly Monday 9am + - cron: "0 9 * * 1" jobs: - install: - runs-on: ubuntu-latest - container: python:3.13-slim - steps: - - uses: actions/checkout@v3 - - - name: Install system dependencies - run: apt-get update -qq && apt-get install -y -qq libcap-dev - - - name: Install Poetry - run: pip install poetry==2.1.1 - - - name: Install dependencies - run: poetry install --without pi --no-interaction - - - name: Cache venv - uses: actions/cache@v3 - with: - path: .venv - key: venv-${{ hashFiles('pyproject.toml') }} - black: runs-on: ubuntu-latest container: python:3.13-slim - needs: install steps: - - uses: actions/checkout@v3 - - run: pip install poetry==2.1.1 - - run: poetry run black --check src/ tests/ + - name: Checkout + run: | + apt-get update -qq && apt-get install -y -qq git + git clone ${{ github.server_url }}/${{ github.repository }} . + git checkout ${{ github.sha }} + + - name: Install system dependencies + run: apt-get install -y -qq libcap-dev + + - name: Install Poetry and dependencies + run: | + pip install poetry==2.1.1 + poetry install --without pi --no-interaction + + - name: Run black + run: poetry run black --check src/ tests/ ruff: runs-on: ubuntu-latest container: python:3.13-slim - needs: install steps: - - uses: actions/checkout@v3 - - run: pip install poetry==2.1.1 - - run: poetry run ruff check src/ tests/ + - name: Checkout + run: | + apt-get update -qq && apt-get install -y -qq git + git clone ${{ github.server_url }}/${{ github.repository }} . + git checkout ${{ github.sha }} + + - name: Install system dependencies + run: apt-get install -y -qq libcap-dev + + - name: Install Poetry and dependencies + run: | + pip install poetry==2.1.1 + poetry install --without pi --no-interaction + + - name: Run ruff + run: poetry run ruff check src/ tests/ mypy: runs-on: ubuntu-latest container: python:3.13-slim - needs: install steps: - - uses: actions/checkout@v3 - - run: pip install poetry==2.1.1 - - run: poetry run mypy src/ + - name: Checkout + run: | + apt-get update -qq && apt-get install -y -qq git + git clone ${{ github.server_url }}/${{ github.repository }} . + git checkout ${{ github.sha }} + + - name: Install system dependencies + run: apt-get install -y -qq libcap-dev + + - name: Install Poetry and dependencies + run: | + pip install poetry==2.1.1 + poetry install --without pi --no-interaction + + - name: Run mypy + run: poetry run mypy src/ pytest: runs-on: ubuntu-latest container: python:3.13-slim - needs: install steps: - - uses: actions/checkout@v3 - - run: apt-get update -qq && apt-get install -y -qq libcap-dev - - run: pip install poetry==2.1.1 - - run: poetry install --without pi --no-interaction - - run: poetry run pytest + - name: Checkout + run: | + apt-get update -qq && apt-get install -y -qq git + git clone ${{ github.server_url }}/${{ github.repository }} . + git checkout ${{ github.sha }} + + - name: Install system dependencies + run: apt-get install -y -qq libcap-dev + + - name: Install Poetry and dependencies + run: | + pip install poetry==2.1.1 + poetry install --without pi --no-interaction + + - name: Run pytest + run: poetry run pytest diff --git a/.gitea/workflows/dependency_update.yml b/.gitea/workflows/dependency_update.yml index c18b21c..7e69050 100644 --- a/.gitea/workflows/dependency_update.yml +++ b/.gitea/workflows/dependency_update.yml @@ -10,21 +10,21 @@ jobs: dependency-update: runs-on: ubuntu-latest container: python:3.13-slim - # skip if this is already a dependency update branch if: "!startsWith(github.ref, 'refs/heads/dependency-updates-')" steps: - - uses: actions/checkout@v3 - with: - token: ${{ secrets.CI_TOKEN }} + - name: Checkout + run: | + apt-get update -qq && apt-get install -y -qq git curl + git clone ${{ github.server_url }}/${{ github.repository }} . + git checkout ${{ github.sha }} - name: Install system dependencies - run: apt-get update -qq && apt-get install -y -qq libcap-dev git curl + run: apt-get install -y -qq libcap-dev - - name: Install Poetry - run: pip install poetry==2.1.1 - - - name: Install dependencies - run: poetry install --without pi --no-interaction + - name: Install Poetry and dependencies + run: | + pip install poetry==2.1.1 + poetry install --without pi --no-interaction - name: Run dependency update check id: update @@ -40,7 +40,7 @@ jobs: CI_TOKEN: ${{ secrets.CI_TOKEN }} CI_SERVER_URL: ${{ secrets.CI_SERVER_URL }} REPO: ${{ github.repository }} - ASSIGNEE_ID: ${{ secrets.CI_ASSIGNEE_ID }} + CI_ASSIGNEE_ID: ${{ secrets.CI_ASSIGNEE_ID }} run: | chmod +x scripts/create_pr_gitea.sh bash scripts/create_pr_gitea.sh