Skip to content

ci: fix conditional target for Fluxer notifications in deploy_dev wor… #100

ci: fix conditional target for Fluxer notifications in deploy_dev wor…

ci: fix conditional target for Fluxer notifications in deploy_dev wor… #100

Workflow file for this run

name: Deployment on Development
on:
push:
branches: [ "develop" ]
workflow_dispatch:
jobs:
# 1. Job: Statische Analyse (Lint, Stan, CodeSniffer)
# Diese laufen zusammen, da sie keine Datenbank benötigen.
static-analysis:
name: PHP Quality Checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6.0.2
- name: Setup PHP and Composer
uses: ./.github/actions/setup-php-composer
- name: Run PHP Linter
run: composer run-script phplint
- name: Run PHP Stan
run: composer run-script phpstan
- name: Run PHP Codesniffer
run: composer run-script phpcs
# 2. Job: Tests (Unit & Functional)
# Dieser Job benötigt die MariaDB Service-Container
tests:
name: PHP Tests
needs: static-analysis
runs-on: ubuntu-latest
services:
database-testing:
image: mariadb:latest
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: db
MYSQL_USER: dev
MYSQL_PASSWORD: dev
ports:
- 3306:3306
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
env:
DB_DATABASE: db
DB_USERNAME: dev
DB_PASSWORD: dev
DB_HOST: 127.0.0.1
DB_PORT: 3306
APP_ENV: action
steps:
- uses: actions/checkout@v6.0.2
- name: Setup PHP and Composer
uses: ./.github/actions/setup-php-composer
- name: Run Tests
run: ./vendor/bin/pest --configuration=phpunit.xml --compact
env:
APP_ENV: action
DB_HOST: 127.0.0.1
# 3. Deployment
deploy:
name: Deployment on Development
needs: tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6.0.2
- name: Setup Environment (No Dev)
uses: ./.github/actions/setup-php-composer
with:
install-flags: '--prefer-dist --no-progress --no-dev'
- name: Build OpenAPI
run: composer run-script openapi
- name: Deploy via rsync
uses: burnett01/rsync-deployments@8.0.3
with:
switches: -avz --no-o --no-g --no-perms --no-t --omit-dir-times --delete --exclude-from='.rsync-exclude'
remote_path: ${{ secrets.DEPLOY_PATH_API_DEV }}
remote_host: ${{ secrets.DEPLOY_HOST }}
remote_port: ${{ secrets.DEPLOY_PORT }}
remote_user: ${{ secrets.DEPLOY_USER }}
remote_key: ${{ secrets.DEPLOY_KEY }}
remote_key_pass: ${{ secrets.DEPLOY_KEY_PASS }}
- name: Clear Cache
uses: appleboy/ssh-action@v1.2.2
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
passphrase: ${{ secrets.DEPLOY_KEY_PASS }}
script: rm -rf ${{ secrets.DEPLOY_PATH_API_DEV }}/data/cache/*
final-notification:
name: Final Notification
needs: [ static-analysis, tests, deploy ]
if: always() # Dieser Job läuft IMMER, egal ob die vorherigen fehlschlagen
runs-on: ubuntu-latest
strategy:
matrix:
# HIER definieren wir die Matrix mit einfachen Schlüsseln
target: [ discord, fluxer ]
steps:
- name: Check Workflow Status
id: status_check
run: |
# Prüfe das Ergebnis aller vorherigen Jobs
# needs ist ein JSON-Kontext, den wir parsen können
if [[ "${{ needs.static-analysis.result }}" == "failure" || \
"${{ needs.tests.result }}" == "failure" || \
"${{ needs.deploy.result }}" == "failure" ]]; then
echo "status=failure" >> $GITHUB_OUTPUT
echo "message=❌ Ein Schritt im Workflow ist fehlgeschlagen." >> $GITHUB_OUTPUT
else
echo "status=success" >> $GITHUB_OUTPUT
echo "message=🚀 Deployment auf Development erfolgreich!" >> $GITHUB_OUTPUT
fi
# Schritt für Discord-Benachrichtigungen
- name: Send Discord Notification
if: matrix.target == 'discord'
uses: rjstone/discord-webhook-notify@v1.0.4
with:
severity: ${{ steps.status_check.outputs.status == 'success' && 'info' || 'error' }}
details: |
${{ steps.status_check.outputs.message }}
[Logs ansehen](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
webhookUrl: ${{ secrets.WEBHOOK_DISCORD_URL }}
# Schritt für Fluxer.app-Benachrichtigungen (mit curl, da Fluxer ein anderes Format erwartet!)
- name: Send Discord Notification
if: matrix.target == 'fluxer'
uses: rjstone/discord-webhook-notify@v1.0.4
with:
severity: ${{ steps.status_check.outputs.status == 'success' && 'info' || 'error' }}
details: |
${{ steps.status_check.outputs.message }}
[Logs ansehen](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
webhookUrl: ${{ secrets.WEBHOOK_FLUXER_URL }}