Skip to content

Commit a9bf801

Browse files
committed
Added separate env files to different build profiles and eas build workflow
1 parent dcc29f7 commit a9bf801

12 files changed

Lines changed: 315 additions & 97 deletions

File tree

.env.example

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
# For Android emulator
2-
EXPO_PUBLIC_API_URL=
2+
API_URL=
33

44
# For real device (uncomment and set your PC's local IP address)
5-
# EXPO_PUBLIC_API_URL="http://192.168.x.x:8080"
5+
# API_URL="http://192.168.x.x:8080"
66

7-
EXPO_PUBLIC_GOOGLE_MAPS_API_KEY=YOUR_GOOGLE_MAPS_API_KEY_HERE
7+
GOOGLE_MAPS_API_KEY=YOUR_GOOGLE_MAPS_API_KEY_HERE
8+
9+
# Chat feature
10+
FIREBASE_API_KEY=
11+
FIREBASE_AUTH_DOMAIN=
12+
FIREBASE_PROJECT_ID=
13+
FIREBASE_STORAGE_BUCKET=
14+
FIREBASE_MESSAGING_SENDER_ID=
15+
FIREBASE_APP_ID=

.github/workflows/eas-build.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: EAS Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main # triggers production build
7+
- dev # triggers preview build
8+
workflow_dispatch:
9+
inputs:
10+
profile:
11+
description: "Build profile"
12+
required: true
13+
default: "preview"
14+
type: choice
15+
options:
16+
- preview
17+
- production
18+
19+
jobs:
20+
build:
21+
name: EAS Build
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: 20
32+
cache: "npm"
33+
34+
- name: Install dependencies
35+
run: npm ci
36+
37+
- name: Setup Expo and EAS
38+
uses: expo/expo-github-action@v8
39+
with:
40+
eas-version: latest
41+
token: ${{ secrets.EXPO_TOKEN }}
42+
43+
- name: Set build profile and environment
44+
id: config
45+
run: |
46+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
47+
PROFILE=${{ github.event.inputs.profile }}
48+
elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
49+
PROFILE=production
50+
else
51+
PROFILE=preview
52+
fi
53+
54+
echo "profile=$PROFILE" >> $GITHUB_OUTPUT
55+
56+
# Set API_URL based on profile
57+
if [ "$PROFILE" == "production" ]; then
58+
echo "API_URL=${{ secrets.PROD_API_URL }}" >> $GITHUB_ENV
59+
echo "APP_ENV=production" >> $GITHUB_ENV
60+
else
61+
echo "API_URL=${{ secrets.PREVIEW_API_URL }}" >> $GITHUB_ENV
62+
echo "APP_ENV=preview" >> $GITHUB_ENV
63+
fi
64+
65+
- name: Create .env file
66+
run: |
67+
echo "API_URL=${{ env.API_URL }}" >> .env.${{ env.APP_ENV }}
68+
echo "APP_ENV=${{ env.APP_ENV }}" >> .env.${{ env.APP_ENV }}
69+
70+
- name: Build on EAS
71+
run: eas build --platform android --profile ${{ steps.config.outputs.profile }} --non-interactive
72+
73+
- name: Notify success
74+
if: success()
75+
run: |
76+
echo "✅ Build succeeded for profile: ${{ steps.config.outputs.profile }}"
77+
echo "🔗 Check your build at https://expo.dev"
78+
79+
- name: Notify failure
80+
if: failure()
81+
run: |
82+
echo "❌ Build failed for profile: ${{ steps.config.outputs.profile }}"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ yarn-error.*
3333
# local env files
3434
.env
3535
.env*.local
36+
.env.development
37+
.env.production
38+
.env.preview
3639

3740
# typescript
3841
*.tsbuildinfo

