Skip to content

Workflow file for this run

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: Java CI with Gradle
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
- name: Build with Gradle Wrapper
run: ./gradlew build
- name: Check for changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add .
git commit -m "Update files after build" || echo "changes=no" >> $GITHUB_ENV
- name: Close earlier pull requests
if: ${{ env.changes != 'no' }}
# use the gh cli to close earlier pull requests
run: |
gh pr list --state open --base main --json number,title | jq -r '.[] | select(.title | contains("Update files after build")) | .number' | xargs -I {} gh pr close {} --comment "This PR was closed because a new build was triggered." --delete-branch
- name: Delete unused branches
if: ${{ env.changes != 'no' }}
run: |
git fetch --prune
for branch in $(git branch -r | grep -v '\->' | grep -v 'main' | grep -v 'origin/main'); do
git push origin --delete ${branch#origin/}
done
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
if: ${{ env.changes != 'no' }}
with:
branch: "update-files-after-build-${{ github.run_id }}"
title: "Update files after build"
body: "This PR updates files after the build process."
commit-message: "Update files after build"
delete-branch: true
dependency-submission:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0