Skip to content

Commit 848de26

Browse files
authored
Merge pull request #3 from niyajali/update-action
refactor: Streamline iOS Firebase App Distribution workflow
2 parents bd16190 + ae2a74f commit 848de26

File tree

2 files changed

+122
-156
lines changed

2 files changed

+122
-156
lines changed

README.md

Lines changed: 111 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,135 @@
1-
# KMP Build & Publish iOS App on Firebase
1+
# KMP Publish iOS App on Firebase Action
22

3-
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.
3+
This GitHub Action automates the process of building and publishing iOS applications to Firebase App Distribution. It handles the build process, signing, and deployment using Fastlane.
44

55
## Features
66

7-
- Automated iOS app building
8-
- Version number generation
9-
- Automated release notes generation
10-
- Firebase App Distribution integration
11-
- Gradle and Konan caching
12-
- Java development environment setup
13-
- Fastlane integration
7+
- Automated Firebase App Distribution deployment
8+
- iOS IPA build and signing
9+
- Build artifact archiving
10+
- Gradle and Ruby dependency caching
11+
- Firebase tester group management
1412

1513
## Prerequisites
1614

17-
- iOS project with Xcode configuration
18-
- Firebase project setup
19-
- GitHub repository with release history
20-
- Fastlane setup in the repository
21-
- Valid iOS certificates and provisioning profiles
15+
Before using this action, ensure you have:
2216

23-
## Inputs
17+
1. A Firebase project with App Distribution enabled
18+
2. Firebase service account credentials
19+
3. An iOS app set up in Firebase
20+
4. Xcode project configured with proper signing
21+
22+
## Setup
23+
24+
### Fastlane Setup
25+
26+
Create a `Gemfile` in your project root:
27+
28+
```ruby
29+
source "https://rubygems.org"
30+
31+
gem "fastlane"
32+
gem "firebase_app_distribution"
33+
```
2434

25-
| Input | Description | Required |
26-
|--------------------|-------------------------------------------|----------|
27-
| `ios_package_name` | Name of the iOS project module | Yes |
28-
| `firebase_creds` | Firebase service account credentials JSON | Yes |
29-
| `github_token` | GitHub token for API access | Yes |
30-
| `target_branch` | Target branch for deployment | Yes |
35+
Create a `fastlane/Fastfile` with the following content:
36+
37+
```ruby
38+
default_platform(:ios)
39+
40+
platform :ios do
41+
desc "Deploy to Firebase App Distribution"
42+
lane :deploy_on_firebase do |options|
43+
build_ios_app(
44+
scheme: ENV["IOS_PACKAGE_NAME"],
45+
export_method: "ad-hoc"
46+
)
47+
48+
firebase_app_distribution(
49+
app: ENV["FIREBASE_APP_ID"],
50+
groups: options[:groups],
51+
service_credentials_file: options[:serviceCredsFile],
52+
release_notes: "New build from GitHub Actions"
53+
)
54+
end
55+
end
56+
```
3157

3258
## Usage
3359

60+
Add the following workflow to your GitHub Actions:
61+
3462
```yaml
35-
name: KMP iOS deploy to Firebase
63+
name: Deploy to Firebase
3664

3765
on:
38-
workflow_dispatch:
39-
inputs:
40-
ios_package_name:
41-
description: 'Name of the iOS project module'
42-
required: true
43-
default: 'mifospay-ios'
44-
45-
46-
permissions:
47-
contents: write
66+
push:
67+
branches: [ main ]
68+
# Or trigger on release
69+
release:
70+
types: [created]
4871

4972
jobs:
50-
deploy_ios_app:
51-
name: Deploy iOS App
73+
deploy:
5274
runs-on: macos-latest
5375
steps:
54-
- name: Checkout Repository
55-
uses: actions/checkout@v4
56-
with:
57-
fetch-depth: 0
58-
59-
- name: Deploy iOS App to Firebase
76+
- uses: actions/checkout@v3
77+
78+
- name: Deploy to Firebase
6079
uses: openMF/[email protected]
6180
with:
62-
ios_package_name: ${{ inputs.ios_package_name }}
63-
github_token: ${{ secrets.GITHUB_TOKEN }}
64-
firebase_creds: ${{ secrets.FIREBASECREDS }}
65-
target_branch: 'dev'
81+
ios_package_name: 'YourAppName'
82+
firebase_creds: ${{ secrets.FIREBASE_CREDS }}
83+
tester_groups: 'qa-team,beta-testers'
84+
```
6685
86+
## Inputs
87+
88+
| Input | Description | Required |
89+
|--------------------|-----------------------------------------------------|----------|
90+
| `ios_package_name` | Name of your iOS app/scheme | Yes |
91+
| `firebase_creds` | Base64 encoded Firebase service account credentials | Yes |
92+
| `tester_groups` | Comma-separated list of Firebase tester groups | Yes |
93+
94+
## Setting up Secrets
95+
96+
1. Encode your Firebase credentials file to base64:
97+
```bash
98+
base64 -i path/to/firebase-credentials.json -o firebase-creds.txt
6799
```
68100