app.config.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import "dotenv/config";
2+
3+
const ENV = process.env.APP_ENV ?? "development";
4+
5+
const envFiles = {
6+
development: ".env.development",
7+
preview: ".env.preview",
8+
production: ".env.production",
9+
};
10+
11+
require("dotenv").config({ path: envFiles[ENV] });
12+
13+
const appName =
14+
ENV === "production" ? "CrimelinkAnalyzer" : `CrimelinkAnalyzer (${ENV})`;
15+
16+
export default {
17+
expo: {
18+
name: appName,
19+
slug: "CrimelinkAnalyzer_app",
20+
version: "1.0.0",
21+
orientation: "portrait",
22+
icon: "./assets/images/logo.png",
23+
scheme: "crimelinkanalyzerapp",
24+
userInterfaceStyle: "automatic",
25+
newArchEnabled: true,
26+
27+
ios: {
28+
supportsTablet: true,
29+
infoPlist: {
30+
NSLocationWhenInUseUsageDescription:
31+
"This app uses your location to show nearby places and reports.",
32+
NSFaceIDUsageDescription:
33+
"Allow Crime Link Analyzer to use Face ID to authenticate you.",
34+
},
35+
},
36+
37+
android: {
38+
adaptiveIcon: {
39+
backgroundColor: "#E6F4FE",
40+
foregroundImage: "./assets/images/logo.png",
41+
backgroundImage: "./assets/images/logo.png",
42+
monochromeImage: "./assets/images/logo.png",
43+
},
44+
edgeToEdgeEnabled: true,
45+
predictiveBackGestureEnabled: false,
46+
permissions: ["ACCESS_FINE_LOCATION"],
47+
package: "com.anonymous.CrimelinkAnalyzer_app",
48+
jsEngine: "jsc",
49+
},
50+
51+
web: {
52+
output: "static",
53+
favicon: "./assets/images/logo.png",
54+
},
55+
56+
plugins: [
57+
"expo-router",
58+
[
59+
"expo-splash-screen",
60+
{
61+
image: "./assets/images/logo.png",
62+
imageWidth: 200,
63+
resizeMode: "contain",
64+
backgroundColor: "#ffffff",
65+
dark: {
66+
backgroundColor: "#000000",
67+
},
68+
},
69+
],
70+
"expo-secure-store",
71+
"expo-sqlite",
72+
],
73+
74+
experiments: {
75+
typedRoutes: true,
76+
reactCompiler: true,
77+
},
78+
79+
extra: {
80+
router: {},
81+
eas: {
82+
projectId: "ab5e7b7b-eb2e-49f5-9a61-01529d4cae27",
83+
},
84+
appEnv: ENV,
85+
apiUrl: process.env.API_URL,
86+
googleMapsApiKey: process.env.GOOGLE_MAPS_API_KEY,
87+
firebaseApiKey: process.env.FIREBASE_API_KEY,
88+
firebaseAuthDomain: process.env.FIREBASE_AUTH_DOMAIN,
89+
firebaseProjectId: process.env.FIREBASE_PROJECT_ID,
90+
firebaseStorageBucket: process.env.FIREBASE_STORAGE_BUCKET,
91+
firebaseMessagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID,
92+
firebaseAppId: process.env.FIREBASE_APP_ID,
93+
},
94+
},
95+
};

app.json

Lines changed: 0 additions & 63 deletions
This file was deleted.

app/(screens)/SafetyZone.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import OverlayButton from "@/src/components/UI/OverlayButton";
33
import Searchbar from "@/src/components/UI/Searchbar";
44
import { getCrimeLocations } from "@/src/services/safetyzoneService";
55
import { CrimeLocationType } from "@/src/types/SafetyzoneTypes";
6-
import { Button } from "@react-navigation/elements";
76
import * as Location from "expo-location";
8-
import { router } from "expo-router";
97
import React, { useEffect, useState } from "react";
108
import { ActivityIndicator, Dimensions, Text, View } from "react-native";
119
import MapView, { Marker, Region } from "react-native-maps";

eas.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,27 @@
66
"build": {
77
"development": {
88
"developmentClient": true,
9-
"distribution": "internal"
9+
"distribution": "internal",
10+
"env": {
11+
"APP_ENV": "development"
12+
}
1013
},
1114
"preview": {
1215
"android": {
13-
"buildType": "apk"
16+
"buildType": "apk",
17+
"env": {
18+
"APP_ENV": "preview"
19+
}
1420
}
1521
},
1622
"production": {
1723
"android": {
1824
"buildType": "app-bundle"
1925
},
20-
"autoIncrement": true
26+
"autoIncrement": true,
27+
"env": {
28+
"APP_ENV": "production"
29+
}
2130
}
2231
},
2332
"submit": {

firebase.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
import { initializeApp, getApps, getApp } from "firebase/app";
1+
import ReactNativeAsyncStorage from "@react-native-async-storage/async-storage";
2+
import { getApp, getApps, initializeApp } from "firebase/app";
23
import {
34
getAuth,
4-
initializeAuth,
55
getReactNativePersistence,
6+
initializeAuth,
67
} from "firebase/auth";
78
import { getFirestore } from "firebase/firestore";
8-
import ReactNativeAsyncStorage from "@react-native-async-storage/async-storage";
9-
10-
const firebaseConfig = {
11-
apiKey: "AIzaSyAUTM7T4PU0wZP2Qs5nWIGNM5D1wrWE0-o",
12-
authDomain: "chatapp-3b437.firebaseapp.com",
13-
projectId: "chatapp-3b437",
14-
storageBucket: "chatapp-3b437.firebasestorage.app",
15-
messagingSenderId: "822724763822",
16-
appId: "1:822724763822:web:3ed2eb039b703b00dacd3f",
17-
};
9+
import { firebaseConfig } from "./src/constants/appConfig";
1810

1911
// Initialize Firebase only if no app exists
2012
const app = !getApps().length ? initializeApp(firebaseConfig) : getApp();

0 commit comments

Comments
 (0)