Skip to content

Commit 4316b12

Browse files
committed
ci: handle no commit gracefully
1 parent af14795 commit 4316b12

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
id: generate-commits
2222
run: |
2323
chmod +x .github/scripts/promote_to_master.sh
24-
.github/scripts/promote_to_master.sh
24+
bash .github/scripts/promote_to_master.sh
2525
2626
# Use a fixed branch name for the PR
2727
- name: Update dev-to-master branch
@@ -37,8 +37,26 @@ jobs:
3737
git checkout -b $BRANCH_NAME
3838
git push --force origin $BRANCH_NAME
3939
40+
# Check if there are any commits between master and our branch
41+
- name: Check for commits between branches
42+
id: check-commits
43+
run: |
44+
# Compare the branches to see if there are any differences
45+
COMMIT_COUNT=$(git rev-list --count master..$BRANCH_NAME)
46+
echo "commit_count=$COMMIT_COUNT" >> $GITHUB_OUTPUT
47+
if [ "$COMMIT_COUNT" -gt 0 ]; then
48+
echo "Detected $COMMIT_COUNT commit(s) between master and $BRANCH_NAME"
49+
echo "has_commits=true" >> $GITHUB_OUTPUT
50+
else
51+
echo "No commits detected between master and $BRANCH_NAME"
52+
echo "has_commits=false" >> $GITHUB_OUTPUT
53+
fi
54+
env:
55+
BRANCH_NAME: "automated-dev-to-master-branch"
56+
4057
# Create or update PR using GitHub API with retry logic
4158
- name: Create or Update Pull Request
59+
if: steps.check-commits.outputs.has_commits == 'true'
4260
uses: actions/github-script@v6
4361
with:
4462
github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -113,6 +131,13 @@ jobs:
113131
}
114132
}
115133
134+
# Output message when no commits are found
135+
- name: No Commits Message
136+
if: steps.check-commits.outputs.has_commits == 'false'
137+
run: |
138+
echo "::notice::No new commits detected between master and dev branches. Skipping PR creation."
139+
echo "The branches master and dev are already in sync."
140+
116141
release:
117142
name: release
118143
if: ${{ github.ref == 'refs/heads/master' }}

0 commit comments

Comments
 (0)