From df9864192e2ed393d98b2957fc6352bea96e7af3 Mon Sep 17 00:00:00 2001 From: gaming <48131223+TheGamer1002@users.noreply.github.com> Date: Sat, 19 Oct 2024 12:27:29 -0400 Subject: [PATCH] feat(ci): setup auto-pushing --- .github/workflows/gradle.yml | 50 ++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 87d5ecb..81197da 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -18,7 +18,8 @@ jobs: runs-on: ubuntu-latest permissions: - contents: read + contents: write + pull-requests: write steps: - uses: actions/checkout@v4 @@ -28,24 +29,43 @@ jobs: java-version: '17' distribution: 'temurin' - # Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies. - # See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md - name: Setup Gradle uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 - name: Build with Gradle Wrapper run: ./gradlew build - # NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html). - # If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version. - # - # - name: Setup Gradle - # uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 - # with: - # gradle-version: '8.9' - # - # - name: Build with Gradle 8.9 - # run: gradle 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: @@ -61,7 +81,5 @@ jobs: java-version: '17' distribution: 'temurin' - # Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies. - # See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md - name: Generate and submit dependency graph - uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 + uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 \ No newline at end of file