Skip to content

Commit

Permalink
Setup EAS for replicable builds (#44)
Browse files Browse the repository at this point in the history
* Install EAS
* Setup EAS project ID
* Generate eas.json
* Disable custom signing in EAS build
* Add dev client to preview build
* Fix dependencies according to expo install check
* Update CLI version
* Disable detox plugin by default
* Build time error if missing env var
* Provide working defaults
* Remove unnecessary plugin
* Remove unnecessary dependencies
* Add missing environment to EAS dev build
* Enforce git repo is clean for build

---------

Co-authored-by: quan.vo <[email protected]>
  • Loading branch information
NSeydoux and quanvo298Wizeline authored Sep 11, 2024
1 parent 0bb0d15 commit 5d1e65c
Show file tree
Hide file tree
Showing 12 changed files with 1,024 additions and 139 deletions.
1 change: 1 addition & 0 deletions .detoxrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @type {Detox.DetoxConfig} */
const dotenv = require('dotenv');
dotenv.config();

module.exports = {
testRunner: {
args: {
Expand Down
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ TEST_ANDROID_EMU=<Name of the Android emulator on your device>
SIGNING_CONFIG_PATH=/absolute/path/to/android-config/signing-config.gradle
KEYSTORE_PATH=/absolute/path/to/wallet.keystore
KEYSTORE_PASSWORD=<keystore password>
EAS_PROJECT_ID="project-id-from-eas"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ npm-debug.*
*.orig.*
web-build/
.idea
.vscode/

# macOS
.DS_Store
Expand All @@ -28,6 +29,7 @@ expo-env.d.ts
.env

*.keystore
*.apk

# Folder where the UI tests get stored.
screenshots/
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This README provides information on:
* [Access](#access)


## Setup
## Build the app locally

### Prerequisites

Expand Down Expand Up @@ -81,6 +81,18 @@ To
- KEYSTORE_PASSWORD with the keystore password
- In CI, decrypt the keystore back: `gpg -d --passphrase "..." --batch wallet.keystore.asc > wallet.keystore`

## Build the app on EAS

Both the Android and the iOS versions of the app can be built using the Expo Application Service (EAS). To do so, follow
the instructions from the [EAS documentation](https://docs.expo.dev/build/setup/).

Note that the project ID is not hard-coded in the `app.config.ts`, but provided as an environment variable instead.
In order to trigger an EAS build, please add the appropriate project ID in your environment, e.g.

```
EAS_PROJECT_ID="..." eas build --platform android --local --profile preview
```

## Running the application

If you are going to run the application in an emulator or simulator, you need to build the development version using
Expand Down
55 changes: 51 additions & 4 deletions app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,41 @@
//
import type { ExpoConfig, ConfigContext } from "expo/config";

export default ({ config }: ConfigContext): ExpoConfig => ({
...config,
const isDevelopmentMode =
process.env.NODE_ENV === "development" ||
process.env.EAS_BUILD_PROFILE === "development";
const isTestMode =
!isDevelopmentMode &&
process.env.EAS_BUILD_PROFILE !== "production" &&
process.env.EAS_BUILD_PROFILE === "preview";

function validateEnv() {
if (
typeof process.env.EXPO_PUBLIC_WALLET_API !== "string" ||
!URL.canParse(process.env.EXPO_PUBLIC_WALLET_API)
) {
throw new Error(
`Missing or invalid environment variable EXPO_PUBLIC_WALLET_API. Expected a valid URL, found ${process.env.EXPO_PUBLIC_WALLET_API}`
);
}
if (
typeof process.env.EXPO_PUBLIC_LOGIN_URL !== "string" ||
!URL.canParse(process.env.EXPO_PUBLIC_LOGIN_URL)
) {
throw new Error(
`Missing or invalid environment variable EXPO_PUBLIC_LOGIN_URL. Expected a valid URL, found ${process.env.EXPO_PUBLIC_LOGIN_URL}`
);
}
if (typeof process.env.EAS_PROJECT_ID !== "string") {
throw new Error(`Missing environment variable EAS_PROJECT_ID.`);
}
}
if (process.env.EAS_BUILD === "true") {
// Check that all required environment variables are defined at build time.
validateEnv();
}

const baseConfig: ExpoConfig = {
name: "inrupt-data-wallet",
slug: "inrupt-data-wallet",
version: "1.0.0",
Expand All @@ -39,6 +72,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
backgroundColor: "#ffffff",
},
package: "com.inrupt.wallet",
permissions: ["android.permission.CAMERA"],
blockedPermissions: [
"android.permission.RECORD_AUDIO",
"android.permission.READ_EXTERNAL_STORAGE",
Expand All @@ -54,18 +88,31 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
plugins: [
"expo-router",
"expo-secure-store",
"@config-plugins/detox",
[
"expo-build-properties",
{
android: {
usesCleartextTraffic: process.env.NODE_ENV === "development",
usesCleartextTraffic: isDevelopmentMode,
},
},
],
"./plugins/withSigningConfig",
// The detox plugin interferes with the generated output, so
// only include it when actually building for tests.
...(isTestMode ? ["@config-plugins/detox"] : []),
],
experiments: {
typedRoutes: true,
},
extra: {
eas: {
projectId: process.env.EAS_PROJECT_ID,
},
},
owner: "inrupt",
};

export default ({ config }: ConfigContext): ExpoConfig => ({
...config,
...baseConfig,
});
2 changes: 1 addition & 1 deletion app/(tabs)/requests/[requestId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const styles = StyleSheet.create({
flex: 1,
paddingLeft: 12,
},
button: { marginBottom: 24, width: 211 },
button: { marginBottom: 16, width: 211 },
name: {
fontSize: 16,
},
Expand Down
5 changes: 3 additions & 2 deletions components/login/LoginWebViewModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
Modal,
} from "react-native";
import { WebView, type WebViewNavigation } from "react-native-webview";
import { DEFAULT_LOGIN_URL, DEFAULT_WALLET_API } from "@/constants/defaults";

interface LoginWebViewModalProps {
onClose: () => void;
Expand All @@ -36,8 +37,8 @@ const LoginWebViewModal: React.FC<LoginWebViewModalProps> = ({
onLogoutSuccess = () => null,
requestMode = "blank",
}) => {
const BASE_URL = process.env.EXPO_PUBLIC_WALLET_API || "";
const LOGIN_URL = process.env.EXPO_PUBLIC_LOGIN_URL || "";
const BASE_URL = process.env.EXPO_PUBLIC_WALLET_API ?? DEFAULT_LOGIN_URL;
const LOGIN_URL = process.env.EXPO_PUBLIC_LOGIN_URL ?? DEFAULT_WALLET_API;
const LOGOUT_URL = `${BASE_URL}/logout`;

const webViewRef = useRef<WebView | null>(null);
Expand Down
19 changes: 19 additions & 0 deletions constants/defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Copyright Inrupt Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

export const DEFAULT_LOGIN_URL =
"https://datawallet.inrupt.com/oauth2/authorization/wallet-app";
export const DEFAULT_WALLET_API = "https://datawallet.inrupt.com";
34 changes: 34 additions & 0 deletions eas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"cli": {
"version": "12.3.0",
"appVersionSource": "remote",
"requireCommit": true
},
"build": {
"development": {
"developmentClient": true,
"distribution": "internal",
"env": {
"EXPO_PUBLIC_LOGIN_URL" : "https://datawallet.dev.inrupt.com/oauth2/authorization/wallet-app",
"EXPO_PUBLIC_WALLET_API": "https://datawallet.dev.inrupt.com"
}
},
"preview": {
"distribution": "internal",
"env": {
"EXPO_PUBLIC_LOGIN_URL" : "https://datawallet.dev.inrupt.com/oauth2/authorization/wallet-app",
"EXPO_PUBLIC_WALLET_API": "https://datawallet.dev.inrupt.com"
}
},
"production": {
"autoIncrement": true,
"env": {
"EXPO_PUBLIC_LOGIN_URL" : "https://datawallet.dev.inrupt.com/oauth2/authorization/wallet-app",
"EXPO_PUBLIC_WALLET_API": "https://datawallet.dev.inrupt.com"
}
}
},
"submit": {
"production": {}
}
}
Loading

0 comments on commit 5d1e65c

Please sign in to comment.