From 8f13d6b0466ea853ec80abe200beac4ee571613e Mon Sep 17 00:00:00 2001 From: frocode Date: Tue, 29 Jul 2025 13:42:02 +0200 Subject: [PATCH 1/3] # test commit 13 --- f13.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 f13.txt diff --git a/f13.txt b/f13.txt new file mode 100644 index 0000000..34b3c3e --- /dev/null +++ b/f13.txt @@ -0,0 +1 @@ +# test commit 13 \ No newline at end of file From 828ac754c8cc5eac7728158c2d0ea86e865d2477 Mon Sep 17 00:00:00 2001 From: frocode Date: Thu, 31 Jul 2025 10:25:42 +0200 Subject: [PATCH 2/3] ++ --- f13.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/f13.txt b/f13.txt index 34b3c3e..dcb3ea3 100644 --- a/f13.txt +++ b/f13.txt @@ -1 +1 @@ -# test commit 13 \ No newline at end of file +# test commit 14 \ No newline at end of file From 27c1fb7b92dc47b90327589fb492859acc4ce3c4 Mon Sep 17 00:00:00 2001 From: frocode Date: Fri, 22 Aug 2025 10:24:17 +0200 Subject: [PATCH 3/3] added --- .github/workflows/squash-merge-into-dev.yml | 109 +++++++++++++++++++ .github/workflows/test_to_prod.yaml | 110 ++++++++++++++++++++ f11.txt | 1 - 3 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/squash-merge-into-dev.yml create mode 100644 .github/workflows/test_to_prod.yaml diff --git a/.github/workflows/squash-merge-into-dev.yml b/.github/workflows/squash-merge-into-dev.yml new file mode 100644 index 0000000..f773ee3 --- /dev/null +++ b/.github/workflows/squash-merge-into-dev.yml @@ -0,0 +1,109 @@ +name: squash-merge-into-dev + +on: + workflow_dispatch: + inputs: + pr_number: + description: "Pull Request Number (e.g. 123)" + required: true + +jobs: + squash-merge: + runs-on: ubuntu-latest + + steps: + # Checkout repository + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.PAT }} + + # Configure Git + - name: Configure Git + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + # Fetch PR branch info + - name: Get PR branch name + id: pr_info + run: | + BRANCH_NAME=$(gh pr view ${{ github.event.inputs.pr_number }} --json headRefName -q ".headRefName") + echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV + env: + GH_TOKEN: ${{ secrets.PAT }} + + # Check for duplicate commit in dev + - name: Check if commit message already exists in dev + id: check_commit + run: | + git fetch origin dev + git checkout dev + COMMIT_MSG="from ${{ env.branch_name }}" + if git log --pretty=format:"%s" origin/dev | grep -q "^$COMMIT_MSG$"; then + echo "duplicate=true" >> $GITHUB_OUTPUT + else + echo "duplicate=false" >> $GITHUB_OUTPUT + fi + + # Trigger revert branch workflow if duplicate found + - name: Trigger revert workflow + if: steps.check_commit.outputs.duplicate == 'true' + uses: peter-evans/workflow-dispatch@v2 + with: + token: ${{ secrets.PAT }} + repository: ${{ github.repository }} + workflow: manual-revert-workflow.yml + ref: dev + inputs: + branch_name: ${{ env.branch_name }} + + # Wait for revert workflow to finish + - name: Wait for revert to complete + if: steps.check_commit.outputs.duplicate == 'true' + run: | + echo "Waiting for revert workflow to finish..." + sleep 30 + + # Retry squash merge after revert OR first attempt + - name: Squash merge PR into dev + id: merge + run: | + git fetch origin + git checkout dev + git pull origin dev + + # Fetch PR branch + git fetch origin ${{ env.branch_name }} + + set +e + git merge origin/${{ env.branch_name }} --squash + STATUS=$? + set -e + + if [ $STATUS -ne 0 ]; then + echo "Merge conflict detected!" + echo "conflict=true" >> $GITHUB_OUTPUT + exit 0 + fi + + git commit -m "from ${{ env.branch_name }}" + git push origin dev + echo "conflict=false" >> $GITHUB_OUTPUT + + # Fail workflow if merge conflict detected + - name: Fail on conflict + if: steps.merge.outputs.conflict == 'true' + run: | + echo "❌ Merge conflict detected while merging ${{ env.branch_name }} into dev." + echo "Please create a PR and resolve conflicts manually." + exit 1 + + # Comment on PR after successful merge + - name: Comment on PR + if: steps.merge.outputs.conflict == 'false' + run: | + gh pr comment ${{ github.event.inputs.pr_number }} --body "✅ Successfully squash merged into dev with commit: from ${{ env.branch_name }}" + env: + GH_TOKEN: ${{ secrets.PAT }} diff --git a/.github/workflows/test_to_prod.yaml b/.github/workflows/test_to_prod.yaml new file mode 100644 index 0000000..8987090 --- /dev/null +++ b/.github/workflows/test_to_prod.yaml @@ -0,0 +1,110 @@ +name: push-test-to-prod + +on: + workflow_run: + workflows: ["manual-revert-workflow"] + types: + - completed + workflow_dispatch: + inputs: + force_push: + description: "Force push test to prod (overwrites prod branch)" + required: false + default: "false" + +jobs: + push-to-prod: + runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion == 'success' + + steps: + # Checkout repository + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.PAT }} + + # Configure Git + - name: Configure Git + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + # Validate branches + - name: Validate branches + run: | + git fetch origin + if ! git ls-remote --heads origin test | grep -q test; then + echo "Error: test branch does not exist" + exit 1 + fi + if ! git ls-remote --heads origin prod | grep -q prod; then + echo "Creating prod branch from test" + git checkout test + git push origin test:prod + exit 0 + fi + + # Push test to prod + - name: Push test to prod + id: push + run: | + git checkout prod + git fetch origin test + set +e + git merge origin/test --no-ff --no-edit + STATUS=$? + set -e + if [ $STATUS -ne 0 ]; then + echo "Merge conflict detected" + TIMESTAMP=$(date +%s) + CONFLICT_BRANCH="conflict/test-to-prod-$TIMESTAMP" + git checkout -b "$CONFLICT_BRANCH" + git push origin "$CONFLICT_BRANCH" + gh pr create \ + --base prod \ + --head "$CONFLICT_BRANCH" \ + --title "Merge conflict: test to prod" \ + --body "Automatic PR: Conflicts occurred while merging test into prod. Please resolve manually." + echo "conflict=true" >> $GITHUB_OUTPUT + exit 0 + fi + git push origin prod + echo "conflict=false" >> $GITHUB_OUTPUT + env: + GH_TOKEN: ${{ secrets.PAT }} + + # Force push if requested + - name: Force push test to prod + if: github.event.inputs.force_push == 'true' && steps.push.outputs.conflict == 'false' + run: | + git checkout test + git push origin test:prod --force + echo "Force pushed test to prod" + env: + GH_TOKEN: ${{ secrets.PAT }} + + # Validate prod branch + - name: Validate prod branch + if: steps.push.outputs.conflict == 'false' + run: | + git fetch origin prod + git checkout prod + MERGE_COMMIT=$(git log --merges --pretty=%H -n 1) + if [ -z "$MERGE_COMMIT" ]; then + echo "No merge commit found in prod branch" + exit 1 + fi + echo "Merge commit validated: $MERGE_COMMIT" + + # Notify on merge conflict + - name: Notify on merge conflict + if: steps.push.outputs.conflict == 'true' + run: | + gh issue create \ + --title "Merge Conflict: Test to Prod" \ + --body "Merge conflict occurred while merging test into prod. Conflict branch created. Check PR for details." \ + --repo ${{ github.repository }} + env: + GH_TOKEN: ${{ secrets.PAT }} diff --git a/f11.txt b/f11.txt index 55c5d2c..e69de29 100644 --- a/f11.txt +++ b/f11.txt @@ -1 +0,0 @@ -test test normal commit \ No newline at end of file