Skip to content

Commit

Permalink
Split the build-and-test GitHub action into separate jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
sdlaver committed Oct 25, 2024
1 parent c178b79 commit d270093
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 64 deletions.
163 changes: 101 additions & 62 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,87 @@ env:
AVD_ANDROID_TARGET: 'google_atd'

jobs:
build-and-test:
build:
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 15

steps:
##########################################################################
# Setup
##########################################################################
- uses: actions/checkout@v4

- uses: solana-mobile/gha-free-disk-space-for-android-build-and-test@v1
- name: set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- uses: actions/checkout@v4
- name: Setup Gradle w/ cache
uses: gradle/actions/setup-gradle@v4

- name: Build with Gradle
run: ./gradlew build assembleAndroidTest

# Upload build intermediates to workflow artifacts
- uses: actions/upload-artifact@v4
with:
name: build-intermediates
path: |
**/.gradle
**/build
include-hidden-files: true # needed for files within dot directories
if-no-files-found: error
retention-days: 1

# Upload libraries to workflow artifacts
- uses: actions/upload-artifact@v4
if: ${{ github.event_name != 'pull_request' }}
with:
name: libraries
path: seedvault/build/outputs/aar/*.aar
if-no-files-found: error
retention-days: 5

# Upload javadoc to workflow artifacts
- uses: actions/upload-artifact@v4
if: ${{ github.event_name != 'pull_request' }}
with:
name: seedvault-javadoc
path: |
seedvault/build/docs/*
!seedvault/build/docs/**/*.zip
if-no-files-found: error
retention-days: 1


test:
runs-on: ubuntu-latest
needs: build
timeout-minutes: 15

steps:
- uses: solana-mobile/gha-free-disk-space-for-android-build-and-test@v1

- name: Enable KVM for Android Virtual Device acceleration
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: build-intermediates

- name: set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Gradle cache
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-disabled: true # no caching - all useful intermediates copied from build job

- name: AVD cache
uses: actions/cache@v4
Expand All @@ -67,41 +121,6 @@ jobs:
disable-animations: false
script: echo "Generated AVD snapshot for caching."

##########################################################################
# Build
##########################################################################

- name: Build with Gradle
run: ./gradlew build assembleAndroidTest

##########################################################################
# Upload build artifacts
##########################################################################

# Upload libraries to workflow artifacts
- uses: actions/upload-artifact@v4
if: ${{ github.event_name != 'pull_request' }}
with:
name: libraries
path: seedvault/build/outputs/aar/*.aar
if-no-files-found: error
retention-days: 5

# Upload javadoc to workflow artifacts
- uses: actions/upload-artifact@v4
if: ${{ github.event_name != 'pull_request' }}
with:
name: seedvault-javadoc
path: |
seedvault/build/docs/*
!seedvault/build/docs/**/*.zip
if-no-files-found: error
retention-days: 1

##########################################################################
# Test
##########################################################################

- name: run CTS test automation
uses: reactivecircus/android-emulator-runner@v2
with:
Expand All @@ -120,10 +139,8 @@ jobs:
./gradlew :SeedVaultSimulator:installDebug
./gradlew :cts:connectedGenericDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.solanamobile.seedvault.cts.SeedVaultSimulatorSetup
./gradlew :cts:connectedGenericDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.solanamobile.seedvault.cts.RunCtsTestsOnSimulator
##########################################################################
# Upload test artifacts
##########################################################################
./gradlew :cts:connectedPrivilegedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.solanamobile.seedvault.cts.SeedVaultSimulatorSetup
./gradlew :cts:connectedPrivilegedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.solanamobile.seedvault.cts.RunCtsTestsOnSimulator
# Upload test results to workflow artifacts
- uses: actions/upload-artifact@v4
Expand All @@ -134,26 +151,14 @@ jobs:
if-no-files-found: error
retention-days: 5

##########################################################################
# Publish to Maven Central
##########################################################################

- name: Publish to Maven Central (release only)
if: ${{ github.event_name == 'release' && startsWith(github.event.release.tag_name, 'v') }} # (only for releases that start with 'v')
env:
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.MAVEN_CENTRAL_PUBLISHING_PRIVATE_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.MAVEN_CENTRAL_PUBLISHING_PRIVATE_KEY_PASSWORD }}
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.MAVEN_CENTRAL_PUBLISHING_USERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.MAVEN_CENTRAL_PUBLISHING_PASSWORD }}
TAG: ${{ github.event.release.tag_name }}
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -P version=${TAG:1} --no-configuration-cache

# Note: only runs on 'push' events for main
publish-to-gh-pages:
runs-on: ubuntu-latest
needs: build-and-test
needs: test # run only after tests pass
concurrency: publish-to-gh-pages
if: ${{ github.event_name == 'push' && github.event.push.base_ref == 'main' }}

steps:
- name: Update seedvault javadoc
uses: solana-mobile/gha-commit-artifact-to-branch@v2
Expand All @@ -165,10 +170,44 @@ jobs:
commit-message: 'Update seedvault javadoc'


# Note: only runs on 'release' events
publish-to-maven:
runs-on: ubuntu-latest
needs: test # run only after tests pass
if: ${{ github.event_name == 'release' && startsWith(github.event.release.tag_name, 'v') }} # (only for releases that start with 'v')

steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: build-intermediates

- 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
with:
cache-disabled: true # no caching - all useful intermediates copied from build job

- name: Publish to Maven Central (release only)
env:
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.MAVEN_CENTRAL_PUBLISHING_PRIVATE_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.MAVEN_CENTRAL_PUBLISHING_PRIVATE_KEY_PASSWORD }}
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.MAVEN_CENTRAL_PUBLISHING_USERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.MAVEN_CENTRAL_PUBLISHING_PASSWORD }}
TAG: ${{ github.event.release.tag_name }}
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -P version=${TAG:1} --no-configuration-cache


# Note: only runs on 'release' events
upload-to-release:
runs-on: ubuntu-latest
needs: build-and-test
needs: test # run only after tests pass
permissions:
contents: write # needed for uploading files to releases
if: ${{ github.event_name == 'release' }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/react-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: React-Native CI
on:
push:
branches: [ main, next ]
paths: [ 'fakewalletreact/**', 'js/**' ]
paths: [ '.github/**', 'fakewalletreact/**', 'js/**' ]
pull_request:
branches: [ main, next ]
paths: [ 'fakewalletreact/**', 'js/**' ]
paths: [ '.github/**', 'fakewalletreact/**', 'js/**' ]
release:
types: [ published ]

Expand Down

0 comments on commit d270093

Please sign in to comment.