Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ifirmawan committed May 29, 2024
2 parents 47fc49e + e4d6c0e commit dcf5e9e
Show file tree
Hide file tree
Showing 49 changed files with 701 additions and 198 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/apk-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ jobs:
with:
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}
run: |
echo "SENTRY_ENV='production'" >> $GITHUB_ENV
env:
SENTRY_ENV: ${{ env.SENTRY_ENV }}
SENTRY_DSN: ${{ secrets.SENTRY_MOBILE_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_MOBILE_AUTH_TOKEN }}

- name: 📦 Install dependencies
run: |
Expand Down Expand Up @@ -101,6 +107,9 @@ jobs:
env:
APK_VERSION: ${{ env.APK_VERSION }}
SECRET: ${{ secrets.APK_UPLOAD_SECRET }}
SENTRY_ENV: ${{ env.SENTRY_ENV }}
SENTRY_DSN: ${{ secrets.SENTRY_MOBILE_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_MOBILE_AUTH_TOKEN }}
run: |
curl -X 'POST' \
'https://rtmis.akvotest.org/api/v1/device/apk/upload' \
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ jobs:
with:
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}
run: |
echo "SENTRY_ENV='production'" >> $GITHUB_ENV
env:
SENTRY_ENV: ${{ env.SENTRY_ENV }}
SENTRY_DSN: ${{ secrets.SENTRY_MOBILE_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_MOBILE_AUTH_TOKEN }}

