Skip to content

Commit

Permalink
chore(eas): access envfiles with eas locally
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandatoledo committed Aug 7, 2024
1 parent e1328bf commit 582ae9e
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 8 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ yarn-error.log

# macOS
.DS_Store

.env.development
.env.production
.env.staging
.env.qa
*.apk

# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb
# The following patterns were generated by expo-cli
Expand Down
4 changes: 4 additions & 0 deletions README-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ To run the app on Android
pnpm android
```

To build your app locally you can run any of the build scripts with --local.

`pnpm build:development:ios --local`

### SonarQube setup

SonarQube is an open-source platform for continuous inspection of code quality. It performs automatic reviews to detect bugs, code smells, and security vulnerabilities. Rootstrap has a SonarQube instance to improve the quality of the software we develop. On each PR, a GitHub Action is triggered to perform the analysis. To set up SonarQube correctly, you need to add the `SONAR_TOKEN`, `SONAR_URL`, and `SONAR_PROJECT` secrets to the repository. Additionally, you must select the quality gate named `ReactNativeTemplate` for your project on SonarQube. In case you're using this project outside Rootstrap and you're not planning to use SonarQube the sonar scanner [workflow](.github/workflows/sonar.yml) should be deleted.
Expand Down
4 changes: 4 additions & 0 deletions app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
},
updates: {
fallbackToCacheTimeout: 0,
url: 'https://u.expo.dev/72fdf440-59f1-493d-96e3-4afad8d7a045',
},
runtimeVersion: {
policy: 'appVersion',
},
assetBundlePatterns: ['**/*'],
ios: {
Expand Down
6 changes: 4 additions & 2 deletions eas.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"prebuildCommand": "prebuild --skip-dependency-update react",
"cache": {
"key": "eas-1"
}
},
"channel": "development"
},
"simulator": {
"ios": {
Expand All @@ -82,7 +83,8 @@
"prebuildCommand": "prebuild --skip-dependency-update react",
"cache": {
"key": "eas-1"
}
},
"channel": "simulator"
}
},
"submit": {
Expand Down
2 changes: 1 addition & 1 deletion env.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require('dotenv').config({
* Such as: bundle id, package name, app name.
*
* You can add them to the .env file but we think it's better to keep them here as as we use prefix to generate this values based on the APP_ENV
* for example: if the APP_ENV is staging, the bundle id will be com.myexpoapp.staging
* for example: if the APP_ENV is staging, the bundle id will be com.rootstrap.staging
*/

// TODO: Replace these values with your own
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"main": "expo-router/entry",
"scripts": {
"eas-build-pre-install": "./source_env_local.sh",
"start": "cross-env EXPO_NO_DOTENV=1 expo start",
"prebuild": "cross-env EXPO_NO_DOTENV=1 pnpm expo prebuild",
"android": "cross-env EXPO_NO_DOTENV=1 expo run:android",
Expand Down Expand Up @@ -59,6 +60,7 @@
"expo-splash-screen": "0.27.5",
"expo-status-bar": "~1.12.1",
"expo-system-ui": "~3.0.7",
"expo-updates": "~0.25.21",
"i18next": "^22.5.1",
"lodash.memoize": "^4.1.2",
"moti": "^0.28.1",
Expand Down
63 changes: 63 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions source_env_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Determine the env file based on the APP_ENV variable
case "$APP_ENV" in
development)
ENV_FILE=".env.development"
;;
staging)
ENV_FILE=".env.staging"
;;
production)
ENV_FILE=".env.production"
;;
*)
echo "Error: Unknown APP_ENV value: $APP_ENV"
exit 1
;;
esac

# Check if .env file exists
if [ ! -f "$ENV_FILE" ]; then
echo "Error: $ENV_FILE file does not exist."
exit 1
fi

echo "I am loading $ENV_FILE"

# Read .env file line by line
while IFS= read -r line; do
# Skip empty lines and lines starting with # (comments)
if [[ -z "$line" || "$line" =~ ^# ]]; then
continue
fi

# Use regex to extract env variable KEY and VALUE
if [[ "$line" =~ ^([^=]+)=(.*) ]]; then
key="${BASH_REMATCH[1]}"
value="${BASH_REMATCH[2]}"

# Use set-env binary to set the environment variable
set-env "$key" "$value"
if [ $? -ne 0 ]; then
echo "Failed to set $key"
else
echo "Set $key"
fi
fi
done < "$ENV_FILE"

0 comments on commit 582ae9e

Please sign in to comment.