Skip to content

Commit

Permalink
Merging jobs into one to reuse gradle build results
Browse files Browse the repository at this point in the history
  • Loading branch information
stigi committed Oct 11, 2024
1 parent e8dc47d commit 6c865b5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 42 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/changeset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
68 changes: 26 additions & 42 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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 }} \
Expand All @@ -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 }}

0 comments on commit 6c865b5

Please sign in to comment.