Skip to content

Instantly share code, notes, and snippets.

@UtkuGlsvn
Created December 27, 2024 20:42
Show Gist options
  • Save UtkuGlsvn/b5438ca5174cdc85e042464a98bbacc6 to your computer and use it in GitHub Desktop.
Save UtkuGlsvn/b5438ca5174cdc85e042464a98bbacc6 to your computer and use it in GitHub Desktop.
name: Deploy to Firebase
on:
push:
branches:
- development
- master
pull_request:
branches:
- feature/*
- bugfix/*
workflow_dispatch:
inputs:
release_notes:
type: string
required: true
default: 'Manual Debug Build'
description: 'Release Notes'
jobs:
build:
name: Build and Deploy to Firebase
runs-on: ubuntu-latest
steps:
# Checkout the code from the repository
- uses: actions/checkout@v3
# Cache Gradle dependencies
- name: Cache Gradle dependencies
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# Set up Java 17
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
# Make gradlew executable
- name: Make gradlew executable
run: chmod +x ./gradlew
# Build the project
- name: Build the project (assembleProdDebug)
run: |
if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
# Master run build
./gradlew assembleProdDebug
elif [[ "${{ github.ref }}" == "refs/heads/development" ]]; then
# Development run build
./gradlew assembleDevelopmentDebug
fi
# List the APK output directory to verify the APK is generated
- name: List build outputs
run: |
if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
# Master run build
ls -alh app/build/outputs/apk/prod/debug/
elif [[ "${{ github.ref }}" == "refs/heads/development" ]]; then
# Development run build
ls -alh app/build/outputs/apk/development/debug/
fi
# Get the commit message for release notes
- name: Use Commit Message
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
echo "The commit message was: '${COMMIT_MESSAGE}'"
# Set APK path and Firebase App ID based on branch or pull request
- name: Set APK path and Firebase App ID
run: |
if [[ "${{ github.event_name }}" == "pull_request" && ( "${{ github.head_ref }}" == feature/* || "${{ github.head_ref }}" == bugfix/* ) ]]; then
echo "APK_PATH=app/build/outputs/apk/development/debug/app-development-debug.apk" >> $GITHUB_ENV
echo "FIREBASE_APP_ID=${{ secrets.FIREBASE_APP_ID_TEST }}" >> $GITHUB_ENV
elif [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
# Master branch condition
echo "APK_PATH=app/build/outputs/apk/prod/debug/app-prod-debug.apk" >> $GITHUB_ENV
echo "FIREBASE_APP_ID=${{ secrets.FIREBASE_APP_ID }}" >> $GITHUB_ENV
elif [[ "${{ github.ref }}" == "refs/heads/development" ]]; then
# Development branch condition
echo "APK_PATH=app/build/outputs/apk/development/debug/app-development-debug.apk" >> $GITHUB_ENV
echo "FIREBASE_APP_ID=${{ secrets.FIREBASE_APP_ID_TEST }}" >> $GITHUB_ENV
fi
# Upload the APK to Firebase App Distribution
- name: Upload APK to Firebase App Distribution
uses: wzieba/Firebase-Distribution-Github-Action@v1
with:
appId: ${{ env.FIREBASE_APP_ID }}
serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }}
groups: testers
file: ${{ env.APK_PATH }}
releaseNotes: ${{ env.COMMIT_MESSAGE }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment