From eea733b715f124bf81bbea8072aa97a33995ff57 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 14 Feb 2025 10:08:41 -0500 Subject: [PATCH 1/7] add CI action that requires clean merges between all named branches --- .github/workflows/require-clean-merges.yml | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/require-clean-merges.yml diff --git a/.github/workflows/require-clean-merges.yml b/.github/workflows/require-clean-merges.yml new file mode 100644 index 0000000000..320a8c0a2c --- /dev/null +++ b/.github/workflows/require-clean-merges.yml @@ -0,0 +1,46 @@ +name: Require Clean Merges + +on: + pull_request: + branches: + - devnet-ready + - devnet + - testnet + +jobs: + assert-clean-merges: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Ensures we get all branches for merging + + - name: Determine Target Branch and Set Merge List + id: set-merge-branches + run: | + TARGET_BRANCH="${{ github.event.pull_request.base.ref }}" + if [[ "$TARGET_BRANCH" == "devnet-ready" ]]; then + echo "MERGE_BRANCHES=devnet-ready devnet testnet main" >> $GITHUB_ENV + elif [[ "$TARGET_BRANCH" == "devnet" ]]; then + echo "MERGE_BRANCHES=devnet testnet main" >> $GITHUB_ENV + elif [[ "$TARGET_BRANCH" == "testnet" ]]; then + echo "MERGE_BRANCHES=testnet main" >> $GITHUB_ENV + elif [[ "$TARGET_BRANCH" == "main" ]]; then + echo "MERGE_BRANCHES=main" >> $GITHUB_ENV + else + echo "MERGE_BRANCHES=devnet-ready devnet testnet main" >> $GITHUB_ENV" + fi + + - name: Check Merge Cleanliness + run: | + for branch in $MERGE_BRANCHES; do + echo "Checking merge from $branch into ${{ github.event.pull_request.base.ref }}..." + git fetch origin $branch + git checkout ${{ github.event.pull_request.base.ref }} + if ! git merge --no-commit --no-ff origin/$branch; then + echo "Merge conflict detected when merging $branch into ${{ github.event.pull_request.base.ref }}" + exit 1 + fi + git merge --abort + done From 74be0ea3638ce972c435c85e2d0e1165d7d903b2 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 14 Feb 2025 10:10:52 -0500 Subject: [PATCH 2/7] fix --- .github/workflows/require-clean-merges.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/require-clean-merges.yml b/.github/workflows/require-clean-merges.yml index 320a8c0a2c..ba162e0ee1 100644 --- a/.github/workflows/require-clean-merges.yml +++ b/.github/workflows/require-clean-merges.yml @@ -29,7 +29,7 @@ jobs: elif [[ "$TARGET_BRANCH" == "main" ]]; then echo "MERGE_BRANCHES=main" >> $GITHUB_ENV else - echo "MERGE_BRANCHES=devnet-ready devnet testnet main" >> $GITHUB_ENV" + echo "MERGE_BRANCHES=devnet-ready devnet testnet main" >> $GITHUB_ENV fi - name: Check Merge Cleanliness From 1ed6a9cdb2f4fdb54ee9736edc2745a184139fef Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 14 Feb 2025 10:13:56 -0500 Subject: [PATCH 3/7] fixes --- .github/workflows/require-clean-merges.yml | 30 ++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/.github/workflows/require-clean-merges.yml b/.github/workflows/require-clean-merges.yml index ba162e0ee1..afe1ce4f06 100644 --- a/.github/workflows/require-clean-merges.yml +++ b/.github/workflows/require-clean-merges.yml @@ -21,26 +21,36 @@ jobs: run: | TARGET_BRANCH="${{ github.event.pull_request.base.ref }}" if [[ "$TARGET_BRANCH" == "devnet-ready" ]]; then - echo "MERGE_BRANCHES=devnet-ready devnet testnet main" >> $GITHUB_ENV + echo "MERGE_BRANCHES='devnet testnet main'" >> $GITHUB_ENV elif [[ "$TARGET_BRANCH" == "devnet" ]]; then - echo "MERGE_BRANCHES=devnet testnet main" >> $GITHUB_ENV + echo "MERGE_BRANCHES='testnet main'" >> $GITHUB_ENV elif [[ "$TARGET_BRANCH" == "testnet" ]]; then - echo "MERGE_BRANCHES=testnet main" >> $GITHUB_ENV + echo "MERGE_BRANCHES='main'" >> $GITHUB_ENV elif [[ "$TARGET_BRANCH" == "main" ]]; then - echo "MERGE_BRANCHES=main" >> $GITHUB_ENV + echo "MERGE_BRANCHES=''" >> $GITHUB_ENV else - echo "MERGE_BRANCHES=devnet-ready devnet testnet main" >> $GITHUB_ENV + echo "MERGE_BRANCHES='devnet-ready devnet testnet main'" >> $GITHUB_ENV fi - name: Check Merge Cleanliness run: | + TARGET_BRANCH="${{ github.event.pull_request.base.ref }}" + echo "Fetching all branches..." + git fetch --all --prune + for branch in $MERGE_BRANCHES; do - echo "Checking merge from $branch into ${{ github.event.pull_request.base.ref }}..." - git fetch origin $branch - git checkout ${{ github.event.pull_request.base.ref }} + echo "Checking merge from $branch into $TARGET_BRANCH..." + + # Ensure we are on the target branch + git checkout $TARGET_BRANCH + git reset --hard origin/$TARGET_BRANCH + + # Merge without committing to check for conflicts if ! git merge --no-commit --no-ff origin/$branch; then - echo "Merge conflict detected when merging $branch into ${{ github.event.pull_request.base.ref }}" + echo "❌ Merge conflict detected when merging $branch into $TARGET_BRANCH" exit 1 fi - git merge --abort + + # Abort the merge since we are only testing + git merge --abort || true done From bd1556e286037970bbeb287693d2c7e56358f1ae Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 14 Feb 2025 10:20:42 -0500 Subject: [PATCH 4/7] try again --- .github/workflows/require-clean-merges.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/require-clean-merges.yml b/.github/workflows/require-clean-merges.yml index afe1ce4f06..90421b76d6 100644 --- a/.github/workflows/require-clean-merges.yml +++ b/.github/workflows/require-clean-merges.yml @@ -21,15 +21,15 @@ jobs: run: | TARGET_BRANCH="${{ github.event.pull_request.base.ref }}" if [[ "$TARGET_BRANCH" == "devnet-ready" ]]; then - echo "MERGE_BRANCHES='devnet testnet main'" >> $GITHUB_ENV + echo "MERGE_BRANCHES=devnet testnet main" >> $GITHUB_ENV elif [[ "$TARGET_BRANCH" == "devnet" ]]; then - echo "MERGE_BRANCHES='testnet main'" >> $GITHUB_ENV + echo "MERGE_BRANCHES=testnet main" >> $GITHUB_ENV elif [[ "$TARGET_BRANCH" == "testnet" ]]; then - echo "MERGE_BRANCHES='main'" >> $GITHUB_ENV + echo "MERGE_BRANCHES=main" >> $GITHUB_ENV elif [[ "$TARGET_BRANCH" == "main" ]]; then - echo "MERGE_BRANCHES=''" >> $GITHUB_ENV + echo "MERGE_BRANCHES=" >> $GITHUB_ENV # No need to merge anything into main else - echo "MERGE_BRANCHES='devnet-ready devnet testnet main'" >> $GITHUB_ENV + echo "MERGE_BRANCHES=devnet-ready devnet testnet main" >> $GITHUB_ENV fi - name: Check Merge Cleanliness @@ -41,10 +41,16 @@ jobs: for branch in $MERGE_BRANCHES; do echo "Checking merge from $branch into $TARGET_BRANCH..." - # Ensure we are on the target branch + # Ensure we are on the target branch and reset to its latest state git checkout $TARGET_BRANCH git reset --hard origin/$TARGET_BRANCH + # Ensure branch exists before attempting a merge + if ! git show-ref --verify --quiet "refs/remotes/origin/$branch"; then + echo "❌ Branch $branch does not exist on remote, skipping..." + continue + fi + # Merge without committing to check for conflicts if ! git merge --no-commit --no-ff origin/$branch; then echo "❌ Merge conflict detected when merging $branch into $TARGET_BRANCH" From 1b6e89ffe2721fd677896e420b8d57a6b98b8897 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 14 Feb 2025 10:26:29 -0500 Subject: [PATCH 5/7] fix again --- .github/workflows/require-clean-merges.yml | 26 +++++++++------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/.github/workflows/require-clean-merges.yml b/.github/workflows/require-clean-merges.yml index 90421b76d6..98fb60b7f4 100644 --- a/.github/workflows/require-clean-merges.yml +++ b/.github/workflows/require-clean-merges.yml @@ -21,15 +21,15 @@ jobs: run: | TARGET_BRANCH="${{ github.event.pull_request.base.ref }}" if [[ "$TARGET_BRANCH" == "devnet-ready" ]]; then - echo "MERGE_BRANCHES=devnet testnet main" >> $GITHUB_ENV + echo "MERGE_BRANCHES='devnet testnet main'" >> $GITHUB_ENV elif [[ "$TARGET_BRANCH" == "devnet" ]]; then - echo "MERGE_BRANCHES=testnet main" >> $GITHUB_ENV + echo "MERGE_BRANCHES='testnet main'" >> $GITHUB_ENV elif [[ "$TARGET_BRANCH" == "testnet" ]]; then - echo "MERGE_BRANCHES=main" >> $GITHUB_ENV + echo "MERGE_BRANCHES='main'" >> $GITHUB_ENV elif [[ "$TARGET_BRANCH" == "main" ]]; then - echo "MERGE_BRANCHES=" >> $GITHUB_ENV # No need to merge anything into main + echo "MERGE_BRANCHES=''" >> $GITHUB_ENV # No need to merge anything into main else - echo "MERGE_BRANCHES=devnet-ready devnet testnet main" >> $GITHUB_ENV + echo "MERGE_BRANCHES='devnet-ready devnet testnet main'" >> $GITHUB_ENV fi - name: Check Merge Cleanliness @@ -41,22 +41,18 @@ jobs: for branch in $MERGE_BRANCHES; do echo "Checking merge from $branch into $TARGET_BRANCH..." - # Ensure we are on the target branch and reset to its latest state + # Ensure we are on the target branch and reset to its latest remote state git checkout $TARGET_BRANCH git reset --hard origin/$TARGET_BRANCH - # Ensure branch exists before attempting a merge - if ! git show-ref --verify --quiet "refs/remotes/origin/$branch"; then - echo "❌ Branch $branch does not exist on remote, skipping..." - continue - fi - # Merge without committing to check for conflicts - if ! git merge --no-commit --no-ff origin/$branch; then + if git merge --no-commit --no-ff origin/$branch; then + echo "✅ Merge from $branch into $TARGET_BRANCH is clean." + else echo "❌ Merge conflict detected when merging $branch into $TARGET_BRANCH" exit 1 fi - # Abort the merge since we are only testing - git merge --abort || true + # Abort merge if one was started, suppressing errors if no merge happened + git merge --abort 2>/dev/null || true done From a4a3aaaae365f8d9d65b9267418f3cf33d53797b Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 14 Feb 2025 10:28:11 -0500 Subject: [PATCH 6/7] fix --- .github/workflows/require-clean-merges.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/require-clean-merges.yml b/.github/workflows/require-clean-merges.yml index 98fb60b7f4..b2550b7880 100644 --- a/.github/workflows/require-clean-merges.yml +++ b/.github/workflows/require-clean-merges.yml @@ -21,15 +21,15 @@ jobs: run: | TARGET_BRANCH="${{ github.event.pull_request.base.ref }}" if [[ "$TARGET_BRANCH" == "devnet-ready" ]]; then - echo "MERGE_BRANCHES='devnet testnet main'" >> $GITHUB_ENV + echo "MERGE_BRANCHES=devnet testnet main" >> $GITHUB_ENV elif [[ "$TARGET_BRANCH" == "devnet" ]]; then - echo "MERGE_BRANCHES='testnet main'" >> $GITHUB_ENV + echo "MERGE_BRANCHES=testnet main" >> $GITHUB_ENV elif [[ "$TARGET_BRANCH" == "testnet" ]]; then - echo "MERGE_BRANCHES='main'" >> $GITHUB_ENV + echo "MERGE_BRANCHES=main" >> $GITHUB_ENV elif [[ "$TARGET_BRANCH" == "main" ]]; then - echo "MERGE_BRANCHES=''" >> $GITHUB_ENV # No need to merge anything into main + echo "MERGE_BRANCHES=" >> $GITHUB_ENV # No need to merge anything into main else - echo "MERGE_BRANCHES='devnet-ready devnet testnet main'" >> $GITHUB_ENV + echo "MERGE_BRANCHES=devnet-ready devnet testnet main" >> $GITHUB_ENV fi - name: Check Merge Cleanliness From 8e061b7411446e91608c2529cd1f4a02b502a378 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 14 Feb 2025 10:30:20 -0500 Subject: [PATCH 7/7] fix --- .github/workflows/require-clean-merges.yml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/require-clean-merges.yml b/.github/workflows/require-clean-merges.yml index b2550b7880..532a411549 100644 --- a/.github/workflows/require-clean-merges.yml +++ b/.github/workflows/require-clean-merges.yml @@ -20,6 +20,9 @@ jobs: id: set-merge-branches run: | TARGET_BRANCH="${{ github.event.pull_request.base.ref }}" + PR_BRANCH="${{ github.event.pull_request.head.ref }}" + echo "PR_BRANCH=$PR_BRANCH" >> $GITHUB_ENV + if [[ "$TARGET_BRANCH" == "devnet-ready" ]]; then echo "MERGE_BRANCHES=devnet testnet main" >> $GITHUB_ENV elif [[ "$TARGET_BRANCH" == "devnet" ]]; then @@ -35,21 +38,25 @@ jobs: - name: Check Merge Cleanliness run: | TARGET_BRANCH="${{ github.event.pull_request.base.ref }}" + PR_BRANCH="${{ github.event.pull_request.head.ref }}" echo "Fetching all branches..." git fetch --all --prune + echo "Checking out PR branch: $PR_BRANCH" + git checkout $PR_BRANCH + git reset --hard origin/$PR_BRANCH + for branch in $MERGE_BRANCHES; do - echo "Checking merge from $branch into $TARGET_BRANCH..." + echo "Checking merge from $branch into $PR_BRANCH..." - # Ensure we are on the target branch and reset to its latest remote state - git checkout $TARGET_BRANCH - git reset --hard origin/$TARGET_BRANCH + # Ensure PR branch is up to date + git reset --hard origin/$PR_BRANCH # Merge without committing to check for conflicts if git merge --no-commit --no-ff origin/$branch; then - echo "✅ Merge from $branch into $TARGET_BRANCH is clean." + echo "✅ Merge from $branch into $PR_BRANCH is clean." else - echo "❌ Merge conflict detected when merging $branch into $TARGET_BRANCH" + echo "❌ Merge conflict detected when merging $branch into $PR_BRANCH" exit 1 fi