Skip to content
Merged

F13 #37

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions .github/workflows/squash-merge-into-dev.yml
Original file line number Diff line number Diff line change
@@ -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 }}
110 changes: 110 additions & 0 deletions .github/workflows/test_to_prod.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 0 additions & 1 deletion f11.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
test test normal commit
3 changes: 0 additions & 3 deletions f13.txt
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@

# test commit 19
# test commit 15
Loading