Skip to content

Commit b394d50

Browse files
authored
Update GHA workflows to avoid creating PRs if no changes to commit (#9317)
* Update docker build workflow * Update jmxfetch submodule workflow
1 parent 00f8da0 commit b394d50

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

.github/workflows/update-docker-build-image.yaml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,7 @@ jobs:
2626

2727
- name: Checkout the repository
2828
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29-
- name: Download ghcommit CLI
30-
run: |
31-
curl https://github.com/planetscale/ghcommit/releases/download/v0.1.48/ghcommit_linux_amd64 -o /usr/local/bin/ghcommit -L
32-
chmod +x /usr/local/bin/ghcommit
33-
- name: Pick a branch name
34-
id: define-branch
35-
run: echo "branch=ci/update-docker-build-image-$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
36-
- name: Create branch
37-
run: |
38-
git checkout -b ${{ steps.define-branch.outputs.branch }}
39-
git push -u origin ${{ steps.define-branch.outputs.branch }} --force
40-
- name: Define the Docker build image tage to use
29+
- name: Define the Docker build image tag to use
4130
id: define-tag
4231
run: |
4332
if [ -n "${{ github.event.inputs.tag }}" ]; then
@@ -59,12 +48,38 @@ jobs:
5948
- name: Update the Docker build image in GitLab CI config
6049
run: |
6150
sed -i -E 's|(BUILDER_IMAGE_VERSION_PREFIX:)[^#]*([#].*)|\1 "${{ steps.define-tag.outputs.tag }}-" \2|' .gitlab-ci.yml
51+
- name: Check if changes should be committed
52+
id: check-changes
53+
run: |
54+
if [[ -z "$(git status -s)" ]]; then
55+
echo "No changes to commit, exiting."
56+
echo "commit_changes=false" >> "$GITHUB_OUTPUT"
57+
exit 0
58+
else
59+
echo "commit_changes=true" >> "$GITHUB_OUTPUT"
60+
fi
61+
- name: Download ghcommit CLI
62+
if: steps.check-changes.outputs.commit_changes == 'true'
63+
run: |
64+
curl https://github.com/planetscale/ghcommit/releases/download/v0.1.48/ghcommit_linux_amd64 -o /usr/local/bin/ghcommit -L
65+
chmod +x /usr/local/bin/ghcommit
66+
- name: Pick a branch name
67+
if: steps.check-changes.outputs.commit_changes == 'true'
68+
id: define-branch
69+
run: echo "branch=ci/update-docker-build-image-$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
70+
- name: Create branch
71+
if: steps.check-changes.outputs.commit_changes == 'true'
72+
run: |
73+
git checkout -b ${{ steps.define-branch.outputs.branch }}
74+
git push -u origin ${{ steps.define-branch.outputs.branch }} --force
6275
- name: Commit and push changes
76+
if: steps.check-changes.outputs.commit_changes == 'true'
6377
env:
6478
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}
6579
run: |
6680
ghcommit --repository ${{ github.repository }} --branch ${{ steps.define-branch.outputs.branch }} --add .gitlab-ci.yml --message "feat(ci): Update Docker build image"
6781
- name: Create pull request
82+
if: steps.check-changes.outputs.commit_changes == 'true'
6883
env:
6984
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
7085
run: |

.github/workflows/update-jmxfetch-submodule.yaml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,37 @@ jobs:
2424
- name: Update Submodule
2525
run: |
2626
git submodule update --remote -- dd-java-agent/agent-jmxfetch/integrations-core
27+
- name: Check if changes should be committed
28+
id: check-changes
29+
run: |
30+
if [[ -z "$(git status -s)" ]]; then
31+
echo "No changes to commit, exiting."
32+
echo "commit_changes=false" >> "$GITHUB_OUTPUT"
33+
exit 0
34+
else
35+
echo "commit_changes=true" >> "$GITHUB_OUTPUT"
36+
fi
2737
- name: Pick a branch name
38+
if: steps.check-changes.outputs.commit_changes == 'true'
2839
id: define-branch
2940
run: echo "branch=ci/update-jmxfetch-submodule-$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
3041
- name: Create branch
42+
if: steps.check-changes.outputs.commit_changes == 'true'
3143
run: |
3244
git checkout -b ${{ steps.define-branch.outputs.branch }}
3345
git push -u origin ${{ steps.define-branch.outputs.branch }} --force
3446
- name: Commit and push changes
47+
if: steps.check-changes.outputs.commit_changes == 'true'
3548
env:
3649
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}
3750
run: |
3851
git config user.name "github-actions[bot]"
3952
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
40-
if [[ -z "$(git status -s)" ]]; then
41-
echo "No changes to commit, exiting."
42-
exit 0;
43-
fi
44-
git checkout -b ${{ steps.define-branch.outputs.branch }}
4553
git add dd-java-agent/agent-jmxfetch/integrations-core
4654
git commit -m "Update agent-jmxfetch submodule"
4755
git push origin ${{ steps.define-branch.outputs.branch }}
4856
- name: Create pull request
57+
if: steps.check-changes.outputs.commit_changes == 'true'
4958
env:
5059
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
5160
run: |

0 commit comments

Comments
 (0)