mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-11-30 22:45:46 +01:00
181 lines
5.3 KiB
YAML
181 lines
5.3 KiB
YAML
name: CI/CD Pipeline
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches: [ "development", "main", "staging" ]
|
|
tags: [ "v*.*.*" ]
|
|
|
|
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 }}
|
|
is_main_branch: ${{ steps.branch_check.outputs.is_main }}
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Check if main branch
|
|
id: branch_check
|
|
run: |
|
|
if [[ "${{ github.ref }}" == "refs/heads/main" || "${{ github.ref }}" == "refs/heads/master" ]]; then
|
|
echo "is_main=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "is_main=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- 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)
|
|
echo "Latest tag found: $latest_tag"
|
|
|
|
if [[ -z "$latest_tag" ]]; then
|
|
major=0
|
|
minor=0
|
|
patch=0
|
|
echo "No existing tags found, starting from v0.0.0"
|
|
else
|
|
version="${latest_tag#v}"
|
|
IFS='.' read -r major minor patch <<< "$version"
|
|
echo "Parsed version: major=$major, minor=$minor, patch=$patch"
|
|
fi
|
|
|
|
if [[ "${{ github.ref }}" == "refs/heads/main" || "${{ github.ref }}" == "refs/heads/master" ]]; then
|
|
major=$((major + 1))
|
|
minor=0
|
|
patch=0
|
|
echo "Main branch - major version bump"
|
|
elif [[ "${{ github.ref }}" == "refs/heads/development" ]]; then
|
|
minor=$((minor + 1))
|
|
patch=0
|
|
echo "Development branch - minor version bump"
|
|
else
|
|
patch=$((patch + 1))
|
|
echo "Other branch - patch version bump"
|
|
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'
|
|
|
|
- name: Install backend dependencies
|
|
working-directory: ./backend
|
|
run: npm install
|
|
|
|
- name: Run TypeScript check
|
|
working-directory: ./backend
|
|
run: npx tsc --noEmit
|
|
|
|
- name: Run backend tests
|
|
working-directory: ./backend
|
|
run: |
|
|
if [ -f "node_modules/.bin/jest" ]; then
|
|
npm test
|
|
else
|
|
echo "⚠️ Jest not installed. Skipping tests."
|
|
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: write
|
|
packages: write
|
|
id-token: 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=raw,value=${{ needs.set-tag.outputs.tag_name }}
|
|
type=raw,value=latest,enable=${{ fromJSON(needs.set-tag.outputs.is_main_branch) }}
|
|
|
|
- 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 }}"
|
|
echo "- Is main branch: ${{ needs.set-tag.outputs.is_main_branch }}"
|