Skip to content

Added cache pip to CI workflows #16

Added cache pip to CI workflows

Added cache pip to CI workflows #16

Workflow file for this run

name: CI
on:
push:
branches: ["*"]
pull_request:
branches: ["*"]
jobs:
build-and-test:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# Get code
- name: Checkout repository
uses: actions/checkout@v4
# Set up Python
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
# Cache pip dependencies
- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('backend/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip
# Install dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r backend/requirements.txt
# Lint with Ruff
- name: Lint with Ruff
run: |
ruff check backend/app backend/tests
# Ruff formating check
- name: Ruff format check
run: |
ruff format --check backend/app backend/tests
# Run tests
- name: Run tests
run: |
pytest backend/tests/
# Log in to Github Container Registry
- name: Log in to GHCR
if: github.ref == 'refs/heads/main'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Build and push Docker image (for main only)
- name: Build and push Docker image
if: github.ref == 'refs/heads/main'
run: |
IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/eventrelay
IMAGE_TAG=${{ github.sha }}
docker build \
-f backend/Dockerfile \
-t $IMAGE_NAME:latest \
-t $IMAGE_NAME:$IMAGE_TAG \
backend
docker push $IMAGE_NAME:latest
docker push $IMAGE_NAME:$IMAGE_TAG