Skip to content

Commit cc21133

Browse files
committed
Update gradle workflow
1 parent 8c6e5cd commit cc21133

File tree

1 file changed

+34
-41
lines changed

1 file changed

+34
-41
lines changed

.github/workflows/update-gradle-dependencies.yaml

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
name: Update Gradle dependencies
1111
permissions:
12-
contents: write # Required to create new branch
12+
contents: read
1313
id-token: write # Required for OIDC token federation
1414
steps:
1515
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
@@ -22,16 +22,6 @@ jobs:
2222
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # 5.0.0
2323
with:
2424
submodules: "recursive"
25-
- name: Download ghcommit CLI
26-
run: |
27-
curl https://github.com/planetscale/ghcommit/releases/download/v0.1.48/ghcommit_linux_amd64 -o /usr/local/bin/ghcommit -L
28-
chmod +x /usr/local/bin/ghcommit
29-
- name: Pick a branch name
30-
run: echo "BRANCH_NAME=ci/update-gradle-dependencies-$(date +'%Y%m%d')" >> $GITHUB_ENV
31-
- name: Create branch
32-
run: |
33-
git checkout -b $BRANCH_NAME
34-
git push -u origin $BRANCH_NAME --force
3525
- name: Update Gradle dependencies
3626
env:
3727
ORG_GRADLE_PROJECT_akkaRepositoryToken: ${{ secrets.AKKA_REPO_TOKEN }}
@@ -42,40 +32,43 @@ jobs:
4232
JAVA_11_HOME=$JAVA_HOME_11_X64 \
4333
JAVA_17_HOME=$JAVA_HOME_17_X64 \
4434
JAVA_21_HOME=$JAVA_HOME_21_X64 \
35+
JAVA_25_HOME=$JAVA_HOME_25_X64 \
4536
./gradlew resolveAndLockAll --write-locks --parallel --stacktrace --no-daemon --max-workers=4
46-
- name: Commit changes
47-
env:
48-
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}
37+
- name: Check if changes should be committed
38+
id: check-changes
4939
run: |
50-
GH_ADD_ARGS=""
51-
COUNT=0
52-
BRANCH_HEAD=$(git rev-parse HEAD)
53-
for lockfile in $(git status --porcelain=v1 -- ':(glob)**/gradle.lockfile' | awk '{ print $NF }'); do
54-
echo "Found lockfile: $lockfile"
55-
GH_ADD_ARGS="$GH_ADD_ARGS --add $lockfile"
56-
COUNT=$((COUNT+1))
57-
if [ $COUNT -eq 10 ]; then
58-
echo "Creating a commit to $BRANCH_NAME@$BRANCH_HEAD with $GH_ADD_ARGS"
59-
OUTPUT=$(ghcommit --repository ${{ github.repository }} --branch $BRANCH_NAME --sha $BRANCH_HEAD $GH_ADD_ARGS --message "chore: Update Gradle dependencies" 2>&1)
60-
echo $OUTPUT
61-
if [[ $OUTPUT != *"Success. New commit"* ]]; then
62-
exit 1
63-
fi
64-
BRANCH_HEAD=${OUTPUT##*/}
65-
echo "ghcommit output: $OUTPUT"
66-
GH_ADD_ARGS=""
67-
COUNT=0
68-
fi
69-
done
70-
# Check at uncommited files
71-
echo "Checking uncommited files"
72-
git status
73-
# Create a PR from the created branch
74-
if [ $COUNT -gt 0 ]; then
75-
echo "Creating a commit to $BRANCH_NAME@$BRANCH_HEAD with $GH_ADD_ARGS"
76-
ghcommit --repository ${{ github.repository }} --branch $BRANCH_NAME --sha $BRANCH_HEAD $GH_ADD_ARGS --message "chore: Update Gradle dependencies"
40+
if [[ -z "$(git status -s)" ]]; then
41+
echo "No changes to commit, exiting."
42+
echo "commit_changes=false" >> "$GITHUB_OUTPUT"
43+
exit 0
44+
else
45+
echo "commit_changes=true" >> "$GITHUB_OUTPUT"
7746
fi
47+
- name: Pick a branch name
48+
if: steps.check-changes.outputs.commit_changes == 'true'
49+
id: define-branch
50+
run: echo "BRANCH_NAME=ci/update-gradle-dependencies-$(date +'%Y%m%d')" >> $GITHUB_ENV
51+
- name: Commit changes
52+
if: steps.check-changes.outputs.commit_changes == 'true'
53+
id: create-commit
54+
run: |
55+
git config user.name "github-actions[bot]"
56+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
57+
git commit -a -m "chore: Update Gradle dependencies"
58+
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
59+
- name: Push changes
60+
uses: DataDog/commit-headless@1186485b788f57eedaaadb19919781698b4d262f # action/v1.0.0
61+
if: steps.check-changes.outputs.commit_changes == 'true'
62+
with:
63+
token: "${{ steps.octo-sts.outputs.token }}"
64+
branch: "${{ steps.define-branch.outputs.branch }}"
65+
# for scheduled runs, sha is the tip of the default branch
66+
# for dispatched runs, sha is the tip of the branch it was dispatched on
67+
branch-from: "${{ github.sha }}"
68+
command: push
69+
commits: "${{ steps.create-commit.outputs.commit }}"
7870
- name: Create pull request
71+
if: steps.check-changes.outputs.commit_changes == 'true'
7972
env:
8073
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
8174
run: |

0 commit comments

Comments
 (0)