mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-11-30 22:45:46 +01:00
174 lines
5.0 KiB
YAML
174 lines
5.0 KiB
YAML
name: CI/CD Pipeline
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, master, development ]
|
|
pull_request:
|
|
branches: [ main, master, development ]
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
set-tag:
|
|
name: Set Tag Name
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
tag_name: ${{ steps.set_tag.outputs.tag_name }}
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # Fetch all history for tags
|
|
|
|
- name: Determine next semantic version tag
|
|
id: set_tag
|
|
run: |
|
|
git fetch --tags
|
|
|
|
# Find latest tag matching vX.Y.Z
|
|
latest_tag=$(git tag --list 'v*.*.*' --sort=-v:refname | head -n 1)
|
|
if [[ -z "$latest_tag" ]]; then
|
|
major=0
|
|
minor=0
|
|
patch=0
|
|
else
|
|
version="${latest_tag#v}"
|
|
IFS='.' read -r major minor patch <<< "$version"
|
|
fi
|
|
|
|
if [[ "${GITHUB_REF}" == "refs/heads/main" || "${GITHUB_REF}" == "refs/heads/master" ]]; then
|
|
major=$((major + 1))
|
|
minor=0
|
|
patch=0
|
|
elif [[ "${GITHUB_REF}" == "refs/heads/development" ]]; then
|
|
minor=$((minor + 1))
|
|
patch=0
|
|
else
|
|
patch=$((patch + 1))
|
|
fi
|
|
|
|
new_tag="v${major}.${minor}.${patch}"
|
|
echo "tag_name=${new_tag}" >> $GITHUB_OUTPUT
|
|
echo "Next version tag: ${new_tag}"
|
|
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
needs: set-tag
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
cache: 'npm'
|
|
cache-dependency-path: backend/package-lock.json
|
|
|
|
- name: Install backend dependencies
|
|
working-directory: ./backend
|
|
run: |
|
|
# Try npm ci first, if it fails use npm install
|
|
npm ci || (echo "package-lock.json out of sync, using npm install..." && npm install)
|
|
|
|
- name: Run TypeScript check
|
|
working-directory: ./backend
|
|
run: npx tsc --noEmit
|
|
|
|
- name: Check if tests exist and run them
|
|
working-directory: ./backend
|
|
run: |
|
|
# Check if jest is available and test script exists
|
|
if npx --no-install jest --version > /dev/null 2>&1; then
|
|
echo "Running tests with Jest..."
|
|
npm test
|
|
elif [ -f "package.json" ] && grep -q '"test"' package.json; then
|
|
echo "Running test script from package.json..."
|
|
npm test
|
|
else
|
|
echo "No tests configured. Skipping test execution."
|
|
fi
|
|
|
|
- name: Setup Python
|
|
uses: actions/setup-python@v4
|
|
with:
|
|
python-version: '3.11'
|
|
|
|
- name: Install Python dependencies
|
|
run: pip install ortools
|
|
|
|
- name: Test Python integration
|
|
run: |
|
|
python -c "from ortools.sat.python import cp_model; print('OR-Tools available')"
|
|
|
|
- name: Display next version
|
|
run: |
|
|
echo "Next version will be: ${{ needs.set-tag.outputs.tag_name }}"
|
|
|
|
build-and-push:
|
|
needs: [set-tag, test]
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push'
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=semver,pattern={{version}}
|
|
type=sha
|
|
# Add the dynamically generated semantic version
|
|
${{ needs.set-tag.outputs.tag_name }}
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Create Git Tag
|
|
if: success()
|
|
run: |
|
|
git config --local user.email "action@github.com"
|
|
git config --local user.name "GitHub Action"
|
|
git tag ${{ needs.set-tag.outputs.tag_name }}
|
|
git push origin ${{ needs.set-tag.outputs.tag_name }}
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Display pushed images
|
|
run: |
|
|
echo "✅ Docker images pushed successfully!"
|
|
echo "📦 Image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
|
|
echo "🏷️ Tags: ${{ steps.meta.outputs.tags }}"
|
|
echo "🚀 New version: ${{ needs.set-tag.outputs.tag_name }}"
|