s #648
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 --warning-mode all --stacktrace | |
# 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 | |
ktlint-check: | |
name: Check Kotlin Code Style | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Install ktlint | |
run: | | |
curl -sSLO https://github.com/pinterest/ktlint/releases/download/1.2.1/ktlint | |
chmod a+x ktlint | |
sudo mv ktlint /usr/local/bin/ | |
- name: Run ktlint | |
run: | | |
set -o pipefail | |
ktlint --reporter=plain > ktlint_errors.txt | |
- name: Check for ktlint errors | |
if: ${{ failure() || steps.run_ktlint.exitCode == 1 }} | |
run: cat ktlint_errors.txt | |
# 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 |