69-
## Workflow Details
70-
71-
1. **Environment Setup**
72-
- Configures Java 17 (Zulu distribution)
73-
- Sets up Gradle with caching
74-
- Configures Ruby and Fastlane
75-
- Sets up dependency caching for Gradle, Konan, and build outputs
76-
77-
2. **Version Management**
78-
- Generates version codes based on commits and tags
79-
- Reads version name from version.txt
80-
- Formula: `version-code = (commits + tags) << 1`
81-
82-
3. **Release Notes Generation**
83-
- Fetches latest release tag
84-
- Generates release notes using GitHub API
85-
- Creates two changelog files:
86-
- `changelogGithub`: Comprehensive release notes
87-
- `changelogBeta`: Changes since last commit
88-
89-
4. **Build Process**
90-
- Configures Firebase credentials
91-
- Builds iOS application using Fastlane
92-
- Generates IPA file
93-
94-
5. **Distribution**
95-
- Uploads build artifacts with high compression
96-
- Distributes to Firebase App Distribution
97-
98-
## Dependencies
99-
100-
- Java 17 (Zulu distribution)
101-
- Gradle
102-
- Ruby
103-
- Bundler 2.2.27
104-
- Fastlane plugins:
105-
- firebase_app_distribution
106-
- increment_build_number
101+
2. Add the following secret to your GitHub repository:
102+
- `FIREBASE_CREDS`: Content of firebase-creds.txt
103+
104+
## Build Artifacts
105+
106+
The action uploads the built IPA file as an artifact with:
107+
- Name: 'ios-app'
108+
- Retention period: 1 day
109+
- Maximum compression (level 9)
110+
111+
You can find the IPA file in your GitHub Actions run artifacts.
112+
113+
This helps reduce build times in subsequent runs.
114+
115+
## Firebase App Setup
116+
117+
1. Go to the Firebase Console
118+
2. Navigate to App Distribution
119+
3. Create a new iOS app or select an existing one
120+
4. Set up tester groups under App Distribution
121+
5. Create a service account with appropriate permissions
122+
6. Download the service account JSON key file
123+
124+
## Troubleshooting
125+
126+
Common issues and solutions:
127+
128+
1. Build fails due to signing
129+
- Ensure your Xcode project has proper signing configuration
130+
- Verify the export method matches your provisioning profile
131+
132+
2. Firebase deployment fails
133+
- Check if the service account has sufficient permissions
134+
- Verify the Firebase app ID is correct
135+
- Ensure tester groups exist in Firebase console

action.yaml

Lines changed: 11 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,13 @@ inputs:
1212
firebase_creds:
1313
description: 'Firebase credentials'
1414
required: true
15-
github_token:
16-
description: 'GitHub token'
17-
required: true
18-
target_branch:
19-
description: 'Target branch for deployment'
15+
tester_groups:
16+
description: 'Firebase Tester Group'
2017
required: true
2118

