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
2222 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
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
2925 - 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
26+ run : echo "branch=ci/update-gradle-dependencies-$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
3527 - name : Update Gradle dependencies
3628 run : |
3729 GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx3G -Xms2G'" \
@@ -42,40 +34,58 @@ jobs:
4234 JAVA_21_HOME=$JAVA_HOME_21_X64 \
4335 ./gradlew resolveAndLockAll --write-locks --parallel --stacktrace --no-daemon --max-workers=4
4436 - name : Commit changes
37+ id : create-commits
4538 env :
46- GITHUB_TOKEN : ${{ steps.octo-sts .outputs.token }}
39+ BRANCH_NAME : ${{ steps.define-branch .outputs.branch }}
4740 run : |
48- GH_ADD_ARGS=""
41+ git config user.name "github-actions[bot]"
42+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
43+
44+ FILES=""
45+ COMMITS=""
4946 COUNT=0
47+ # XXX: Could be replaced by ${{ github.sha }}
5048 BRANCH_HEAD=$(git rev-parse HEAD)
5149 for lockfile in $(git status --porcelain=v1 | awk '{ print $NF }'); do
5250 echo "Found lockfile: $lockfile"
53- GH_ADD_ARGS ="$GH_ADD_ARGS --add $lockfile"
51+ FILES ="$FILES $lockfile"
5452 COUNT=$((COUNT+1))
5553 if [ $COUNT -eq 10 ]; then
56- echo "Creating a commit to $BRANCH_NAME@$BRANCH_HEAD with $GH_ADD_ARGS"
57- OUTPUT=$(ghcommit --repository ${{ github.repository }} --branch $BRANCH_NAME --sha $BRANCH_HEAD $GH_ADD_ARGS --message "chore: Update Gradle dependencies" 2>&1)
58- echo $OUTPUT
59- if [[ $OUTPUT != *"Success. New commit"* ]]; then
60- exit 1
61- fi
62- BRANCH_HEAD=${OUTPUT##*/}
63- echo "ghcommit output: $OUTPUT"
64- GH_ADD_ARGS=""
54+ echo "Creating a commit to $BRANCH_NAME@$BRANCH_HEAD with files $FILES"
55+ git commit --no-verify --message="chore: Update Gradle dependencies" "${FILES}"
56+ COMMITS="$COMMITS $(git rev-parse HEAD)"
57+ FILES=""
6558 COUNT=0
6659 fi
6760 done
6861 # Check at uncommited files
6962 echo "Checking uncommited files"
7063 git status
71- # Create a PR from the created branch
64+
65+ # Commit any remaining files
7266 if [ $COUNT -gt 0 ]; then
73- echo "Creating a commit to $BRANCH_NAME@$BRANCH_HEAD with $GH_ADD_ARGS"
74- ghcommit --repository ${{ github.repository }} --branch $BRANCH_NAME --sha $BRANCH_HEAD $GH_ADD_ARGS --message "chore: Update Gradle dependencies"
67+ echo "Creating a commit to $BRANCH_NAME@$BRANCH_HEAD with $FILES"
68+ git commit --no-verify --message="chore: Update Gradle dependencies" "${FILES}"
69+ COMMITS="$COMMITS $(git rev-parse HEAD)"
7570 fi
71+
72+ echo "Commits to push: ${COMMITS}"
73+ echo "commits=\"${COMMITS}\"" >> $GITHUB_OUTPUT
74+ - name : Push changes
75+ uses : DataDog/commit-headless@1186485b788f57eedaaadb19919781698b4d262f # action/v1.0.0
76+ if : ${{ steps.create-commits.outputs.commits != '' }}
77+ with :
78+ token : " ${{ steps.octo-sts.outputs.token }}"
79+ branch : " ${{ steps.define-branch.outputs.branch }}"
80+ # for scheduled runs, sha is the tip of the default branch
81+ # for dispatched runs, sha is the tip of the branch it was dispatched on
82+ branch-from : " ${{ github.sha }}"
83+ command : push
84+ commits : " ${{ steps.create-commits.outputs.commits }}"
7685 - name : Create pull request
7786 env :
7887 GH_TOKEN : ${{ steps.octo-sts.outputs.token }}
88+ BRANCH_NAME : ${{ steps.define-branch.outputs.branch }}
7989 run : |
8090 # use echo to set a multiline body for the PR
8191 echo -e "This PR updates the Gradle dependencies. ⚠️ Don't forget to squash commits before merging. ⚠️\n\n- [ ] Update PR title if a code change is needed to support one of those new dependencies" | \
0 commit comments