From 6416b0f74936960a51b918117ba9d9e9c3ab98d0 Mon Sep 17 00:00:00 2001 From: Moritz Utcke Date: Mon, 28 Apr 2025 12:45:21 -0300 Subject: [PATCH] Workflows --- .../auto-merge-staging-into-main.yml | 52 +++++++++++++++++++ .github/workflows/prevent-wrong-pr.yml | 26 ++++++++++ 2 files changed, 78 insertions(+) create mode 100644 .github/workflows/auto-merge-staging-into-main.yml create mode 100644 .github/workflows/prevent-wrong-pr.yml diff --git a/.github/workflows/auto-merge-staging-into-main.yml b/.github/workflows/auto-merge-staging-into-main.yml new file mode 100644 index 00000000..42255d3c --- /dev/null +++ b/.github/workflows/auto-merge-staging-into-main.yml @@ -0,0 +1,52 @@ +name: Auto Merge Staging into Main + +on: + schedule: + - cron: '0 2 * * *' # 2:00 UTC = 4:00 CET + workflow_dispatch: + +jobs: + merge: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set Git user + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Fetch all branches + run: | + git fetch origin main + git fetch origin staging + + - name: Check if main has commits not in staging + id: check + run: | + if ! git merge-base --is-ancestor origin/staging origin/main; then + echo "Main hat neuere Commits als Staging. Merge wird abgebrochen." + exit 1 + fi + + - name: Merge staging into main + if: steps.check.outcome == 'success' + run: | + git checkout main + git merge origin/staging --no-ff --no-edit + git push origin main + + notify_failure: + needs: merge + if: failure() + runs-on: ubuntu-latest + steps: + - name: Send Discord notification on failure + run: | + curl -H "Content-Type: application/json" \ + -X POST \ + -d "{\"content\": \"🚨 Auto-Merge fehlgeschlagen! Bitte manuell prüfen: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}" \ + ${{ secrets.DISCORD_WEBHOOK_URL }} \ No newline at end of file diff --git a/.github/workflows/prevent-wrong-pr.yml b/.github/workflows/prevent-wrong-pr.yml new file mode 100644 index 00000000..ec59d02c --- /dev/null +++ b/.github/workflows/prevent-wrong-pr.yml @@ -0,0 +1,26 @@ +name: PR Rules Enforcement + +on: + pull_request: + branches: + - main + - staging + +jobs: + check-pr: + runs-on: ubuntu-latest + steps: + - name: Prevent dev merges + run: | + if [[ "${{ github.head_ref }}" == "dev" ]]; then + echo "ERROR: Merging 'dev' into '${{ github.base_ref }}' is forbidden!" + exit 1 + fi + + - name: Allow only staging into main + if: github.base_ref == 'main' + run: | + if [[ "${{ github.head_ref }}" != "staging" ]]; then + echo "ERROR: Only 'staging' branch is allowed to merge into 'main'. Current: '${{ github.head_ref }}'" + exit 1 + fi