Skip to content

Implement semantic docker image tagging #17

Implement semantic docker image tagging

Implement semantic docker image tagging #17

Workflow file for this run

name: CI

Check failure on line 1 in .github/workflows/ci.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/ci.yml

Invalid workflow file

(Line: 84, Col: 19): Unrecognized function: 'startWith'. Located at position 36 within expression: github.ref == 'refs/heads/main' || startWith(github.ref, 'refs/tags/v')
on:
push:
branches: ["main"]
tags:
- "v*"
pull_request:
branches: ["main"]
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' || startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Semantic Docker image tagging (relesae-grade)
- name: Dcoker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/eventrelay
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
# Build and push docker image (for main only)
- name: Build and push Docker image
uses: docker/build-push-action@v5
if: github.ref == 'refs/heads/main' || startWith(github.ref, 'refs/tags/v')
with:
context: backend
file: backend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}