From e962f48eb96097ec6d688c8fb40f1662d9e3db6b Mon Sep 17 00:00:00 2001 From: appleb_m Date: Tue, 10 Mar 2026 13:44:03 +0100 Subject: [PATCH] Revert changes to workflows before large merge from x10sa branch --- .gitea/workflows/action.yaml | 172 ++++++++++++++++++++++++++++++++++- 1 file changed, 169 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/action.yaml b/.gitea/workflows/action.yaml index a06a1fc3..79686358 100644 --- a/.gitea/workflows/action.yaml +++ b/.gitea/workflows/action.yaml @@ -1,17 +1,24 @@ 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 + jobs: build: runs-on: ubuntu-latest @@ -28,8 +35,24 @@ jobs: - name: Build the common wheel run: | - source venv/bin/activate - python -m build + source venv/bin/activate + cd common/ + python -m build + mv dist/* ../dist + + - name: Build the GUI wheel + run: | + source venv/bin/activate + cd gui/ + python -m build + mv dist/* ../dist + + - name: Build the DAQ wheel + run: | + source venv/bin/activate + cd daq/ + python -m build + mv dist/* ../dist - name: Upload Package to Gitea PyPI if: github.ref == 'refs/heads/master' && contains(github.event.head_commit.message, 'build and publish') @@ -40,3 +63,146 @@ jobs: 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 + 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: daq/docs + run: | + # ensure on master + git fetch origin master:master || true + git checkout master || true + + # create venv one level up and activate it + python3 -m venv ../venv + source ../venv/bin/activate + + # ensure pip and Sphinx are installed in this venv + pip install --upgrade pip + pip install "Sphinx==8.2.3" + pip install myst-parser + pip install sphinx_immaterial + pip install linkify-it-py + + if [ -f requirements.txt ]; then + pip install -r requirements.txt + elif [ -f ../docs/requirements.txt ]; then + pip install -r ../docs/requirements.txt + else + # fallback to known packages if requirements file is not present + pip install "Sphinx==8.2.3" myst-parser sphinx_immaterial linkify-it-py + fi + + + # install project editable without deps (avoid private packages) + pip install -e ../ --no-deps + + # prefer the sphinx-apidoc CLI if available; otherwise try module fallback + if command -v sphinx-apidoc > /dev/null 2>&1; then + sphinx-apidoc -o modules/ ../src --separate --module-first --force --remove-old + else + # module fallback: some Sphinx installs expose the module at sphinx.ext.apidoc + python -m sphinx.ext.apidoc -o modules/ ../src --separate --module-first --force --remove-old + fi + + + # Build HTML (source is '.' because working-directory is docs) + # Run sphinx-build and capture exit code and full output to help debugging if it fails. + sphinx-build -b html . _build/html || { + echo "=== Sphinx build failed with exit $?: showing build output and tree ===" + echo "Contents of docs/ after build attempt:" + ls -la + echo "Contents of daq/docs/_build (if any):" + ls -la _build || true + # If sphinx produced a build log file, print it + if [ -f sphinx-build.log ]; then + echo "---- sphinx-build.log ----" + cat sphinx-build.log + fi + # Exit with non-zero to fail the job (avoid deploying empty site) + exit 1 + } + + # Sanity check: ensure HTML output exists before continuing to deploy + if [ ! -d _build/html ] || [ -z "$(ls -A _build/html)" ]; then + echo "ERROR: daq/docs/_build/html does not exist or is empty after successful sphinx-build." + ls -la _build || true + exit 1 + fi + + - 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="daq/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 daq/docs/_build:" + ls -la daq/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