Skip to content

Commit

Permalink
feat(ci): setup auto-pushing
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGamer1002 committed Oct 19, 2024
1 parent 1221939 commit df98641
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ jobs:

runs-on: ubuntu-latest
permissions:
contents: read
contents: write
pull-requests: write

steps:
- uses: actions/checkout@v4
Expand All @@ -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:

Expand All @@ -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

0 comments on commit df98641

Please sign in to comment.