|
| 1 | +name: Update Maven Wrapper |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 19 * * 5' |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + update: |
| 10 | + permissions: |
| 11 | + contents: write |
| 12 | + pull-requests: write |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - uses: actions/setup-java@v4 |
| 18 | + with: |
| 19 | + java-version: '21' |
| 20 | + distribution: 'temurin' |
| 21 | + |
| 22 | + - name: Get latest Maven version |
| 23 | + # This fetches latest Maven releas from maven.org - not the download page; it might be delayed a few days after releases. |
| 24 | + # Note that the "gav" at the end of the URL ensures we use only generally available version. As of now, this is 3.x. |
| 25 | + id: maven |
| 26 | + run: | |
| 27 | + LATEST=$(curl -s "https://search.maven.org/solrsearch/select?q=g:org.apache.maven+a:apache-maven&rows=1&wt=json&core=gav" \ |
| 28 | + | jq -r '[.response.docs[].v | select(test("^3\\.\\d+\\.\\d+$"))] | first') |
| 29 | + echo "version=$LATEST" >> $GITHUB_OUTPUT |
| 30 | +
|
| 31 | + - name: Update wrapper |
| 32 | + # Update Maven wrapper scripts AND maven-wrapper.properties. |
| 33 | + # Note that this removes the SHA from properties file. |
| 34 | + run: ./mvnw wrapper:wrapper -Dmaven=${{ steps.maven.outputs.version }} |
| 35 | + |
| 36 | + - name: Patch SHA512 into wrapper properties |
| 37 | + # Add the SHA to properties file. |
| 38 | + # We might need the -L for curl, as after a new release all old SHA files will move to . |
| 39 | + run: | |
| 40 | + VERSION=${{ steps.maven.outputs.version }} |
| 41 | + MAJOR=$(echo "$VERSION" | cut -d. -f1) |
| 42 | + SHA=$(curl -sL "https://downloads.apache.org/maven/maven-${MAJOR}/${VERSION}/binaries/apache-maven-${VERSION}-bin.zip.sha512") |
| 43 | + PROPS=".mvn/wrapper/maven-wrapper.properties" |
| 44 | + sed -i '/^distributionSha512Sum=/d' "$PROPS" |
| 45 | + echo "distributionSha512Sum=${SHA}" >> "$PROPS" |
| 46 | +
|
| 47 | + - name: Open PR if changed |
| 48 | + uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # 8.1.0 |
| 49 | + with: |
| 50 | + commit-message: "Update maven wrapper to ${{ steps.maven.outputs.version }}" |
| 51 | + title: "Update Maven Wrapper to ${{ steps.maven.outputs.version }}" |
| 52 | + branch: gha/update-maven-wrapper |
| 53 | + delete-branch: true |
| 54 | + labels: infrastructure |
0 commit comments