Skip to content

Commit

Permalink
Merge pull request #1 from niyajali/create-action
Browse files Browse the repository at this point in the history
feat: Added iOS app build and publish to Firebase Action
  • Loading branch information
niyajali authored Dec 14, 2024
2 parents fef41ce + aafac8d commit bd16190
Show file tree
Hide file tree
Showing 3 changed files with 363 additions and 1 deletion.
125 changes: 125 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
### AndroidStudio template
# Covers files to be ignored for android development using Android Studio.

# Built application files
*.apk
*.ap_
*.aab

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle
.gradle/
build/

# Signing files
.signing/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio
/*/build/
/*/local.properties
/*/out
/*/*/build
/*/*/production
captures/
.navigation/
*.ipr
*~
*.swp

# Keystore files
*.jks
*.keystore

# Google Services (e.g. APIs or Firebase)
# google-services.json

# Android Patch
gen-external-apklibs

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# NDK
obj/

# IntelliJ IDEA
*.iml
*.iws
/out/

# User-specific configurations
.idea/

# Legacy Eclipse project files
.classpath
.project
.cproject
.settings/

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.war
*.ear

# virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml)
hs_err_pid*

## Plugin-specific files:

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Mongo Explorer plugin
.idea/mongoSettings.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### Kotlin template
# Compiled class file

# Log file

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)

# Package Files #
*.jar
*.nar
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
replay_pid*

107 changes: 106 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,106 @@
# KMP-Publish-Ios-on-Firebase
# KMP Build & Publish iOS App on Firebase

This GitHub Action automates the process of building an iOS application, generating release notes, and distributing the build to Firebase App Distribution. It includes version management and comprehensive caching for optimized build times.

## Features

- Automated iOS app building
- Version number generation
- Automated release notes generation
- Firebase App Distribution integration
- Gradle and Konan caching
- Java development environment setup
- Fastlane integration

## Prerequisites

- iOS project with Xcode configuration
- Firebase project setup
- GitHub repository with release history
- Fastlane setup in the repository
- Valid iOS certificates and provisioning profiles

## Inputs

| Input | Description | Required |
|--------------------|-------------------------------------------|----------|
| `ios_package_name` | Name of the iOS project module | Yes |
| `firebase_creds` | Firebase service account credentials JSON | Yes |
| `github_token` | GitHub token for API access | Yes |
| `target_branch` | Target branch for deployment | Yes |

## Usage

```yaml
name: KMP iOS deploy to Firebase

on:
workflow_dispatch:
inputs:
ios_package_name:
description: 'Name of the iOS project module'
required: true
default: 'mifospay-ios'


permissions:
contents: write

jobs:
deploy_ios_app:
name: Deploy iOS App
runs-on: macos-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Deploy iOS App to Firebase
uses: openMF/kmp-publish-ios-on-firebase-action@v1.0.0
with:
ios_package_name: ${{ inputs.ios_package_name }}
github_token: ${{ secrets.GITHUB_TOKEN }}
firebase_creds: ${{ secrets.FIREBASECREDS }}
target_branch: 'dev'

```

## Workflow Details

1. **Environment Setup**
- Configures Java 17 (Zulu distribution)
- Sets up Gradle with caching
- Configures Ruby and Fastlane
- Sets up dependency caching for Gradle, Konan, and build outputs

2. **Version Management**
- Generates version codes based on commits and tags
- Reads version name from version.txt
- Formula: `version-code = (commits + tags) << 1`

3. **Release Notes Generation**
- Fetches latest release tag
- Generates release notes using GitHub API
- Creates two changelog files:
- `changelogGithub`: Comprehensive release notes
- `changelogBeta`: Changes since last commit

4. **Build Process**
- Configures Firebase credentials
- Builds iOS application using Fastlane
- Generates IPA file

5. **Distribution**
- Uploads build artifacts with high compression
- Distributes to Firebase App Distribution

## Dependencies

- Java 17 (Zulu distribution)
- Gradle
- Ruby
- Bundler 2.2.27
- Fastlane plugins:
- firebase_app_distribution
- increment_build_number
132 changes: 132 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: 'KMP Publish iOS App on Firebase'
description: 'Build and publish iOS application on Firebase'
author: 'Mifos Initiative'
branding:
icon: 'package'
color: 'blue'

inputs:
ios_package_name:
description: 'Name of the Android project module'
required: true
firebase_creds:
description: 'Firebase credentials'
required: true
github_token:
description: 'GitHub token'
required: true
target_branch:
description: 'Target branch for deployment'
required: true

runs:
using: composite
steps:
- name: Set up Java development environment
uses: actions/setup-java@v4.2.2
with:
distribution: 'zulu' # Use Zulu distribution of OpenJDK
java-version: '17' # Use Java 17 version

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

# Cache Gradle dependencies to speed up builds
- uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
~/.konan
build
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}

- name: Configure Ruby
uses: ruby/setup-ruby@a2bbe5b1b236842c1cb7dd11e8e3b51e0a616acc # v1.202.0
with:
bundler-cache: true

- name: Install Fastlane
shell: bash
run: |
gem install bundler:2.2.27
bundle install --jobs 4 --retry 3
bundle exec fastlane add_plugin firebase_app_distribution
bundle exec fastlane add_plugin increment_build_number
# Generate version number
- name: Generate Release Number
id: rel_number
shell: bash
run: |
./gradlew versionFile
COMMITS=`git rev-list --count HEAD`
TAGS=`git tag | grep -v beta | wc -l`
VC=$(((COMMITS+TAGS) << 1))
echo "version-code=$VC" >> $GITHUB_OUTPUT
VERSION=`cat version.txt`
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Generate Release Notes
uses: actions/github-script@v7
id: release-notes
with:
github-token: ${{ inputs.github_token }}
script: |
try {
// Get latest release tag
const latestRelease = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo,
});
const previousTag = latestRelease.data.tag_name;
// Generate release notes
const params = {
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: '${{ steps.rel_number.outputs.version }}',
target_commitish: '${{ inputs.target_branch }}'
};
const { data } = await github.rest.repos.generateReleaseNotes(params);
const changelog = data.body.replaceAll('`', '\'').replaceAll('"', '\'');
// Write changelog files
const fs = require('fs');
fs.writeFileSync('${{ inputs.ios_package_name }}/changelogGithub', changelog);
// Generate beta changelog
const { execSync } = require('child_process');
execSync('git log --format="* %s" HEAD^..HEAD > ${{ inputs.ios_package_name }}/changelogBeta');
return changelog;
} catch (error) {
console.error('Error generating release notes:', error);
return '';
}
- name: Inflate Secrets
shell: bash
env:
FIREBASE_CREDS: ${{ inputs.firebase_creds }}
run: |
# Inflate Firebase credentials
touch ${{ inputs.ios_package_name }}/firebaseAppDistributionServiceCredentialsFile.json
echo $FIREBASE_CREDS > ${{ inputs.ios_package_name }}/firebaseAppDistributionServiceCredentialsFile.json
- name: Build iOS App
shell: bash
run: bundle exec fastlane ios build_ios

- name: Upload iOS Artifact
uses: actions/upload-artifact@v4
with:
name: ios-app
retention-days: 1
compression-level: 9
path: '**/*.ipa'

- name: Upload iOS App to Firebase Distribution
shell: bash
run: bundle exec fastlane ios deploy_on_firebase

0 comments on commit bd16190

Please sign in to comment.