From 8f13d6b0466ea853ec80abe200beac4ee571613e Mon Sep 17 00:00:00 2001 From: frocode Date: Tue, 29 Jul 2025 13:42:02 +0200 Subject: [PATCH 01/12] # 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 02/12] ++ --- 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 03/12] 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 From 58473de1c92cd455e7085c692b7df1ad9930247f Mon Sep 17 00:00:00 2001 From: frocode Date: Fri, 22 Aug 2025 12:09:34 +0200 Subject: [PATCH 04/12] deded --- 2.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/2.txt b/2.txt index e69de29..a3c4398 100644 --- a/2.txt +++ b/2.txt @@ -0,0 +1 @@ +sdws \ No newline at end of file From 81ce36f558c0fc8538ed39bb5e9087239a901370 Mon Sep 17 00:00:00 2001 From: frocode Date: Fri, 22 Aug 2025 12:27:10 +0200 Subject: [PATCH 05/12] ded --- 2.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2.txt b/2.txt index a3c4398..0178531 100644 --- a/2.txt +++ b/2.txt @@ -1 +1 @@ -sdws \ No newline at end of file +sdwsde \ No newline at end of file From af7e6cc7875f147ab6985787a6d1ca0031ed2a95 Mon Sep 17 00:00:00 2001 From: frocode Date: Fri, 22 Aug 2025 12:51:08 +0200 Subject: [PATCH 06/12] fix the conflict --- 2.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/2.txt b/2.txt index 8b13789..e69de29 100644 --- a/2.txt +++ b/2.txt @@ -1 +0,0 @@ - From 44242a332579f046a717ef81e57ee1591683bf38 Mon Sep 17 00:00:00 2001 From: frocode Date: Fri, 22 Aug 2025 12:57:34 +0200 Subject: [PATCH 07/12] fix conflicts --- 2.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/2.txt b/2.txt index e69de29..8b13789 100644 --- a/2.txt +++ b/2.txt @@ -0,0 +1 @@ + From 09496435050aebba8875251ef5053865b2386804 Mon Sep 17 00:00:00 2001 From: frocode Date: Fri, 22 Aug 2025 13:02:49 +0200 Subject: [PATCH 08/12] adeed --- main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main.py b/main.py index fb314e0..0eed882 100644 --- a/main.py +++ b/main.py @@ -36,3 +36,4 @@ def merge_sorted_arrays(arr1, arr2): # second commit f99 # feature 7 added +# added \ No newline at end of file From 05ae757542ab2c2bdfbf6a54d327c43b714ad582 Mon Sep 17 00:00:00 2001 From: frocode Date: Fri, 22 Aug 2025 13:24:03 +0200 Subject: [PATCH 09/12] ded --- f13.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/f13.txt b/f13.txt index 08fe8fc..0ec04ab 100644 --- a/f13.txt +++ b/f13.txt @@ -1,3 +1,4 @@ # test commit 19 # test commit 15 +# aded \ No newline at end of file From cfde15e7aa7a52790a53d7925c8cfa8715795f2d Mon Sep 17 00:00:00 2001 From: frocode Date: Fri, 22 Aug 2025 18:42:56 +0200 Subject: [PATCH 10/12] ded --- f11.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/f11.txt b/f11.txt index 55c5d2c..8ea3a12 100644 --- a/f11.txt +++ b/f11.txt @@ -1 +1,2 @@ -test test normal commit \ No newline at end of file +test test normal commit +22 \ No newline at end of file From c26d2034668ad9c56bae4342a0717ff6d77b080c Mon Sep 17 00:00:00 2001 From: frocode Date: Fri, 22 Aug 2025 19:04:02 +0200 Subject: [PATCH 11/12] dd --- f11.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/f11.txt b/f11.txt index 8ea3a12..24b851b 100644 --- a/f11.txt +++ b/f11.txt @@ -1,2 +1 @@ test test normal commit -22 \ No newline at end of file From 3e5599e9b9bd9eb135a92c8b4dacdc775e61f8c5 Mon Sep 17 00:00:00 2001 From: frocode Date: Fri, 22 Aug 2025 19:27:46 +0200 Subject: [PATCH 12/12] de --- f13.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/f13.txt b/f13.txt index 0ec04ab..df6f9bb 100644 --- a/f13.txt +++ b/f13.txt @@ -1,4 +1,5 @@ # test commit 19 # test commit 15 -# aded \ No newline at end of file +# aded +de \ No newline at end of file