Skip to content

Merge branch 'develop' of github.com:ScaDS/cicd-ga-scadsai into develop #10

Merge branch 'develop' of github.com:ScaDS/cicd-ga-scadsai into develop

Merge branch 'develop' of github.com:ScaDS/cicd-ga-scadsai into develop #10

Workflow file for this run

name: cicd-pipeline
# CICD Pipeline with GitHub Actions
# See Docs: https://docs.github.com/en/actions
# See available actions: https://github.com/marketplace?type=actions
# Define when to run this pipeline
on:
push:
branches: [develop, main]
pull_request:
branches: [develop, main]
# Avoid duplicate runs per reference, e.g., for multiple successive pushes to a branch
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Define reusable ENV vars
env:
CONDA_ENV_FILE: devops-conda-env.yml
CONDA_ENV_NAME: devops-env
# Define least privilege security for this workflow
permissions:
contents: read
# Define CICD jobs
jobs:
linting:
name: linting
runs-on: ubuntu-latest
steps:
# Checkout the repository
- uses: actions/checkout@v5
# Small footprint conda with built-in caching
- uses: mamba-org/setup-micromamba@v2
with:
environment-file: ${{ env.CONDA_ENV_FILE }}
environment-name: ${{ env.CONDA_ENV_NAME }}
cache-environment: true
cache-downloads: true
- name: Run ruff for linting
run: micromamba run -n $CONDA_ENV_NAME ruff check
tests:
name: tests
runs-on: ubuntu-latest
needs: linting
steps:
# Checkout the repository
- uses: actions/checkout@v5
# Small footprint conda with built-in caching
- uses: mamba-org/setup-micromamba@v2
with:
environment-file: ${{ env.CONDA_ENV_FILE }}
environment-name: ${{ env.CONDA_ENV_NAME }}
cache-environment: true
cache-downloads: true
- name: Run pytest with coverage report
run: micromamba run -n $CONDA_ENV_NAME pytest --cov=app --cov-report=xml
- name: Validate test coverage
run: micromamba run -n $CONDA_ENV_NAME python scripts/check_test_coverage.py
deploy:
name: deploy
runs-on: ubuntu-latest
needs: tests
# Run only for push on main branch
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
REGISTRY: docker.scadsai.uni-leipzig.de
PROJECT: library
IMAGE: docker.scadsai.uni-leipzig.de/library/analysis-app
steps:
# Checkout the repository
- uses: actions/checkout@v5
# Set up Docker buildx for multi-arch builds inside CI
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
# Read current application version from pyproject.toml
- id: ver
shell: bash
run: |
set -euo pipefail
VERSION="$(grep -E '^[[:space:]]*version[[:space:]]*=[[:space:]]*\"[^\"]+\"' pyproject.toml | head -1 | sed -E 's/.*version[[:space:]]*=[[:space:]]*\"([^\"]+)\".*/\1/')"
if [[ -z "${VERSION}" ]]; then
echo "Version not found in pyproject.toml"; exit 1
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "Found version: ${VERSION}"
# Login to Harbor Docker registry
- name: Log in to Harbor
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_PASSWORD }}
# Build and push multi-arch application Docker image
- name: Build and Push Docker Image
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t $IMAGE:${{ steps.ver.outputs.version }} \
-t $IMAGE:latest \
--push \
.
echo "Pushed:"
echo " $IMAGE:${{ steps.ver.outputs.version }}"
echo " $IMAGE:latest"