- name: 📦 Install dependencies
run: |
Expand Down Expand Up @@ -183,6 +189,9 @@ jobs:
env:
APK_VERSION: ${{ env.APK_VERSION }}
SECRET: ${{ secrets.APK_UPLOAD_SECRET }}
SENTRY_ENV: ${{ env.SENTRY_ENV }}
SENTRY_DSN: ${{ secrets.SENTRY_MOBILE_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_MOBILE_AUTH_TOKEN }}
run: |
curl -X 'POST' \
'https://rtmis.akvo.org/api/v1/device/apk/upload' \
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ PGADMIN_LISTEN_PORT="5050"
IP_ADDRESS="http://<your_ip_address>:3000/api/v1/device"
APK_UPLOAD_SECRET="123456789AU"
STORAGE_PATH="./storage"
SENTRY_MOBILE_ENV="<<your sentry env>>"
SENTRY_MOBILE_DSN="<<your_sentry_mobile_DSN>>"
SENTRY_MOBILE_AUTH_TOKEN="<<your_sentry_mobile_auth_token>>"
```


You can generate a Sentry auth token by following [this official Sentry documentation](https://docs.sentry.io/account/auth-tokens/).

#### Start

For initial run, you need to create a new docker volume.
Expand Down
43 changes: 31 additions & 12 deletions app/App.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/* eslint-disable no-console */
import React, { useCallback, useEffect } from 'react';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import NetInfo from '@react-native-community/netinfo';
import * as Notifications from 'expo-notifications';
import * as TaskManager from 'expo-task-manager';
import * as BackgroundFetch from 'expo-background-fetch';

import * as Sentry from '@sentry/react-native';
import { ToastAndroid } from 'react-native';
import * as Location from 'expo-location';
import Navigation from './src/navigation';
import { SENTRY_DSN, SENTRY_ENV } from '@env';

import Navigation, { routingInstrumentation } from './src/navigation';
import { conn, query, tables } from './src/database';
import { UIState, AuthState, UserState, BuildParamsState } from './src/store';
import { crudUsers, crudConfig, crudDataPoints } from './src/database/crud';
Expand All @@ -34,7 +35,6 @@ TaskManager.defineTask(SYNC_FORM_SUBMISSION_TASK_NAME, async () => {
try {
const pendingToSync = await crudDataPoints.selectSubmissionToSync();
const activeJob = await crudJobs.getActiveJob(SYNC_FORM_SUBMISSION_TASK_NAME);
console.info('[BACKGROUND ACTIVE JOB]', activeJob);

if (activeJob?.status === jobStatus.ON_PROGRESS) {
if (activeJob.attempt < MAX_ATTEMPT && pendingToSync.length) {
Expand Down Expand Up @@ -76,11 +76,30 @@ TaskManager.defineTask(SYNC_FORM_SUBMISSION_TASK_NAME, async () => {
}
return BackgroundFetch.BackgroundFetchResult.NewData;
} catch (err) {
console.error(`[${SYNC_FORM_SUBMISSION_TASK_NAME}] Define task manager failed`, err);
Sentry.captureMessage(`[${SYNC_FORM_SUBMISSION_TASK_NAME}] Define task manager failed`);
Sentry.captureException(err);
return BackgroundFetch.Result.Failed;
}
});

Sentry.init({
dsn: SENTRY_DSN,
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 1.0,
enableInExpoDevelopment: true,
// If `true`, Sentry will try to print out useful debugging information if something goes wrong with sending the event.
// Set it to `false` in production
environment: SENTRY_ENV,
debug: false,
integrations: [
new Sentry.ReactNativeTracing({
routingInstrumentation,
}),
],
});

const App = () => {
const serverURLState = BuildParamsState.useState((s) => s.serverURL);
const syncValue = BuildParamsState.useState((s) => s.dataSyncInterval);
Expand All @@ -94,7 +113,6 @@ const App = () => {
crudUsers
.getActiveUser()
.then((user) => {
console.info('Users =>', user);

const page = 'Home';
return { user, page };
Expand Down Expand Up @@ -153,7 +171,7 @@ const App = () => {
s.syncWifiOnly = configExist?.syncWifiOnly;
});
}
console.info('[CONFIG] Server URL', serverURL);

}, [geoLocationTimeout, gpsAccuracyLevel, gpsThreshold, serverURLState, syncValue]);

const handleInitDB = useCallback(async () => {
Expand All @@ -172,7 +190,8 @@ const App = () => {
await handleInitConfig();
handleCheckSession();
} catch (error) {
console.error(`[INITIAL DB]: ${error}`);
Sentry.captureMessage(`[INITIAL DB]`);
Sentry.captureException(error);
ToastAndroid.show(`[INITIAL DB]: ${error}`, ToastAndroid.LONG);
}
}, [handleInitConfig, handleCheckSession]);
Expand All @@ -197,15 +216,15 @@ const App = () => {
const handleOnRegisterTask = useCallback(async () => {
try {
const allTasks = await TaskManager.getRegisteredTasksAsync();
console.log('allTasks', allTasks);

allTasks.forEach(async (a) => {
if ([SYNC_FORM_SUBMISSION_TASK_NAME, SYNC_FORM_VERSION_TASK_NAME].includes(a.taskName)) {
console.info(`[${a.taskName}] IS REGISTERED`);
await backgroundTask.registerBackgroundTask(a.taskName);
}
});
} catch (error) {
console.error('TASK REGISTER ERROR', error);
Sentry.captureMessage(`handleOnRegisterTask`);
Sentry.captureException(error);
}
}, []);

Expand Down Expand Up @@ -238,4 +257,4 @@ const App = () => {
);
};

export default App;
export default Sentry.wrap(App);
23 changes: 23 additions & 0 deletions app/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@
"enabled": true
}
]
},
"plugins": [
[
"sentry-expo",
{
"url": "https://sentry.io/",
"note": "Use SENTRY_AUTH_TOKEN env to authenticate with Sentry.",
"organization": "akvo-foundation",
"project": "rtmis-mobile",
"setCommits": true
}
]
],
"hooks": {
"postPublish": [
{
"file": "sentry-expo/upload-sourcemaps",
"config": {
"organization": "akvo-foundation",
"project": "rtmis-mobile"
}
}
]
}
}
}
4 changes: 2 additions & 2 deletions app/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ module.exports = {
// setupFiles: [],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],
setupFilesAfterEnv: ['<rootDir>/setup-test-env.js'],

// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,
Expand Down Expand Up @@ -176,7 +176,7 @@ module.exports = {
// transform: undefined,

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
transformIgnorePatterns: ['node_modules/(?!react-native|react-navigation)/'],
transformIgnorePatterns: ['node_modules/(?!react-native|react-navigation|@sentry|sentry-expo)/'],

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
Expand Down
4 changes: 4 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
"@react-navigation/native-stack": "^6.9.12",
"@rneui/base": "^4.0.0-rc.7",
"@rneui/themed": "^4.0.0-rc.7",
"@sentry/react-native": "5.10.0",
"axios": "^1.4.0",
"expo": "^49.0.22",
"expo-application": "~5.3.0",
"expo-asset": "~8.10.1",
"expo-background-fetch": "~11.3.0",
"expo-constants": "~14.4.2",
"expo-crypto": "~12.4.1",
"expo-device": "~5.4.0",
"expo-file-system": "~15.4.5",
Expand All @@ -52,6 +55,7 @@
"react-native-screens": "~3.22.0",
"react-native-vector-icons": "^9.2.0",
"react-native-webview": "13.2.2",
"sentry-expo": "~7.1.0",
"yup": "^1.2.0"
},
"devDependencies": {
Expand Down
9 changes: 9 additions & 0 deletions app/setup-test-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable no-undef */
jest.mock('@sentry/react-native', () => ({
init: () => jest.fn(),
wrap: (node) => jest.fn(node),
ReactNativeTracing: () => jest.fn(),
ReactNavigationInstrumentation: (node) => jest.fn(node),
captureMessage: (msg) => jest.fn(msg),
captureException: (e) => jest.fn(e),
}));
4 changes: 0 additions & 4 deletions app/src/components/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ const SyncService = () => {
const activeJob = await crudJobs.getActiveJob(SYNC_FORM_SUBMISSION_TASK_NAME);
const settings = await crudConfig.getConfig();

// eslint-disable-next-line no-console
console.info('[ACTIVE JOB]', activeJob);

const { type: networkType } = await Network.getNetworkStateAsync();
if (settings?.syncWifiOnly && networkType !== Network.NetworkStateType.WIFI) {
return;
Expand Down Expand Up @@ -157,7 +154,6 @@ const SyncService = () => {
];
}

// console.log(apiURLs?.[0]?.url, 'is ip address same');
await Promise.all(
apiURLs.map(({ isCertification, ...u }) => downloadDatapointsJson(isCertification, u)),
);
Expand Down
3 changes: 3 additions & 0 deletions app/src/database/conn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Asset } from 'expo-asset';
import * as FileSystem from 'expo-file-system';
import * as SQLite from 'expo-sqlite';
import * as Sentry from '@sentry/react-native';

const openDatabase = () => {
const db = SQLite.openDatabase('db.db');
Expand Down Expand Up @@ -89,6 +90,8 @@ const removeDB = async () => {
}
return false;
} catch (error) {
Sentry.captureMessage('[conn] removeDB failed');
Sentry.captureException(error);
return Promise.reject(error);
}
};
Expand Down
4 changes: 3 additions & 1 deletion app/src/form/fields/TypeAutofield.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useMemo, useState } from 'react';
import { View } from 'react-native';
import { Input } from '@rneui/themed';
import PropTypes from 'prop-types';
import * as Sentry from '@sentry/react-native';

import { FieldLabel } from '../support';
import styles from '../styles';
Expand Down Expand Up @@ -148,7 +149,8 @@ const strToFunction = (id, fnString, values) => {
// eslint-disable-next-line no-new-func
return new Function(`return ${fnBody}`);
} catch (error) {
// console.error('[ERROR][TypeAutofield]', id, error, fnBody);
Sentry.captureMessage(`[TypeAutofield] question ID: ${id}`);
Sentry.captureException(error);
return false;
}
};
Expand Down
2 changes: 1 addition & 1 deletion app/src/form/fields/TypeGeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const TypeGeo = ({ keyform, id, label, value, tooltip, required, requiredSign, d
* accuracy number in meters, doc: https://docs.expo.dev/versions/latest/sdk/location/#locationgeocodedlocation
*/
setGpsAccuracy(Math.floor(accuracy));
// console.info('GPS accuracy:', accuracy, 'GPS Threshold:', gpsThreshold);

FormState.update((s) => {
s.currentValues = { ...s.currentValues, [id]: [lat, lng] };
});
Expand Down
Loading

0 comments on commit dcf5e9e

Please sign in to comment.