From 6c865b5eabc4f13e71357c7a07166f587a9bca48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ullrich=20Sch=C3=A4fer?= Date: Fri, 11 Oct 2024 12:49:05 +0200 Subject: [PATCH] Merging jobs into one to reuse gradle build results --- .github/workflows/changeset.yml | 4 ++ .github/workflows/gradle.yml | 68 +++++++++++++-------------------- 2 files changed, 30 insertions(+), 42 deletions(-) diff --git a/.github/workflows/changeset.yml b/.github/workflows/changeset.yml index 66b1860..4c7b561 100644 --- a/.github/workflows/changeset.yml +++ b/.github/workflows/changeset.yml @@ -22,16 +22,20 @@ jobs: published: ${{ steps.changesets.outputs.published }} steps: - uses: actions/checkout@v4 + if: github.ref == 'refs/heads/main' with: token: ${{ secrets.BELLA_ACTION_TOKEN }} - name: Setup node + if: github.ref == 'refs/heads/main' uses: actions/setup-node@v4 with: node-version: 20 - uses: bahmutov/npm-install@v1 + if: github.ref == 'refs/heads/main' - name: Create release PR or publish release + if: github.ref == 'refs/heads/main' id: changesets uses: changesets/action@v1 with: diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index a9b9fc8..c71c0fe 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -2,21 +2,28 @@ name: Gradle Build, Tests and Publish on: push: - branches: [ "main" ] + branches: [ "main", "ullrich/publish-via-ci" ] pull_request: jobs: build: runs-on: ubuntu-latest + + permissions: + checks: write + pull-requests: write + contents: write + + needs: changeset-on-main + steps: + # Setup - 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@v4 @@ -25,19 +32,13 @@ jobs: DATA: ${{ secrets.GOOGLE_SERVICES }} run: echo $DATA | base64 -di > ./example/google-services.json + # Build - name: Build with Gradle Wrapper run: ./gradlew build -xlint - test: - runs-on: ubuntu-latest - permissions: - checks: write - pull-requests: write - needs: build - steps: + # Test - name: Test with Gradle Wrapper run: ./gradlew test - - name: Publish Test Report uses: mikepenz/action-junit-report@v4 if: success() || failure() # always run even if the previous step fails @@ -46,10 +47,7 @@ jobs: token: ${{ secrets.BELLA_ACTION_TOKEN }} comment: true - lint: - runs-on: ubuntu-latest - needs: build - steps: + # Lint - name: Lint with Gradle Wrapper run: ./gradlew lint - name: Publish Lint Report @@ -60,26 +58,14 @@ jobs: ignore-warnings: false continue-on-error: false # If annotations contain error of severity, action-android-lint exit 1. - - ## -- Release Jobs - - ## The release depends on the Changesets workflow. Only if changesets published a release, - ## we also run the jobs to push the resulting artifacts to Maven - - changeset-on-main: - if: github.ref == 'refs/heads/main' - uses: ./.github/workflows/changeset.yml - secrets: - BELLA_ACTION_TOKEN: ${{ secrets.BELLA_ACTION_TOKEN }} - - publish: - runs-on: ubuntu-latest - needs: [ changeset-on-main, build, test, lint ] - if: ${{ needs.changeset-on-main.outputs.published == 'true'}} - steps: + # Publish + ## Publishing depends on the Changesets workflow. Only if changesets published a release, + ## we also run the jobs to push the resulting artifacts to Maven - name: Publish to Maven Local + if: ${{ needs.changeset-on-main.outputs.published == 'true'}} run: ./gradlew -xtest -xlint assemble publishToMavenLocal - name: Setup Keyring + if: ${{ needs.changeset-on-main.outputs.published == 'true'}} id: keyring env: KEYRING_FILE: "~/publish-keyring.gpg" @@ -88,6 +74,7 @@ jobs: echo $DATA | base64 -di > "$KEYRING_FILE" echo "keyringFile=$KEYRING_FILE" >> "$GITHUB_OUTPUT" - name: Publish to Maven + if: ${{ needs.changeset-on-main.outputs.published == 'true'}} run: | ./gradlew -xtest -xlint assemble publish \ -Psigning.keyId=${{ secrets.SIGNING_KEYID }} \ @@ -96,17 +83,14 @@ jobs: -PNEXUS_USERNAME=${{ secrets.NEXUS_USERNAME }} \ -PNEXUS_PASSWORD=${{ secrets.NEXUS_PASSWORD }} - dependency-submission: - runs-on: ubuntu-latest - permissions: - contents: write - - needs: publish - - steps: # 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 + if: ${{ needs.changeset-on-main.outputs.published == 'true'}} uses: gradle/actions/dependency-submission@v4 - with: - cache-read-only: true + + ## -- Release Jobs + changeset-on-main: + uses: ./.github/workflows/changeset.yml + secrets: + BELLA_ACTION_TOKEN: ${{ secrets.BELLA_ACTION_TOKEN }}