Gradle Wrapper Upgrade #96
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Gradle Wrapper Upgrade | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 12 * * *' # daily at 12:00 | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
update-gradle-wrapper: | |
runs-on: ubuntu-24.04 | |
timeout-minutes: 5 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Fetch wrapper version | |
run: | | |
URL=$(grep 'distributionUrl' "./gradle/wrapper/gradle-wrapper.properties") | |
echo "WRAPPER_VERSION=$(echo $URL | sed -n 's/.*gradle-\([0-9]*\.[0-9]*\)-\(bin\|all\)\.zip.*/\1/p')" >> $GITHUB_ENV | |
- name: Fetch latest version | |
run: | | |
JSON=$(curl -s "https://services.gradle.org/versions/current") | |
echo "LATEST_VERSION=$(echo $JSON | jq -r .version)" >> $GITHUB_ENV | |
- name: Update Gradle Wrapper | |
run: | | |
if [ ${{ env.WRAPPER_VERSION }} != ${{ env.LATEST_VERSION }} ]; then | |
./gradlew wrapper --gradle-version=${{ env.LATEST_VERSION }} | |
echo "WRAPPER_UPDATED=true" >> $GITHUB_ENV | |
fi | |
- name: Commit changes | |
if: ${{ env.WRAPPER_UPDATED }} | |
run: | | |
BRANCH="gradle-${{ env.LATEST_VERSION }}" | |
echo "BRANCH=$BRANCH" >> $GITHUB_ENV | |
git checkout -b $BRANCH | |
git config user.name "${{ github.actor }}" | |
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" | |
git add -A | |
git commit -m "build: bump gradle from ${{ env.WRAPPER_VERSION }} to ${{ env.LATEST_VERSION }}" | |
git push --force origin $BRANCH | |
- name: Create pull request | |
if: ${{ env.WRAPPER_UPDATED }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
if ! (( $(gh pr list --state open --head ${{ env.BRANCH }} --json number --jq length) )); then | |
gh pr create --fill-first --label "chore" --head ${{ env.BRANCH }} | |
fi |