2219
runs:
2320
using: composite
2421
steps:
25-
- name: Set up Java development environment
26-
uses: actions/[email protected]
27-
with:
28-
distribution: 'zulu' # Use Zulu distribution of OpenJDK
29-
java-version: '17' # Use Java 17 version
30-
31-
- name: Setup Gradle
32-
uses: gradle/actions/setup-gradle@v4
33-
3422
# Cache Gradle dependencies to speed up builds
3523
- uses: actions/cache@v3
3624
with:
@@ -54,70 +42,23 @@ runs:
5442
bundle exec fastlane add_plugin firebase_app_distribution
5543
bundle exec fastlane add_plugin increment_build_number
5644
57-
# Generate version number
58-
- name: Generate Release Number
59-
id: rel_number
60-
shell: bash
61-
run: |
62-
./gradlew versionFile
63-
COMMITS=`git rev-list --count HEAD`
64-
TAGS=`git tag | grep -v beta | wc -l`
65-
VC=$(((COMMITS+TAGS) << 1))
66-
echo "version-code=$VC" >> $GITHUB_OUTPUT
67-
VERSION=`cat version.txt`
68-
echo "version=$VERSION" >> $GITHUB_OUTPUT
69-
70-
- name: Generate Release Notes
71-
uses: actions/github-script@v7
72-
id: release-notes
73-
with:
74-
github-token: ${{ inputs.github_token }}
75-
script: |
76-
try {
77-
// Get latest release tag
78-
const latestRelease = await github.rest.repos.getLatestRelease({
79-
owner: context.repo.owner,
80-
repo: context.repo.repo,
81-
});
82-
const previousTag = latestRelease.data.tag_name;
83-
84-
// Generate release notes
85-
const params = {
86-
owner: context.repo.owner,
87-
repo: context.repo.repo,
88-
tag_name: '${{ steps.rel_number.outputs.version }}',
89-
target_commitish: '${{ inputs.target_branch }}'
90-
};
91-
92-
const { data } = await github.rest.repos.generateReleaseNotes(params);
93-
const changelog = data.body.replaceAll('`', '\'').replaceAll('"', '\'');
94-
95-
// Write changelog files
96-
const fs = require('fs');
97-
fs.writeFileSync('${{ inputs.ios_package_name }}/changelogGithub', changelog);
98-
99-
// Generate beta changelog
100-
const { execSync } = require('child_process');
101-
execSync('git log --format="* %s" HEAD^..HEAD > ${{ inputs.ios_package_name }}/changelogBeta');
102-
103-
return changelog;
104-
} catch (error) {
105-
console.error('Error generating release notes:', error);
106-
return '';
107-
}
108-
10945
- name: Inflate Secrets
11046
shell: bash
11147
env:
48+
GOOGLE_SERVICES: ${{ inputs.google_services }}
11249
FIREBASE_CREDS: ${{ inputs.firebase_creds }}
11350
run: |
51+
mkdir -p secrets
52+
11453
# Inflate Firebase credentials
115-
touch ${{ inputs.ios_package_name }}/firebaseAppDistributionServiceCredentialsFile.json
116-
echo $FIREBASE_CREDS > ${{ inputs.ios_package_name }}/firebaseAppDistributionServiceCredentialsFile.json
54+
touch secrets/firebaseAppDistributionServiceCredentialsFile.json
55+
echo $FIREBASE_CREDS | base64 --decode > secrets/firebaseAppDistributionServiceCredentialsFile.json
11756
118-
- name: Build iOS App
57+
- name: Upload iOS App to Firebase Distribution
11958
shell: bash
120-
run: bundle exec fastlane ios build_ios
59+
run: bundle exec fastlane ios deploy_on_firebase \
60+
serviceCredsFile:secrets/firebaseAppDistributionServiceCredentialsFile.json \
61+
groups:${{ inputs.tester_groups }}
12162

12263
- name: Upload iOS Artifact
12364
uses: actions/upload-artifact@v4
@@ -126,7 +67,3 @@ runs:
12667
retention-days: 1
12768
compression-level: 9
12869
path: '**/*.ipa'
129-
130-
- name: Upload iOS App to Firebase Distribution
131-
shell: bash
132-
run: bundle exec fastlane ios deploy_on_firebase

0 commit comments

Comments
 (0)