LiberTEM/LiberTEM

View on GitHub
.github/workflows/ci.yml

Summary

Maintainability
Test Coverage
name: CI

on:
  push:
    branches:
      - master
      - 'v[0-9]*'
    tags:
      - 'v[0-9]*'
  pull_request:

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  tests:
    strategy:
      matrix:
        python_version: ["3.9", "3.10", "3.11", "3.12"]
        os: [ubuntu-latest, windows-latest, macos-14]
        exclude:
          - os: macos-14
            python_version: "3.9"
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - name: Choose Python version ${{ matrix.python_version }}
        uses: actions/setup-python@v5
        with:
          python-version: '${{ matrix.python_version }}'
          cache: 'pip'
      - run: |
           [[ "${{ matrix.os }}" = "ubuntu-latest" ]] && sudo apt-get install -y libcap-dev || true
        shell: bash
      - name: install tox (with uv)
        run: python3 -m pip install tox tox-uv
      - name: run tox
        run: tox -e 'py${{ matrix.python_version }}'
      - name: submit code coverage
        uses: codecov/codecov-action@v4
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

  node:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup Node.js environment
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'npm'
          cache-dependency-path: client/package-lock.json
      - run: (cd client && npm ci)
      - run: (cd client && npm run build)
      - run: (cd client && CI=1 npm run coverage)
      - run: (cd client && npm run lint)
      - name: submit code coverage
        uses: codecov/codecov-action@v4
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

  additional:
    strategy:
      matrix:
        envs: ["numba_coverage", "docs-check", "web_api"]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: 'Choose Python version 3.11'
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'
          cache: 'pip'
      - run: sudo apt-get install -y pandoc libcap-dev graphviz
      - name: install tox
        run: python3 -m pip install tox tox-uv
      - name: 'run tox for environment ${{ matrix.envs }}'
        run: tox -e '${{ matrix.envs }}'
      - name: submit code coverage
        uses: codecov/codecov-action@v4
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

  build-docker-image:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: 'Choose Python version 3.11'
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      - name: install dependencies
        run: python3 -m pip install pip-tools
      - name: generate requirements.txt
        run: cd packaging/docker && ./update_reqs.sh
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Pull cache base image
        run: |
          docker pull python:3.11-slim  # the base image, to make sure we get the latest one
          docker pull ghcr.io/libertem/libertem-dev:latest
      - name: Build and push (libertem/libertem-triage)
        uses: docker/build-push-action@v5
        with:
          file: packaging/docker/Dockerfile
          context: .
          push: ${{ startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/v') || github.ref == 'refs/heads/master' }}
          tags: ghcr.io/libertem/libertem-triage:pre-${{ github.sha }}
          cache-from: type=registry,ref=ghcr.io/libertem/libertem-dev:latest
          cache-to: type=inline
      - name: Build and push (libertem/libertem-dev)
        uses: docker/build-push-action@v5
        with:
          file: packaging/docker/Dockerfile
          context: .
          push: ${{ startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/v') || github.ref == 'refs/heads/master' }}
          tags: ghcr.io/libertem/libertem-dev:pre-${{ github.sha }}
          cache-from: type=registry,ref=ghcr.io/libertem/libertem-dev:latest
          cache-to: type=inline
          build-args: |
            dev=1

  build-docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: 'Choose Python version 3.11'
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'
          cache: 'pip'
      - run: sudo apt-get install -y pandoc
      - name: install tox
        run: python3 -m pip install tox tox-uv
      - name: 'run tox for docs-build-ci'
        run: tox -e 'docs-build-ci'
      - uses: actions/upload-pages-artifact@v3.0.1
        with:
          path: 'docs/build/html/'

  deploy-docs:
    runs-on: ubuntu-latest
    needs: [build-docs, additional, tests, node, build-docker-image]
    if: github.ref  == 'refs/heads/master'
    permissions:
      pages: write
      id-token: write
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4
      - run: |
          curl -XPOST -u "sk1p:${{secrets.PAGES_TRIGGER_GH_TOKEN}}" -H "Accept: application/vnd.github.everest-preview+json" -H 'Content-Type: application/json' https://api.github.com/repos/LiberTEM/libertem.github.io/dispatches --data '{"event_type":"build_pages","client_payload":{"from":"LiberTEM"}}'

  release:
    runs-on: ubuntu-latest
    needs: [build-docs, additional, tests, node, build-docker-image]
    # master branch, stable branches or release tags:
    if: startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/v') || github.ref == 'refs/heads/master'
    env:
      LT_RELEASE_UPLOAD_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      LT_RELEASE_UPLOAD_PYPI_PASSWORD: ${{ secrets.LT_RELEASE_UPLOAD_PYPI_PASSWORD }}
      LT_RELEASE_UPLOAD_ZENODO_TOKEN: ${{ secrets.LT_RELEASE_UPLOAD_ZENODO_TOKEN }}
      LT_RELEASE_UPLOAD_ZENODO_PARENT: ${{ secrets.LT_RELEASE_UPLOAD_ZENODO_PARENT }}
    steps:
      - run: sudo apt-get install -y fuse
      - uses: actions/checkout@v4
      - name: Choose Python version 3.10
        uses: actions/setup-python@v5
        with:
          python-version: "3.10"
          cache: 'pip'
      - name: install release script deps
        run: pip install -r scripts/requirements.txt
      - name: release status
        run: ./scripts/release status
      - name: run release script
        run: ./scripts/release --verbose upload --no-dry-run --pypi-user __token__ --build-appimage
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Pull docker images from build stage
        run: |
          docker pull ghcr.io/libertem/libertem-triage:pre-${{ github.sha }}
          docker pull ghcr.io/libertem/libertem-dev:pre-${{ github.sha }}
      - name: Push images to GHCR
        run: |
          ./scripts/release docker-retag ghcr.io/libertem/libertem-triage:pre-${{ github.sha }} ghcr.io/libertem/libertem
          docker buildx imagetools create --tag ghcr.io/libertem/libertem-dev:latest ghcr.io/libertem/libertem-dev:pre-${{ github.sha }}