Skip to content

Commit

Permalink
[expo] extract env screts in Github Action.
Browse files Browse the repository at this point in the history
**Summary**

We use eas-{env} for Github Environment and set secrets.

**Test**

- Github action with main branch

**Issue**

- #155
  • Loading branch information
yssk22 committed Dec 19, 2024
1 parent e96780f commit 26c96bd
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 23 deletions.
92 changes: 71 additions & 21 deletions .github/workflows/eas-build-android.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,90 @@
name: EAS - Build - Android
name: EAS - Build Android
on:
workflow_dispatch:
inputs:
config:
description: "HPAPP_CONFIG_NAME set"
required: true
default: "dev"
type: choice
options:
- dev
- beta
- prod
dev:
description: "HPAPP_CONFIG_NAME=dev"
required: false
type: boolean
default: false
beta:
description: "HPAPP_CONFIG_NAME=beta"
required: false
type: boolean
default: false
prod:
description: "HPAPP_CONFIG_NAME=prod"
required: false
type: boolean
default: false
env:
NODE_VERSION: 22.3.0
EAS_VERSION: 13.4.2
JAVA_VERSION: 17
jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
target: ${{ steps.generatematrix.outputs.target }}
steps:
- id: generatematrix
run: |
inputs='${{ toJson(github.event.inputs) }}'
targets=()
for key in $(echo "$inputs" | jq -r 'keys[]'); do
if [ "$(echo "$inputs" | jq -r ".\"$key\"")" == "true" ]; then
targets+=("$key")
fi
done
targets_str=$(printf ',"%s"' "${targets[@]}")
targets_str="[${targets_str:1}]"
echo "target=$targets_str" >> $GITHUB_OUTPUT
build:
needs: generate-matrix
strategy:
matrix:
target: ${{ fromJson(needs.generate-matrix.outputs.target) }}
runs-on: ubuntu-latest
environment:
name: eas-${{inputs.platform}}
name: eas-${{ matrix.target }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "22.3.0"
node-version: ${{ env.NODE_VERSION }}
cache: "yarn"
cache-dependency-path: "expo/package.json"
- uses: expo/expo-github-action@v8
with:
eas-version: 13.4.2
eas-version: ${{ env.EAS_VERSION }}
token: ${{ secrets.EXPO_TOKEN }}
- uses: actions/setup-java@v3
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: "temurin"
- uses: android-actions/setup-android@v3
- run: cd expo && ./scripts/eas-githubaction-pre.sh
env:
HPAPP_CONFIG_NAME: ${{ matrix.target }}
SECRETS_JSON: ${{ secrets.SECRETS_JSON }}
GOOGLE_SERVICES_INFO_PLIST: ${{ secrets.GOOGLE_SERVICES_INFO_PLIST }}
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
- run: cd expo && yarn install
- if: ${{ ((inputs.config == 'prod') || (inputs.config == 'beta')) }}
run: cd expo && ./scripts/eas.sh build --profile ${{inputs.config}} --platform android --local --output ./build/hpapp-${{inputs.config}}.aab
- run: cd expo && ./scripts/eas.sh build --profile ${{ matrix.target }} --platform android --local --output ./build/hpapp-${{ matrix.target }}.apk
if: ${{ matrix.target == 'dev' }}
env:
HPAPP_CONFIG_NAME: ${{inputs.config}}
HPAPP_CONFIG_PLATFORM: ${{inputs.platform}}
- if: ${{ ((inputs.config != 'prod') && (inputs.config != 'beta')) }}
run: cd expo && ./scripts/eas.sh build --profile dev --platform android --local --output ./build/hpapp-${{inputs.config}}.apk
HPAPP_CONFIG_NAME: ${{ matrix.target }}
- uses: actions/upload-artifact@v4
if: ${{ matrix.target == 'dev' }}
with:
name: hpapp-${{ matrix.target }}.aab
path: ./build/hpapp-${{ matrix.target }}.apk
- run: cd expo && ./scripts/eas.sh build --profile ${{ matrix.target }} --platform android --local --output ./build/hpapp-${{ matrix.target }}.aab
if: ${{ matrix.target != 'dev' }}
env:
HPAPP_CONFIG_NAME: dev
HPAPP_CONFIG_PLATFORM: ${{ inputs.platform }}
HPAPP_CONFIG_NAME: ${{ matrix.target }}
- uses: actions/upload-artifact@v4
if: ${{ matrix.target != 'dev' }}
with:
name: hpapp-${{ matrix.target }}.aab
path: ./build/hpapp-${{ matrix.target }}.aab
74 changes: 74 additions & 0 deletions .github/workflows/eas-build-ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: EAS - Build iOS
on:
workflow_dispatch:
inputs:
dev:
description: "HPAPP_CONFIG_NAME=dev"
required: false
type: boolean
default: false
beta:
description: "HPAPP_CONFIG_NAME=beta"
required: false
type: boolean
default: false
prod:
description: "HPAPP_CONFIG_NAME=prod"
required: false
type: boolean
default: false
env:
NODE_VERSION: 22.3.0
EAS_VERSION: 13.4.2
JAVA_VERSION: 17
jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
target: ${{ steps.generatematrix.outputs.target }}
steps:
- id: generatematrix
run: |
inputs='${{ toJson(github.event.inputs) }}'
targets=()
for key in $(echo "$inputs" | jq -r 'keys[]'); do
if [ "$(echo "$inputs" | jq -r ".\"$key\"")" == "true" ]; then
targets+=("$key")
fi
done
targets_str=$(printf ',"%s"' "${targets[@]}")
targets_str="[${targets_str:1}]"
echo "target=$targets_str" >> $GITHUB_OUTPUT
build:
needs: generate-matrix
strategy:
matrix:
target: ${{ fromJson(needs.generate-matrix.outputs.target) }}
runs-on: macos-latest
environment:
name: eas-${{ matrix.target }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: "yarn"
cache-dependency-path: "expo/package.json"
- uses: expo/expo-github-action@v8
with:
eas-version: ${{ env.EAS_VERSION }}
token: ${{ secrets.EXPO_TOKEN }}
- run: cd expo && ./scripts/eas-githubaction-pre.sh
env:
HPAPP_CONFIG_NAME: ${{ matrix.target }}
SECRETS_JSON: ${{ secrets.SECRETS_JSON }}
GOOGLE_SERVICES_INFO_PLIST: ${{ secrets.GOOGLE_SERVICES_INFO_PLIST }}
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
- run: cd expo && yarn install
- run: cd expo && ./scripts/eas.sh build --profile ${{ matrix.target }} --platform ios --non-interactive --local --output ./build/hpapp-${{ matrix.target }}.ipa
env:
HPAPP_CONFIG_NAME: ${{ matrix.target }}
- uses: actions/upload-artifact@v4
with:
name: hpapp-${{ matrix.target }}.ipa
path: ./build/hpapp-${{ matrix.target }}.ipa
2 changes: 1 addition & 1 deletion expo/config/prod/app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = (config) => {
// those id can be easily found in the URL in the browser in development build so we don't necessary put them into secrets.json
config.extra.hpapp.firebaseIOSClientID = '265427540400-um42nfj6a2d2i59u7j01pmgpijmqk1oc.apps.googleusercontent.com';
config.extra.hpapp.firebaseAndroidClientID =
'265427540400-83oj9vqhc5o3srj9pvh5d9e9hkfmnmdg.apps.googleusercontent.com';
'265427540400-k0bpqfj2fph4vf2sspqd5a85te6lh151.apps.googleusercontent.com';
config.updates.url = 'https://u.expo.dev/a76e7e46-e508-43cf-93a8-1ae32871d4f7';
return config;
};
1 change: 1 addition & 0 deletions expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"expo-sqlite": "~14.0.6",
"expo-status-bar": "~1.12.1",
"expo-updates": "~0.25.17",
"fs-extra": "^11.2.0",
"i18n-js": "^4.3.2",
"jsdom-jscore-rn": "^0.1.8",
"node-html-parser": "^6.1.13",
Expand Down
15 changes: 15 additions & 0 deletions expo/scripts/eas-githubaction-pre.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
BASEDIR=$(dirname $0)/..

if [ -z $HPAPP_CONFIG_NAME ]; then
echo "HPAPP_CONFIG_NAME is not defined."
exit 1
fi

## extract environment screts
echo '$SECRETS_JSON' | envsubst > $BASEDIR/config/$HPAPP_CONFIG_NAME/secrets.json
echo '$GOOGLE_SERVICES_INFO_PLIST' | envsubst > $BASEDIR/config/$HPAPP_CONFIG_NAME/GoogleService-Info.plist
echo '$GOOGLE_SERVICES_JSON' | envsubst > $BASEDIR/config/$HPAPP_CONFIG_NAME/google-services.json

## remove .gitignore as eas still ignore those files
rm $BASEDIR/config/$HPAPP_CONFIG_NAME/.gitignore
2 changes: 1 addition & 1 deletion expo/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7310,7 +7310,7 @@ fs-extra@^10.0.0:
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^11.1.0:
fs-extra@^11.1.0, fs-extra@^11.2.0:
version "11.2.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.2.0.tgz#e70e17dfad64232287d01929399e0ea7c86b0e5b"
integrity sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==
Expand Down

0 comments on commit 26c96bd

Please sign in to comment.