Skip to content

Commit 582ae9e

Browse files
chore(eas): access envfiles with eas locally
1 parent e1328bf commit 582ae9e

File tree

8 files changed

+127
-8
lines changed

8 files changed

+127
-8
lines changed

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ yarn-error.log
1919

2020
# macOS
2121
.DS_Store
22-
23-
.env.development
24-
.env.production
25-
.env.staging
26-
.env.qa
22+
*.apk
2723

2824
# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb
2925
# The following patterns were generated by expo-cli

README-project.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ To run the app on Android
3737
pnpm android
3838
```
3939

40+
To build your app locally you can run any of the build scripts with --local.
41+
42+
`pnpm build:development:ios --local`
43+
4044
### SonarQube setup
4145

4246
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.

app.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
2121
},
2222
updates: {
2323
fallbackToCacheTimeout: 0,
24+
url: 'https://u.expo.dev/72fdf440-59f1-493d-96e3-4afad8d7a045',
25+
},
26+
runtimeVersion: {
27+
policy: 'appVersion',
2428
},
2529
assetBundlePatterns: ['**/*'],
2630
ios: {

eas.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
"prebuildCommand": "prebuild --skip-dependency-update react",
6565
"cache": {
6666
"key": "eas-1"
67-
}
67+
},
68+
"channel": "development"
6869
},
6970
"simulator": {
7071
"ios": {
@@ -82,7 +83,8 @@
8283
"prebuildCommand": "prebuild --skip-dependency-update react",
8384
"cache": {
8485
"key": "eas-1"
85-
}
86+
},
87+
"channel": "simulator"
8688
}
8789
},
8890
"submit": {

env.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ require('dotenv').config({
2828
* Such as: bundle id, package name, app name.
2929
*
3030
* 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
31-
* for example: if the APP_ENV is staging, the bundle id will be com.myexpoapp.staging
31+
* for example: if the APP_ENV is staging, the bundle id will be com.rootstrap.staging
3232
*/
3333

3434
// TODO: Replace these values with your own

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"private": true,
55
"main": "expo-router/entry",
66
"scripts": {
7+
"eas-build-pre-install": "./source_env_local.sh",
78
"start": "cross-env EXPO_NO_DOTENV=1 expo start",
89
"prebuild": "cross-env EXPO_NO_DOTENV=1 pnpm expo prebuild",
910
"android": "cross-env EXPO_NO_DOTENV=1 expo run:android",
@@ -59,6 +60,7 @@
5960
"expo-splash-screen": "0.27.5",
6061
"expo-status-bar": "~1.12.1",
6162
"expo-system-ui": "~3.0.7",
63+
"expo-updates": "~0.25.21",
6264
"i18next": "^22.5.1",
6365
"lodash.memoize": "^4.1.2",
6466
"moti": "^0.28.1",

pnpm-lock.yaml

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source_env_local.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
# Determine the env file based on the APP_ENV variable
4+
case "$APP_ENV" in
5+
development)
6+
ENV_FILE=".env.development"
7+
;;
8+
staging)
9+
ENV_FILE=".env.staging"
10+
;;
11+
production)
12+
ENV_FILE=".env.production"
13+
;;
14+
*)
15+
echo "Error: Unknown APP_ENV value: $APP_ENV"
16+
exit 1
17+
;;
18+
esac
19+
20+
# Check if .env file exists
21+
if [ ! -f "$ENV_FILE" ]; then
22+
echo "Error: $ENV_FILE file does not exist."
23+
exit 1
24+
fi
25+
26+
echo "I am loading $ENV_FILE"
27+
28+
# Read .env file line by line
29+
while IFS= read -r line; do
30+
# Skip empty lines and lines starting with # (comments)
31+
if [[ -z "$line" || "$line" =~ ^# ]]; then
32+
continue
33+
fi
34+
35+
# Use regex to extract env variable KEY and VALUE
36+
if [[ "$line" =~ ^([^=]+)=(.*) ]]; then
37+
key="${BASH_REMATCH[1]}"
38+
value="${BASH_REMATCH[2]}"
39+
40+
# Use set-env binary to set the environment variable
41+
set-env "$key" "$value"
42+
if [ $? -ne 0 ]; then
43+
echo "Failed to set $key"
44+
else
45+
echo "Set $key"
46+
fi
47+
fi
48+
done < "$ENV_FILE"

0 commit comments

Comments
 (0)