Skip to content

Commit a104f21

Browse files
committed
updated auto merge workflow
1 parent 45dbff3 commit a104f21

File tree

4 files changed

+65
-15
lines changed

4 files changed

+65
-15
lines changed

.github/workflows/auto-merge-golang.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ jobs:
5151
if [[ "${{ github.event.inputs.force_update }}" == "true" ]]; then
5252
echo "Force update requested, proceeding with update"
5353
echo "has_changes=true" >> $GITHUB_OUTPUT
54-
echo "$GO_REPO_COMMIT" > last_processed_commit.txt
5554
exit 0
5655
fi
5756
@@ -66,12 +65,10 @@ jobs:
6665
else
6766
echo "New changes detected in golang/go repository"
6867
echo "has_changes=true" >> $GITHUB_OUTPUT
69-
echo "$GO_REPO_COMMIT" > last_processed_commit.txt
7068
fi
7169
else
7270
echo "First time running workflow or tracking file not found"
7371
echo "has_changes=true" >> $GITHUB_OUTPUT
74-
echo "$GO_REPO_COMMIT" > last_processed_commit.txt
7572
fi
7673
7774
- name: Extract Go version
@@ -140,7 +137,7 @@ jobs:
140137
# Push to the update branch
141138
git push origin ${UPDATE_BRANCH}
142139
143-
- name: Create PR for the changes
140+
- name: Create and merge PR for the changes
144141
if: steps.check_changes.outputs.has_changes == 'true'
145142
env:
146143
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -152,5 +149,19 @@ jobs:
152149
153150
gh pr create --title "${PR_TITLE}" --body "${PR_BODY}" --base master --head ${UPDATE_BRANCH}
154151
155-
# Auto-approve and merge immediately
156-
gh pr merge ${UPDATE_BRANCH} --auto --squash
152+
# Wait a moment for PR to be created and any initial checks to start
153+
sleep 10
154+
155+
# Get PR number
156+
PR_NUMBER=$(gh pr list --head ${UPDATE_BRANCH} --json number --jq '.[0].number')
157+
echo "Created PR #${PR_NUMBER}"
158+
159+
# Check if PR can be merged (has no conflicts)
160+
if gh pr view ${PR_NUMBER} --json mergeable | grep -q '"mergeable": true'; then
161+
echo "PR is mergeable, attempting to merge"
162+
# Auto-approve and merge
163+
gh pr merge ${PR_NUMBER} --admin --squash --delete-branch
164+
else
165+
echo "PR has conflicts and cannot be auto-merged. Manual intervention required."
166+
exit 1
167+
fi

.github/workflows/build-and-release-linux.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,30 @@ jobs:
7171
cd golang-repo
7272
echo "GO_REPO_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
7373
74+
- name: Check if workflow is triggered by auto-merge
75+
id: workflow_trigger
76+
run: |
77+
if [[ "${{ github.event_name }}" == "workflow_run" ]]; then
78+
echo "This workflow was triggered by the auto-merge workflow."
79+
echo "has_changes=true" >> $GITHUB_OUTPUT
80+
exit 0
81+
fi
82+
7483
- name: Check if new changes exist in upstream
7584
id: check_changes
7685
if: ${{ github.event_name != 'workflow_run' || steps.workflow_check.outputs.workflow_succeeded == 'true' }}
7786
run: |
87+
# If this is triggered by a workflow_run, we already know we have changes
88+
if [[ "${{ steps.workflow_trigger.outputs.has_changes }}" == "true" ]]; then
89+
echo "Changes detected from auto-merge workflow"
90+
echo "has_changes=true" >> $GITHUB_OUTPUT
91+
exit 0
92+
fi
93+
7894
# If force_build is set to true, always build
7995
if [[ "${{ github.event.inputs.force_build }}" == "true" ]]; then
8096
echo "Force build requested, proceeding with build"
8197
echo "has_changes=true" >> $GITHUB_OUTPUT
82-
echo "$GO_REPO_COMMIT" > last_processed_commit.txt
8398
exit 0
8499
fi
85100
@@ -94,12 +109,10 @@ jobs:
94109
else
95110
echo "New changes detected in golang/go repository"
96111
echo "has_changes=true" >> $GITHUB_OUTPUT
97-
echo "$GO_REPO_COMMIT" > last_processed_commit.txt
98112
fi
99113
else
100114
echo "First time running workflow or tracking file not found"
101115
echo "has_changes=true" >> $GITHUB_OUTPUT
102-
echo "$GO_REPO_COMMIT" > last_processed_commit.txt
103116
fi
104117
105118
- name: Extract Go version

