Skip to content

Commit

Permalink
Add input for custom command in firebase emulators:exec (#81)
Browse files Browse the repository at this point in the history
# Add option to run custom command right before fastlane in emulator
execution.

## ♻️ Current situation & Problem
In the ENGAGE-HF project, when we seed the emulator using the `npm run
serve:seeded` command, the following command executes under the hood:
`firebase emulators:exec --only auth,firestore,functions,storage --ui
"npm run serve:seed && read -rd \"\""`. This spins up an emulator
instance for the duration of the execution of the `"npm run serve:seed
&& read -rd \"\""` calls. `npm run serve:seed` executes the required
functions to seed the emulator, and the `read -rd \"\"` then causes the
emulator to continue running until the user cancels the operation.

However, when integrating the seeding functionality into the CI for
ENGAGE, we need to be able to have a seeded instance of the emulator for
the duration of the fastlane testing call. The `read -rd \"\"` won't
work for the self-hosted runner, as there is no way to cancel the
emulator without canceling the workflow. Instead, we can introduce an
input to the build-and-test workflow that allows us to pass a custom
command to execute right before the `fastlane test` call. This custom
command will then stay in effect throughout the lifespan of the
emulator, which will shut down after the fastlane process finishes.


## ⚙️ Release Notes 
- Added an input for the custom command called
`customfirebaseemulatorcommand`
- Modified the execution of the fastlane command for the case where the
`fastlanelane` argument is not empty, the `setupfirebaseemulator`
argument is true, and the `firebaseemulatorimport` is empty.


Currently, the workflow executes the following command to run the
fastlane tests if there is no firebase import provided:
```shell
firebase emulators:exec 'fastlane ${{ inputs.fastlanelane }}'
``` 

Instead, we replace this with the following:
```shell
if [ -n "${{ inputs.customfirebaseemulatorcommand }}" ]; then
    firebase emulators:exec '${{ inputs.customfirebaseemulatorcommand }} && fastlane ${{ inputs.fastlanelane }}'
else
    firebase emulators:exec 'fastlane ${{ inputs.fastlanelane }}'
``` 

This allows the following emulator command to be run:
```shell
firebase emulators:exec 'npm run serve:seed && fastlane test'
``` 


## 📚 Documentation
See description of `customfirebaseemulatorcommand` in
`xcodebuild-or-fastland.yml`.


## ✅ Testing
NA


### Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md):
- [X] I agree to follow the [Code of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
nriedman authored Sep 16, 2024
1 parent 919f1be commit 6544a6c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/xcodebuild-or-fastlane.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ on:
required: false
type: string
default: ''
firebasejsonpath:
description: |
Path to the firebase.json file that is used to boot up the firebase emulator.
Defaults to the root of the project.
required: false
type: string
default: './firebase.json'
googleserviceinfoplistpath:
description: |
Path to the GoogleService-Info.plist file that is replaced using the content found in the secret GOOGLE_SERVICE_INFO_PLIST.
Expand Down Expand Up @@ -374,9 +381,9 @@ jobs:
if [ -n "${{ inputs.firebaseemulatorimport }}" ]; then
echo "Importing firebase emulator data from ${{ inputs.firebaseemulatorimport }}"
firebase emulators:exec --import=${{ inputs.firebaseemulatorimport }} 'fastlane ${{ inputs.fastlanelane }}'
firebase emulators:exec -c ${{ inputs.firebasejsonpath }} --import=${{ inputs.firebaseemulatorimport }} 'fastlane ${{ inputs.fastlanelane }}'

Check warning on line 384 in .github/workflows/xcodebuild-or-fastlane.yml

View workflow job for this annotation

GitHub Actions / YAML Lint Check

384:151 [line-length] line too long (161 > 150 characters)
else
firebase emulators:exec 'fastlane ${{ inputs.fastlanelane }}'
firebase emulators:exec -c ${{ inputs.firebasejsonpath }} 'fastlane ${{ inputs.fastlanelane }}'
fi
else
fastlane ${{ inputs.fastlanelane }}
Expand Down

0 comments on commit 6544a6c

Please sign in to comment.