Skip to content

Update android-workflow.yaml #499

Update android-workflow.yaml

Update android-workflow.yaml #499

name: CI Workflow
# Run this workflow every time a new commit pushed to your repository
on: push
jobs:
unit-tests:
name: Run Unit Tests
runs-on: macos-latest
steps:
# Checks out a copy of your repository on the ubuntu-latest machine
- name: Checkout code
uses: actions/checkout@v2
# Set up Java JDK
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# Get the secrets from GitHub and add them to local.properties
# https://blog.jakelee.co.uk/accessing-android-app-secret-from-github-actions-using-gradle/
- name: Access PLATFORM_CLIENT_ID
env:
PLATFORM_CLIENT_ID: ${{ secrets.PLATFORM_CLIENT_ID }}
run: echo PLATFORM_CLIENT_ID=\"$PLATFORM_CLIENT_ID\" >> ./local.properties
- name: Access PLATFORM_REDIRECT_URI
env:
PLATFORM_REDIRECT_URI: ${{ secrets.PLATFORM_REDIRECT_URI }}
run: echo PLATFORM_REDIRECT_URI=\"$PLATFORM_REDIRECT_URI\" >> ./local.properties
# Create google-services.json
- name: Create google-services.json
run: |
cat << EOF > PennMobile/google-services.json
${{ secrets.GOOGLE_SERVICES_JSON }}
EOF
# Run unit tests
- name: Run Unit Tests
run: ./gradlew testDebugUnitTest
# If tests pass, generate and upload APK
generate-apk:
name: Generate apk
runs-on: ubuntu-latest
needs: unit-tests
# Generate APK only if we are pushing to master or pushing a new release tag
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# Get the secrets from GitHub and add them to local.properties
- name: Access PLATFORM_CLIENT_ID
env:
PLATFORM_CLIENT_ID: ${{ secrets.PLATFORM_CLIENT_ID }}
run: echo PLATFORM_CLIENT_ID=\"$PLATFORM_CLIENT_ID\" >> ./local.properties
- name: Access PLATFORM_REDIRECT_URI
env:
PLATFORM_REDIRECT_URI: ${{ secrets.PLATFORM_REDIRECT_URI }}
run: echo PLATFORM_REDIRECT_URI=\"$PLATFORM_REDIRECT_URI\" >> ./local.properties
# Create google-services.json
- name: Create google-services.json
run: |
cat << EOF > PennMobile/google-services.json
${{ secrets.GOOGLE_SERVICES_JSON }}
EOF
# Generate Signed APK
- name: Generate Release APK
run: ./gradlew assembleRelease
- name: Setup build tool version variable
shell: bash
run: |
BUILD_TOOL_VERSION=$(ls /usr/local/lib/android/sdk/build-tools/ | tail -n 1)
echo "BUILD_TOOL_VERSION=$BUILD_TOOL_VERSION" >> $GITHUB_ENV
echo Last build tool version is: $BUILD_TOOL_VERSION
- name: Sign app APK
uses: r0adkll/sign-android-release@v1
# ID used to access action output
id: sign_app
with:
releaseDirectory: PennMobile/build/outputs/apk/release
signingKeyBase64: ${{ secrets.SIGNING_KEY }}
alias: ${{ secrets.ALIAS }}
keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
keyPassword: ${{ secrets.KEY_PASSWORD }}
env:
BUILD_TOOLS_VERSION: ${{ env.BUILD_TOOL_VERSION }}
# Upload signed APK
- uses: actions/upload-artifact@v4
with:
name: release.apk
path: ${{steps.sign_app.outputs.signedReleaseFile}}
code-cov:
name: JaCoCo Code Coverage
# Set the type of machine to run on, macOS is better for running Android emulators
runs-on: macos-latest
needs: unit-tests
steps:
- name: Checkout code
uses: actions/checkout@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# Get the secrets from GitHub and add them to local.properties
- name: Access PLATFORM_CLIENT_ID
env:
PLATFORM_CLIENT_ID: ${{ secrets.PLATFORM_CLIENT_ID }}
run: echo PLATFORM_CLIENT_ID=\"$PLATFORM_CLIENT_ID\" >> ./local.properties
- name: Access PLATFORM_REDIRECT_URI
env:
PLATFORM_REDIRECT_URI: ${{ secrets.PLATFORM_REDIRECT_URI }}
run: echo PLATFORM_REDIRECT_URI=\"$PLATFORM_REDIRECT_URI\" >> ./local.properties
# Create google-services.json
- name: Create google-services.json
run: |
cat << EOF > PennMobile/google-services.json
${{ secrets.GOOGLE_SERVICES_JSON }}
EOF
# Run JaCoCo, generate Test Report
- name: Check Code Coverage
run: ./gradlew jacocoTestReport --stacktrace
# Upload reports to GitHub Actions
- name: Upload Reports
uses: actions/upload-artifact@v4
with:
name: reports
path: PennMobile/build/reports
# Publish to Firebase App Distribution
# https://github.com/wzieba/Firebase-Distribution-Github-Action
deploy-firebase:
needs: generate-apk
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: release.apk
- name: Upload APK to Firebase App Distribution
uses: wzieba/Firebase-Distribution-Github-Action@v1
with:
appId: ${{secrets.FIREBASE_APP_ID}}
serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }}
groups: tester
file: PennMobile-release-unsigned-signed.apk
# Publish to Play Store test track
deploy-play-store:
needs: generate-apk
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: release.apk
- name: Publish to Play Store internal test track
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }}
packageName: com.pennapps.labs.pennmobile
releaseFiles: PennMobile-release-unsigned-signed.apk
track: internal
status: completed
# userFraction: 0.50