.github/workflows/build-and-release-macos.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,30 @@ jobs:
7272
cd golang-repo
7373
echo "GO_REPO_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
7474
75+
- name: Check if workflow is triggered by auto-merge
76+
id: workflow_trigger
77+
run: |
78+
if [[ "${{ github.event_name }}" == "workflow_run" ]]; then
79+
echo "This workflow was triggered by the auto-merge workflow."
80+
echo "has_changes=true" >> $GITHUB_OUTPUT
81+
exit 0
82+
fi
83+
7584
- name: Check if new changes exist in upstream
7685
id: check_changes
7786
if: ${{ github.event_name != 'workflow_run' || steps.workflow_check.outputs.workflow_succeeded == 'true' }}
7887
run: |
88+
# If this is triggered by a workflow_run, we already know we have changes
89+
if [[ "${{ steps.workflow_trigger.outputs.has_changes }}" == "true" ]]; then
90+
echo "Changes detected from auto-merge workflow"
91+
echo "has_changes=true" >> $GITHUB_OUTPUT
92+
exit 0
93+
fi
94+
7995
# If force_build is set to true, always build
8096
if [[ "${{ github.event.inputs.force_build }}" == "true" ]]; then
8197
echo "Force build requested, proceeding with build"
8298
echo "has_changes=true" >> $GITHUB_OUTPUT
83-
echo "$GO_REPO_COMMIT" > last_processed_commit.txt
8499
exit 0
85100
fi
86101
@@ -95,12 +110,10 @@ jobs:
95110
else
96111
echo "New changes detected in golang/go repository"
97112
echo "has_changes=true" >> $GITHUB_OUTPUT
98-
echo "$GO_REPO_COMMIT" > last_processed_commit.txt
99113
fi
100114
else
101115
echo "First time running workflow or tracking file not found"
102116
echo "has_changes=true" >> $GITHUB_OUTPUT
103-
echo "$GO_REPO_COMMIT" > last_processed_commit.txt
104117
fi
105118
106119
- name: Extract Go version

.github/workflows/build-and-release-windows.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,30 @@ jobs:
7272
cd golang-repo
7373
echo "GO_REPO_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
7474
75+
- name: Check if workflow is triggered by auto-merge
76+
id: workflow_trigger
77+
run: |
78+
if [[ "${{ github.event_name }}" == "workflow_run" ]]; then
79+
echo "This workflow was triggered by the auto-merge workflow."
80+
echo "has_changes=true" >> $GITHUB_OUTPUT
81+
exit 0
82+
fi
83+
7584
- name: Check if new changes exist in upstream
7685
id: check_changes
7786
if: ${{ github.event_name != 'workflow_run' || steps.workflow_check.outputs.workflow_succeeded == 'true' }}
7887
run: |
88+
# If this is triggered by a workflow_run, we already know we have changes
89+
if [[ "${{ steps.workflow_trigger.outputs.has_changes }}" == "true" ]]; then
90+
echo "Changes detected from auto-merge workflow"
91+
echo "has_changes=true" >> $GITHUB_OUTPUT
92+
exit 0
93+
fi
94+
7995
# If force_build is set to true, always build
8096
if [[ "${{ github.event.inputs.force_build }}" == "true" ]]; then
8197
echo "Force build requested, proceeding with build"
8298
echo "has_changes=true" >> $GITHUB_OUTPUT
83-
echo "$GO_REPO_COMMIT" > last_processed_commit.txt
8499
exit 0
85100
fi
86101
@@ -95,12 +110,10 @@ jobs:
95110
else
96111
echo "New changes detected in golang/go repository"
97112
echo "has_changes=true" >> $GITHUB_OUTPUT
98-
echo "$GO_REPO_COMMIT" > last_processed_commit.txt
99113
fi
100114
else
101115
echo "First time running workflow or tracking file not found"
102116
echo "has_changes=true" >> $GITHUB_OUTPUT
103-
echo "$GO_REPO_COMMIT" > last_processed_commit.txt
104117
fi
105118
106119
- name: Extract Go version

0 commit comments

Comments
 (0)