Files
AareDAQ/.gitea/workflows/action.yaml
T
appleb_m bdd62ebc48
Build and Publish / test (push) Failing after 1m15s
Build and Publish / build (push) Has been skipped
Build and Publish / Build and Deploy Docs (push) Has been skipped
gitea workflows: updated action.yaml to remove PYTEST_DISBALE_PLUGIN_AUTOLOAD
2026-04-28 13:58:14 +02:00

224 lines
6.8 KiB
YAML

name: Build and Publish
on:
push:
tags:
- '*'
branches:
- master
- deploy
- 'feature/**'
- gitea-pages
pull_request:
branches:
- master
- deploy
pull_request_target:
types: [closed]
env:
DEPLOY_BRANCH: gitea-pages
PREVIEWS_DIR: previews
PYTHONPATH: src
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set Up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-test-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-test-
- name: Create virtual environment
run: |
python -m venv venv
- name: Install dependencies
env:
PIP_INDEX_URL: https://${{ secrets.GITEA_USER }}:${{ secrets.GITEA_TOKEN }}@gitea.psi.ch/api/packages/mx/pypi/simple/
PIP_EXTRA_INDEX_URL: https://pypi.org/simple
run: |
source venv/bin/activate
python -m pip install --upgrade pip
pip install pytest pytest-cov pytest-mock pytest-qt pytest-asyncio
pip install -e .
- name: Install system dependencies for PySide6
run: |
sudo apt-get update
sudo apt-get install -y \
libgl1 \
libegl1 \
libxkbcommon-x11-0 \
libdbus-1-3 \
libxcb-cursor0 \
libx11-xcb1
- name: Debug Python env
run: |
source venv/bin/activate
which python
which pytest
python -m pip list | grep pytest
- name: Run tests with pytest
env:
QT_QPA_PLATFORM: offscreen
BEAMLINE: SIMULATED
run: |
source venv/bin/activate
python -m pytest --cov=aare --cov-report=xml tests/unit
build:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
- name: Set Up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Set Up Python Environment
run: |
python3 -m venv venv # Create a virtual environment
source venv/bin/activate
pip install twine build
- name: Build the package
run: |
source venv/bin/activate
python -m build
- name: Upload Package to Gitea PyPI
if: startsWith(github.ref, 'refs/tags/')
env:
TWINE_USERNAME: "__token__" # Username for Twine when using token-based auth
TWINE_PASSWORD: ${{ secrets.PIP_REPOSITORY_API_TOKEN }} # Use the secret for authentication
run: |
source venv/bin/activate
twine upload --repository-url https://gitea.psi.ch/api/packages/mx/pypi \
dist/*
docs:
name: Build and Deploy Docs
runs-on: ubuntu-latest
needs: [build, test]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # needed for pushing branches/tags
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Build Sphinx HTML
working-directory: docs
run: |
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
pip install -e .. --no-deps
sphinx-apidoc -o modules/ ../src/aare --separate --module-first --force --remove-old
sphinx-build -b html . _build/html
- name: Deploy to gitea-pages branch (Gitea)
env:
GIT_USER: "Martin Appleby (Gitea)"
GIT_EMAIL: "martin.appleby@psi.ch"
DEPLOY_TOKEN: ${{ secrets.DOCS_DEPLOY_TOKEN }}
run: |
set -e
git config --global user.name "$GIT_USER"
git config --global user.email "$GIT_EMAIL"
# Deploy strategy: create/update branch gitea-pages and replace its contents
# with the generated daq/docs/_build/html. This keeps only the documentation
# on the gitea-pages branch.
# Confirm build output exists (relative to repository root)
BUILD_DIR="docs/_build/html"
echo "Checking build output at: $BUILD_DIR"
if [ ! -d "$BUILD_DIR" ] || [ -z "$(ls -A "$BUILD_DIR")" ]; then
echo "ERROR: $BUILD_DIR does not exist or is empty"
echo "Listing docs/:"
ls -la docs || true
echo "Listing docs/_build:"
ls -la docs/_build || true
exit 1
fi
# Work in a temporary clone to avoid touching the runner workspace
TMPDIR=$(mktemp -d)
REPO_URL="https://$DEPLOY_TOKEN@gitea.psi.ch/${{ github.repository }}"
git clone "$REPO_URL" "$TMPDIR"
cd "$TMPDIR"
# Create or switch to orphan branch gitea-pages
if git rev-parse --verify --quiet gitea-pages >/dev/null; then
git checkout gitea-pages
# Make sure working tree matches branch (hard reset)
git fetch --prune origin gitea-pages || true
git reset --hard origin/gitea-pages || git reset --hard
else
git checkout --orphan gitea-pages
fi
# Remove all files tracked in the branch (leave .git)
git rm -rf . || true
# Also remove untracked files to ensure clean branch state
git clean -fdx || true
# Copy built HTML into the clone root
echo "Copying built HTML into branch root..."
(cd "${GITHUB_WORKSPACE}/${BUILD_DIR}" && tar -cf - .) | tar -xf - -C "$TMPDIR"
# Ensure index.html exists in destination as sanity check
if [ ! -f "$TMPDIR/index.html" ] && [ ! -f "$TMPDIR/index.htm" ]; then
# If site root index is not present, try to check subfolder
echo "Warning: no index.html found at branch root after copy. Listing files:"
ls -la "$TMPDIR" || true
fi
git add --all
if git diff --quiet --cached; then
echo "No changes to deploy"
exit 0
fi
COMMIT_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
git commit -m "docs: (${COMMIT_DATE}) | auto-update documentation from ${GITHUB_SHA}"
git push --force-with-lease origin gitea-pages