From fb93eb4e5da1420d0e69afe12d58b1445c335487 Mon Sep 17 00:00:00 2001 From: Fiereu Date: Tue, 21 Jul 2026 11:07:40 +0200 Subject: [PATCH] ci: collapse spotless and test into one workflow that runs on PRs (#50) --- .github/workflows/ci.yml | 56 ++++++++++++++++++++++++++++++++++ .github/workflows/spotless.yml | 44 -------------------------- .github/workflows/test.yml | 41 ------------------------- 3 files changed, 56 insertions(+), 85 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/spotless.yml delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3d948d5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,56 @@ +name: CI + +on: + pull_request: + push: + branches: [ "master" ] + +permissions: + contents: write + +concurrency: + group: ci-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + ci: + name: Spotless and check + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v7 + with: + submodules: recursive + # On pull requests check out the branch itself, not the detached merge + # commit, so the formatting commit can be pushed back. + ref: ${{ github.head_ref || github.sha }} + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up JDK 25 + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: "25" + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v6 + + - name: Apply Spotless and push formatting changes + # Only pull request branches from this repository, where the formatting + # commit can be pushed back. Everywhere else the spotlessCheck inside + # the check task must fail on violations instead of hiding them. + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + run: | + ./gradlew spotlessApply + if git diff --quiet; then + echo "Nothing to format." + exit 0 + fi + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add -u + git commit -m "chore(style): spotlessApply" + git push + + - name: Run checks + run: ./gradlew check diff --git a/.github/workflows/spotless.yml b/.github/workflows/spotless.yml deleted file mode 100644 index 65ab00b..0000000 --- a/.github/workflows/spotless.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Spotless - -on: - push: - branches-ignore: - - master - -permissions: - contents: write - -concurrency: - group: spotless-${{ github.ref }} - cancel-in-progress: true - -jobs: - format: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v7 - with: - ref: ${{ github.ref_name }} - token: ${{ secrets.GITHUB_TOKEN }} - - - uses: actions/setup-java@v5 - with: - distribution: temurin - java-version: "25" - - - uses: gradle/actions/setup-gradle@v6 - - - name: Apply Spotless - run: ./gradlew spotlessApply --no-daemon - - - name: Commit formatting changes - run: | - if git diff --quiet; then - echo "Nothing to format." - exit 0 - fi - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git add -u - git commit -m "chore(style): spotlessApply" - git push \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 11f1bac..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Test - -on: - workflow_run: - workflows: [ "Spotless" ] - types: [ completed ] - push: - branches: [ "master" ] - -permissions: - contents: read - -concurrency: - group: test-${{ github.event.workflow_run.head_branch || github.ref }} - cancel-in-progress: true - -jobs: - test: - name: Test - runs-on: ubuntu-latest - if: ${{ github.event_name == 'push' || github.event.workflow_run.conclusion == 'success' }} - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - submodules: recursive - # workflow_run starts from the default branch, so check out the branch Spotless just ran - # on. Its tip, not head_sha, since Spotless pushes its formatting as a new commit. - ref: ${{ github.event.workflow_run.head_branch || github.sha }} - - - name: Set up JDK 25 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '25' - - - name: Set up Gradle - uses: gradle/actions/setup-gradle@v4 - - - name: Run checks - run: ./gradlew check