From 6122be6ddd13603a39a92c1d35e3cac66e140100 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Thu, 8 Aug 2024 13:45:12 +0200 Subject: [PATCH 01/31] Create Dockerfile for UI tests --- Dockerfile | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..40589f9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +FROM cimg/android:2024.07.1-node + +# Setup Android environment +ARG ARCH="x86_64" +ARG TARGET="google_apis_playstore" +ARG API_LEVEL="34" +ARG ANDROID_API_LEVEL="android-${API_LEVEL}" +ARG ANDROID_APIS="${TARGET};${ARCH}" +ARG EMULATOR_PACKAGE="system-images;${ANDROID_API_LEVEL};${ANDROID_APIS}" +ARG ANDROID_SDK_PACKAGES="${EMULATOR_PACKAGE}" +# Install system image for emulator. +RUN sdkmanager --verbose ${ANDROID_SDK_PACKAGES} +# Create new virtual device +RUN avdmanager --verbose create avd --name "pixel_7" --device "pixel_7" --package "system-images;android-34;google_apis_playstore;x86_64" + +WORKDIR /inrupt-wallet-frontend/ + +COPY android-config/ ./android-config/ +COPY api/ ./api/ +COPY app/ ./app/ +COPY assets/ ./assets/ +COPY components/ ./components/ +COPY constants/ ./constants/ +COPY e2e/ ./e2e/ +COPY hooks/ ./hooks/ +COPY plugins/ ./plugins/ +COPY types/ ./types/ +COPY utils/ ./utils/ +COPY .detoxrc.js app.config.ts metro.config.js package.json package-lock.json run-ui-tests.sh tsconfig.json ./ +# The APK must be compiled beforehand +# TODO: Add a test checking for its presence +COPY android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk . + +RUN chown circleci . + +ENV CI=true +ENV SIGNING_CONFIG_PATH=/inrupt-wallet-frontend/android-config/signing-config.gradle + +RUN echo "Installing the dependencies" +RUN npm ci + +# The following starts an emulator, it seems successfully +#emulator @pixel -no-snapshot -accel off -no-window -noaudio -no-boot-anim -camera-back none + +CMD ["bash", "-c", "npx detox test --configuration android.emu.release"] From e32694c828ee0a9864afbeef1ae9334ccf846dd0 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Thu, 8 Aug 2024 14:50:25 +0200 Subject: [PATCH 02/31] Add CI config to detox emulator --- .detoxrc.js | 5 ++++- Dockerfile | 15 +++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.detoxrc.js b/.detoxrc.js index e8ff3ea..211bfe7 100644 --- a/.detoxrc.js +++ b/.detoxrc.js @@ -47,7 +47,10 @@ module.exports = { type: 'android.emulator', device: { avdName: process.env.TEST_ANDROID_EMU - } + }, + // If running in CI, the emulator requires additional configuration options. + bootArgs: process.env.NODE_ENV === "development" ? "" : "-no-snapshot -accel off -noaudio -no-boot-anim -camera-back none", + headless: process.env.NODE_ENV !== "development" } }, configurations: { diff --git a/Dockerfile b/Dockerfile index 40589f9..e73162a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,11 @@ RUN sdkmanager --verbose ${ANDROID_SDK_PACKAGES} RUN avdmanager --verbose create avd --name "pixel_7" --device "pixel_7" --package "system-images;android-34;google_apis_playstore;x86_64" WORKDIR /inrupt-wallet-frontend/ +COPY package.json package-lock.json ./ +RUN echo "Installing the dependencies" +RUN npm ci +COPY .detoxrc.js app.config.ts metro.config.js tsconfig.json ./ COPY android-config/ ./android-config/ COPY api/ ./api/ COPY app/ ./app/ @@ -26,20 +30,15 @@ COPY hooks/ ./hooks/ COPY plugins/ ./plugins/ COPY types/ ./types/ COPY utils/ ./utils/ -COPY .detoxrc.js app.config.ts metro.config.js package.json package-lock.json run-ui-tests.sh tsconfig.json ./ # The APK must be compiled beforehand # TODO: Add a test checking for its presence -COPY android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk . +COPY android/app/build/outputs/apk/release/app-release.apk ./android/app/build/outputs/apk/release/app-release.apk +COPY android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk ./android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk RUN chown circleci . ENV CI=true ENV SIGNING_CONFIG_PATH=/inrupt-wallet-frontend/android-config/signing-config.gradle - -RUN echo "Installing the dependencies" -RUN npm ci - -# The following starts an emulator, it seems successfully -#emulator @pixel -no-snapshot -accel off -no-window -noaudio -no-boot-anim -camera-back none +ENV TEST_ANDROID_EMU="pixel_7" CMD ["bash", "-c", "npx detox test --configuration android.emu.release"] From 6def162e077b5132aaf75e16080b6f4b80771021 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 09:44:28 +0200 Subject: [PATCH 03/31] Enable hardware acceleration --- .detoxrc.js | 2 +- Dockerfile => e2e/docker/Dockerfile | 5 +++-- e2e/docker/run_docker_ui_tests.sh | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) rename Dockerfile => e2e/docker/Dockerfile (88%) create mode 100644 e2e/docker/run_docker_ui_tests.sh diff --git a/.detoxrc.js b/.detoxrc.js index 211bfe7..c58a50d 100644 --- a/.detoxrc.js +++ b/.detoxrc.js @@ -49,7 +49,7 @@ module.exports = { avdName: process.env.TEST_ANDROID_EMU }, // If running in CI, the emulator requires additional configuration options. - bootArgs: process.env.NODE_ENV === "development" ? "" : "-no-snapshot -accel off -noaudio -no-boot-anim -camera-back none", + bootArgs: process.env.NODE_ENV === "development" ? "" : "-no-snapshot -noaudio -no-boot-anim -camera-back none", headless: process.env.NODE_ENV !== "development" } }, diff --git a/Dockerfile b/e2e/docker/Dockerfile similarity index 88% rename from Dockerfile rename to e2e/docker/Dockerfile index e73162a..ad410d3 100644 --- a/Dockerfile +++ b/e2e/docker/Dockerfile @@ -18,7 +18,7 @@ COPY package.json package-lock.json ./ RUN echo "Installing the dependencies" RUN npm ci -COPY .detoxrc.js app.config.ts metro.config.js tsconfig.json ./ +COPY --chown=circleci .detoxrc.js app.config.ts metro.config.js tsconfig.json run_docker_ui_tests.sh ./ COPY android-config/ ./android-config/ COPY api/ ./api/ COPY app/ ./app/ @@ -36,9 +36,10 @@ COPY android/app/build/outputs/apk/release/app-release.apk ./android/app/build/o COPY android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk ./android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk RUN chown circleci . +RUN chmod u+x run_docker_ui_tests.sh ENV CI=true ENV SIGNING_CONFIG_PATH=/inrupt-wallet-frontend/android-config/signing-config.gradle ENV TEST_ANDROID_EMU="pixel_7" -CMD ["bash", "-c", "npx detox test --configuration android.emu.release"] +CMD ["bash", "-c", "./run_docker_ui_tests.sh"] diff --git a/e2e/docker/run_docker_ui_tests.sh b/e2e/docker/run_docker_ui_tests.sh new file mode 100644 index 0000000..db76e9d --- /dev/null +++ b/e2e/docker/run_docker_ui_tests.sh @@ -0,0 +1,8 @@ +#! /bin/bash + +# Enable QEmu hardware acceleration. +sudo chown circleci -R /dev/kvm +echo "kvm:x:200:circleci" | sudo tee -a /etc/group + +# Run the tests +npx detox test --configuration android.emu.release --loglevel verbose From c1b28179309779f2fa622a37a703e4ce6e9c18f3 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 10:26:11 +0200 Subject: [PATCH 04/31] Move files to root --- e2e/docker/Dockerfile => Dockerfile | 4 ++-- e2e/pages/PermissionPage.ts | 10 ++++++---- .../run_docker_ui_tests.sh => run_docker_ui_tests.sh | 0 3 files changed, 8 insertions(+), 6 deletions(-) rename e2e/docker/Dockerfile => Dockerfile (95%) rename e2e/docker/run_docker_ui_tests.sh => run_docker_ui_tests.sh (100%) diff --git a/e2e/docker/Dockerfile b/Dockerfile similarity index 95% rename from e2e/docker/Dockerfile rename to Dockerfile index ad410d3..eb25581 100644 --- a/e2e/docker/Dockerfile +++ b/Dockerfile @@ -15,11 +15,11 @@ RUN avdmanager --verbose create avd --name "pixel_7" --device "pixel_7" --packag WORKDIR /inrupt-wallet-frontend/ COPY package.json package-lock.json ./ -RUN echo "Installing the dependencies" + RUN npm ci COPY --chown=circleci .detoxrc.js app.config.ts metro.config.js tsconfig.json run_docker_ui_tests.sh ./ -COPY android-config/ ./android-config/ +COPY ../../android-config/ ./android-config/ COPY api/ ./api/ COPY app/ ./app/ COPY assets/ ./assets/ diff --git a/e2e/pages/PermissionPage.ts b/e2e/pages/PermissionPage.ts index b556201..d80bcbd 100644 --- a/e2e/pages/PermissionPage.ts +++ b/e2e/pages/PermissionPage.ts @@ -18,20 +18,22 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // + +import { expect, web, by } from "detox"; + class PermissionPage { private continueButton: Detox.WebElement; constructor() { this.continueButton = web.element( - by.web.xpath('//button[text()="Continue"]') + by.web.cssSelector('button[data-testid="prompt-continue"]') ); } async clickContinueButton() { + await expect(this.continueButton).toExist(); // await waitFor(this.continueButton).toExist().withTimeout(5000); - await this.continueButton.runScript((element: HTMLButtonElement) => { - element.click(); - }); + await this.continueButton.tap(); } } diff --git a/e2e/docker/run_docker_ui_tests.sh b/run_docker_ui_tests.sh similarity index 100% rename from e2e/docker/run_docker_ui_tests.sh rename to run_docker_ui_tests.sh From 139758a5204c921573b245fe90823aee9986311d Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 10:26:29 +0200 Subject: [PATCH 05/31] Add UI tests to CI This is an initial test to see if hardware acceleration works in CI --- .github/workflows/ci.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df489c3..41b1d38 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,22 @@ jobs: - uses: actions/setup-node@v4 - run: npm ci + ui-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # Build the docker image containing the Android emulator and all the test dependencies. + - run: | + docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test . + # Run the Detox tests in the emulator container. + - run: | + docker run -it \ + --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ + --env EXPO_PUBLIC_WALLET_API="https://datawallet.inrupt.com" \ + # FIXME read these from secrets, this is just for initial testing + --env TEST_ACCOUNT_USERNAME="some-username" \ + --env TEST_ACCOUNT_PASSWORD="some-password" \ + inrupt-wallet-frontend-ui-tests:test sonarqube: name: run sonarqube if: ${{ github.actor != 'dependabot[bot]' }} @@ -41,4 +57,4 @@ jobs: uses: kitabisa/sonarqube-action@v1.2.1 with: host: ${{ secrets.SONARQUBE_HOST }} - login: ${{ secrets.SONARQUBE_DEV_INRUPT_COM_GITHUB_TOKEN }} \ No newline at end of file + login: ${{ secrets.SONARQUBE_DEV_INRUPT_COM_GITHUB_TOKEN }} From 663fb32bcf40dea91c1579ac4f7fa2627fd22d3d Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 10:30:37 +0200 Subject: [PATCH 06/31] fixup! Add UI tests to CI --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41b1d38..97b9878 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + - run: npm ci + # Build the test apk to be loaded in the container. + - run: npx detox build --configuration android.emu.release # Build the docker image containing the Android emulator and all the test dependencies. - run: | docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test . From d5ad5fda6f71a18dbd084687e7a6b5b386b6ac55 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 10:53:44 +0200 Subject: [PATCH 07/31] fixup! fixup! Add UI tests to CI --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 97b9878..83a04d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,8 +31,14 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 17 + cache: 'maven' - run: npm ci # Build the test apk to be loaded in the container. + - run: npx expo prebuild --platform android - run: npx detox build --configuration android.emu.release # Build the docker image containing the Android emulator and all the test dependencies. - run: | From 11691400b58b352ea329efd81c4f718d734dfa67 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 10:56:56 +0200 Subject: [PATCH 08/31] fixup! fixup! fixup! Add UI tests to CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83a04d6..de11826 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,7 +35,7 @@ jobs: with: distribution: 'temurin' java-version: 17 - cache: 'maven' + cache: 'gradle' - run: npm ci # Build the test apk to be loaded in the container. - run: npx expo prebuild --platform android From 859b52a99a46d74c0d892dcfa5e8a02b3c17b27d Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 11:03:13 +0200 Subject: [PATCH 09/31] fixup! fixup! fixup! fixup! Add UI tests to CI --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de11826..c45b687 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,8 @@ jobs: - run: npm ci # Build the test apk to be loaded in the container. - run: npx expo prebuild --platform android + env: + SIGNING_CONFIG_PATH: ${{ github.workspace }}/android-config/signing-config.gradle - run: npx detox build --configuration android.emu.release # Build the docker image containing the Android emulator and all the test dependencies. - run: | From 73712d8c2a7eeeb32def2b1c1f0753b505eb5982 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 11:46:09 +0200 Subject: [PATCH 10/31] Add hardware acceleration check --- run_docker_ui_tests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run_docker_ui_tests.sh b/run_docker_ui_tests.sh index db76e9d..c483ef0 100644 --- a/run_docker_ui_tests.sh +++ b/run_docker_ui_tests.sh @@ -3,6 +3,8 @@ # Enable QEmu hardware acceleration. sudo chown circleci -R /dev/kvm echo "kvm:x:200:circleci" | sudo tee -a /etc/group +# Check that hardware emulation is enabled. +emulator -accel-check # Run the tests npx detox test --configuration android.emu.release --loglevel verbose From bb7c8aaf89c6dfde6cfb12078aac2b31e8684d41 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 13:10:21 +0200 Subject: [PATCH 11/31] Minimal test for hardware acceleration --- .github/workflows/ci.yml | 49 +++++++++++++++++++++++++++------------- Dockerfile.minimal | 45 ++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 Dockerfile.minimal diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c45b687..5839b1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,26 +26,12 @@ jobs: - uses: actions/setup-node@v4 - run: npm ci - ui-tests: + hw-acceleration-sanity-check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: 17 - cache: 'gradle' - - run: npm ci - # Build the test apk to be loaded in the container. - - run: npx expo prebuild --platform android - env: - SIGNING_CONFIG_PATH: ${{ github.workspace }}/android-config/signing-config.gradle - - run: npx detox build --configuration android.emu.release - # Build the docker image containing the Android emulator and all the test dependencies. - run: | - docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test . - # Run the Detox tests in the emulator container. + docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test ./Docker.minimal - run: | docker run -it \ --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ @@ -54,6 +40,37 @@ jobs: --env TEST_ACCOUNT_USERNAME="some-username" \ --env TEST_ACCOUNT_PASSWORD="some-password" \ inrupt-wallet-frontend-ui-tests:test + # ui-tests: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v4 + # - uses: actions/setup-node@v4 + # - uses: actions/setup-java@v4 + # with: + # distribution: 'temurin' + # java-version: 17 + # cache: 'gradle' + # - run: echo "${{ secrets.ENCRYPTED_KEYSTORE }}" > wallet.keystore.asc + # - run: gpg -d --passphrase "${{ secrets.KEYSTORE_DECRYPTION_KEY }}" --batch wallet.keystore.asc > wallet.keystore + # - run: npm ci + # # Build the test apk to be loaded in the container. + # - run: npx expo prebuild --platform android + # env: + # SIGNING_CONFIG_PATH: ${{ github.workspace }}/android-config/signing-config.gradle + # - run: npx detox build --configuration android.emu.release + # # Build the docker image containing the Android emulator and all the test dependencies. + # - run: | + # docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test . + # # Run the Detox tests in the emulator container. + # - run: | + # docker run -it \ + # --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ + # --env EXPO_PUBLIC_WALLET_API="https://datawallet.inrupt.com" \ + # # FIXME read these from secrets, this is just for initial testing + # --env TEST_ACCOUNT_USERNAME="some-username" \ + # --env TEST_ACCOUNT_PASSWORD="some-password" \ + # inrupt-wallet-frontend-ui-tests:test + sonarqube: name: run sonarqube if: ${{ github.actor != 'dependabot[bot]' }} diff --git a/Dockerfile.minimal b/Dockerfile.minimal new file mode 100644 index 0000000..b057110 --- /dev/null +++ b/Dockerfile.minimal @@ -0,0 +1,45 @@ +FROM cimg/android:2024.07.1-node + +# Setup Android environment +ARG ARCH="x86_64" +ARG TARGET="google_apis_playstore" +ARG API_LEVEL="34" +ARG ANDROID_API_LEVEL="android-${API_LEVEL}" +ARG ANDROID_APIS="${TARGET};${ARCH}" +ARG EMULATOR_PACKAGE="system-images;${ANDROID_API_LEVEL};${ANDROID_APIS}" +ARG ANDROID_SDK_PACKAGES="${EMULATOR_PACKAGE}" +# Install system image for emulator. +RUN sdkmanager --verbose ${ANDROID_SDK_PACKAGES} +# Create new virtual device +RUN avdmanager --verbose create avd --name "pixel_7" --device "pixel_7" --package "system-images;android-34;google_apis_playstore;x86_64" + +WORKDIR /inrupt-wallet-frontend/ +COPY package.json package-lock.json ./ + +# RUN npm ci + +COPY --chown=circleci .detoxrc.js app.config.ts metro.config.js tsconfig.json run_docker_ui_tests.sh ./ +# COPY ../../android-config/ ./android-config/ +# COPY api/ ./api/ +# COPY app/ ./app/ +# COPY assets/ ./assets/ +# COPY components/ ./components/ +# COPY constants/ ./constants/ +# COPY e2e/ ./e2e/ +# COPY hooks/ ./hooks/ +# COPY plugins/ ./plugins/ +# COPY types/ ./types/ +# COPY utils/ ./utils/ +# The APK must be compiled beforehand +# TODO: Add a test checking for its presence +# COPY android/app/build/outputs/apk/release/app-release.apk ./android/app/build/outputs/apk/release/app-release.apk +# COPY android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk ./android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk + +RUN chown circleci . +RUN chmod u+x run_docker_ui_tests.sh + +ENV CI=true +ENV SIGNING_CONFIG_PATH=/inrupt-wallet-frontend/android-config/signing-config.gradle +ENV TEST_ANDROID_EMU="pixel_7" + +CMD ["bash", "-c", "./run_docker_ui_tests.sh"] From f2702e6799aa7433083052337647983fa33fa027 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 13:16:42 +0200 Subject: [PATCH 12/31] fixup! Minimal test for hardware acceleration --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5839b1f..4ada21b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: steps: - uses: actions/checkout@v4 - run: | - docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test ./Docker.minimal + docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test ./Dockerfile.minimal - run: | docker run -it \ --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ From 330cfaf15bd3669c92a1cdc47512ac1af6fde791 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 13:24:53 +0200 Subject: [PATCH 13/31] fixup! fixup! Minimal test for hardware acceleration --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ada21b..c0aec2e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,8 +30,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - run: | - docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test ./Dockerfile.minimal + docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test --file=Dockerfile.minimal . - run: | docker run -it \ --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ From c8d00fbfe16705c477c78f51eae21a33bc7bfa83 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 13:31:47 +0200 Subject: [PATCH 14/31] fixup! fixup! fixup! Minimal test for hardware acceleration --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0aec2e..e2a4b1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,10 +34,10 @@ jobs: - run: | docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test --file=Dockerfile.minimal . - run: | + # FIXME read these from secrets, this is just for initial testing docker run -it \ --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ --env EXPO_PUBLIC_WALLET_API="https://datawallet.inrupt.com" \ - # FIXME read these from secrets, this is just for initial testing --env TEST_ACCOUNT_USERNAME="some-username" \ --env TEST_ACCOUNT_PASSWORD="some-password" \ inrupt-wallet-frontend-ui-tests:test From d246f7107ee223be66c4d89b3056f7efaf938754 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 13:36:57 +0200 Subject: [PATCH 15/31] fixup! fixup! fixup! fixup! Minimal test for hardware acceleration --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2a4b1f..2210f3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,6 @@ jobs: - run: | docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test --file=Dockerfile.minimal . - run: | - # FIXME read these from secrets, this is just for initial testing docker run -it \ --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ --env EXPO_PUBLIC_WALLET_API="https://datawallet.inrupt.com" \ From d25d1b91f8a8b62049f2214e645cca8da3dbb515 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 13:45:50 +0200 Subject: [PATCH 16/31] fixup! fixup! fixup! fixup! fixup! Minimal test for hardware acceleration --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2210f3a..f7c21a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: - run: | docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test --file=Dockerfile.minimal . - run: | - docker run -it \ + docker run \ --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ --env EXPO_PUBLIC_WALLET_API="https://datawallet.inrupt.com" \ --env TEST_ACCOUNT_USERNAME="some-username" \ From 00f04e8d28af7b5edc907ac06d8d24cc3e174013 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 13:52:59 +0200 Subject: [PATCH 17/31] fixup! fixup! fixup! fixup! fixup! fixup! Minimal test for hardware acceleration --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7c21a2..b727ff6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: - run: | docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test --file=Dockerfile.minimal . - run: | - docker run \ + docker run --privileged --device /dev/kvm \ --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ --env EXPO_PUBLIC_WALLET_API="https://datawallet.inrupt.com" \ --env TEST_ACCOUNT_USERNAME="some-username" \ From 6316133457744862e97ce3fbc9c9c6b3627217f1 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 14:06:26 +0200 Subject: [PATCH 18/31] Get keystore config from environment Previously, the keystore configuration was stored in the global gradle configuration, which is fine for dev machines, but more problematic for CI. Keystore configuration now comes from environment variables, which is easier to manipulate in CI. --- README.md | 8 +++---- android-config/signing-config.gradle | 14 +++++++---- plugins/withSigningConfig.js | 36 +++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c08fbf9..aab7888 100644 --- a/README.md +++ b/README.md @@ -64,12 +64,10 @@ keytool -genkeypair -v -storetype PKCS12 \ -noprompt -dname "CN=wallet.example.com" ``` -Add the following to: `~/.gradle/gradle.properties` and update the placeholders. +Add the following to: `.env` and update the placeholders. ```text -WALLET_UPLOAD_STORE_FILE=/inrupt-wallet-frontend/android/app/wallet.keystore -WALLET_UPLOAD_STORE_PASSWORD= -WALLET_UPLOAD_KEY_ALIAS=wallet -WALLET_UPLOAD_KEY_PASSWORD= +KEYSTORE_PATH=/inrupt-wallet-frontend/android/app/wallet.keystore +KEYSTORE_PASSWORD= ``` ## Running the application diff --git a/android-config/signing-config.gradle b/android-config/signing-config.gradle index 0d6dd16..161d859 100644 --- a/android-config/signing-config.gradle +++ b/android-config/signing-config.gradle @@ -1,11 +1,15 @@ android { signingConfigs { release { - if (project.hasProperty('WALLET_UPLOAD_STORE_FILE')) { - storeFile file(WALLET_UPLOAD_STORE_FILE) - storePassword WALLET_UPLOAD_STORE_PASSWORD - keyAlias WALLET_UPLOAD_KEY_ALIAS - keyPassword WALLET_UPLOAD_KEY_PASSWORD + // inrupt.wallet.frontend.keystore.file=/inrupt-wallet-frontend/android/app/wallet.keystore + // inrupt.wallet.frontend.keystore.password= + // inrupt.wallet.frontend.key.alias=wallet + // inrupt.wallet.frontend.key.password= + if (project.hasProperty('inrupt.wallet.frontend.keystore.file')) { + storeFile file(inrupt.wallet.frontend.keystore.file) + storePassword inrupt.wallet.frontend.keystore.password + keyAlias inrupt.wallet.frontend.key.alias + keyPassword inrupt.wallet.frontend.key.password } } } diff --git a/plugins/withSigningConfig.js b/plugins/withSigningConfig.js index d2a265b..fec78fc 100644 --- a/plugins/withSigningConfig.js +++ b/plugins/withSigningConfig.js @@ -28,18 +28,48 @@ module.exports = function withSigningConfig(config) { // Add path to gradle signing snippet to gradle.properties. // This is then used by the android/app/build.gradle mod. withGradleProperties(config, async (gradleProps) => { + if (process.env.SIGNING_CONFIG_PATH === undefined) { + throw new Error("Missing environment variable SIGNING_CONFIG_PATH"); + } gradleProps.modResults.push({ type: "comment", value: "Path to the signing configuration gradle snippet", }); - if (process.env.SIGNING_CONFIG_PATH === undefined) { - throw new Error("Missing environment variable SIGNING_CONFIG_PATH"); - } gradleProps.modResults.push({ type: "property", key: "inrupt.wallet.frontend.signing", value: process.env.SIGNING_CONFIG_PATH, }); + if (process.env.KEYSTORE_PATH === undefined) { + throw new Error("Missing environment variable KEYSTORE_PATH"); + } + if (process.env.KEYSTORE_PASSWORD === undefined) { + throw new Error("Missing environment variable KEYSTORE_PASSWORD"); + } + gradleProps.modResults.push({ + type: "comment", + value: "Keystore configuration for app signing.", + }); + gradleProps.modResults.push({ + type: "property", + key: "inrupt.wallet.frontend.keystore.file", + value: process.env.KEYSTORE_PATH, + }); + gradleProps.modResults.push({ + type: "property", + key: "inrupt.wallet.frontend.keystore.password", + value: process.env.KEYSTORE_PASSWORD, + }); + gradleProps.modResults.push({ + type: "property", + key: "inrupt.wallet.frontend.key.alias", + value: "wallet", + }); + gradleProps.modResults.push({ + type: "property", + key: "inrupt.wallet.frontend.key.password", + value: process.env.KEYSTORE_PASSWORD, + }); return gradleProps; }); // Append a block to android/app/build.gradle to reuse signing config From 916f3adf2cf88dc15fb36ec652ccf40dc5ac46a4 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 14:10:45 +0200 Subject: [PATCH 19/31] Remove HW acceleration experiment HW acceleration is available in the CI runner. --- .github/workflows/ci.yml | 55 ++++++++++++++++++---------------------- Dockerfile.minimal | 45 -------------------------------- 2 files changed, 24 insertions(+), 76 deletions(-) delete mode 100644 Dockerfile.minimal diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b727ff6..9827a96 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,43 +33,36 @@ jobs: - run: | docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test --file=Dockerfile.minimal . + ui-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 17 + cache: 'gradle' + - run: echo "${{ secrets.ENCRYPTED_KEYSTORE }}" > wallet.keystore.asc + - run: gpg -d --passphrase "${{ secrets.KEYSTORE_DECRYPTION_KEY }}" --batch wallet.keystore.asc > wallet.keystore + - run: npm ci + # Build the test apk to be loaded in the container. + - run: npx expo prebuild --platform android + env: + SIGNING_CONFIG_PATH: ${{ github.workspace }}/android-config/signing-config.gradle + - run: npx detox build --configuration android.emu.release + # Build the docker image containing the Android emulator and all the test dependencies. + - run: | + docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test . + # Run the Detox tests in the emulator container. - run: | - docker run --privileged --device /dev/kvm \ + docker run -it \ --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ --env EXPO_PUBLIC_WALLET_API="https://datawallet.inrupt.com" \ + # FIXME read these from secrets, this is just for initial testing --env TEST_ACCOUNT_USERNAME="some-username" \ --env TEST_ACCOUNT_PASSWORD="some-password" \ inrupt-wallet-frontend-ui-tests:test - # ui-tests: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v4 - # - uses: actions/setup-node@v4 - # - uses: actions/setup-java@v4 - # with: - # distribution: 'temurin' - # java-version: 17 - # cache: 'gradle' - # - run: echo "${{ secrets.ENCRYPTED_KEYSTORE }}" > wallet.keystore.asc - # - run: gpg -d --passphrase "${{ secrets.KEYSTORE_DECRYPTION_KEY }}" --batch wallet.keystore.asc > wallet.keystore - # - run: npm ci - # # Build the test apk to be loaded in the container. - # - run: npx expo prebuild --platform android - # env: - # SIGNING_CONFIG_PATH: ${{ github.workspace }}/android-config/signing-config.gradle - # - run: npx detox build --configuration android.emu.release - # # Build the docker image containing the Android emulator and all the test dependencies. - # - run: | - # docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test . - # # Run the Detox tests in the emulator container. - # - run: | - # docker run -it \ - # --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ - # --env EXPO_PUBLIC_WALLET_API="https://datawallet.inrupt.com" \ - # # FIXME read these from secrets, this is just for initial testing - # --env TEST_ACCOUNT_USERNAME="some-username" \ - # --env TEST_ACCOUNT_PASSWORD="some-password" \ - # inrupt-wallet-frontend-ui-tests:test sonarqube: name: run sonarqube diff --git a/Dockerfile.minimal b/Dockerfile.minimal deleted file mode 100644 index b057110..0000000 --- a/Dockerfile.minimal +++ /dev/null @@ -1,45 +0,0 @@ -FROM cimg/android:2024.07.1-node - -# Setup Android environment -ARG ARCH="x86_64" -ARG TARGET="google_apis_playstore" -ARG API_LEVEL="34" -ARG ANDROID_API_LEVEL="android-${API_LEVEL}" -ARG ANDROID_APIS="${TARGET};${ARCH}" -ARG EMULATOR_PACKAGE="system-images;${ANDROID_API_LEVEL};${ANDROID_APIS}" -ARG ANDROID_SDK_PACKAGES="${EMULATOR_PACKAGE}" -# Install system image for emulator. -RUN sdkmanager --verbose ${ANDROID_SDK_PACKAGES} -# Create new virtual device -RUN avdmanager --verbose create avd --name "pixel_7" --device "pixel_7" --package "system-images;android-34;google_apis_playstore;x86_64" - -WORKDIR /inrupt-wallet-frontend/ -COPY package.json package-lock.json ./ - -# RUN npm ci - -COPY --chown=circleci .detoxrc.js app.config.ts metro.config.js tsconfig.json run_docker_ui_tests.sh ./ -# COPY ../../android-config/ ./android-config/ -# COPY api/ ./api/ -# COPY app/ ./app/ -# COPY assets/ ./assets/ -# COPY components/ ./components/ -# COPY constants/ ./constants/ -# COPY e2e/ ./e2e/ -# COPY hooks/ ./hooks/ -# COPY plugins/ ./plugins/ -# COPY types/ ./types/ -# COPY utils/ ./utils/ -# The APK must be compiled beforehand -# TODO: Add a test checking for its presence -# COPY android/app/build/outputs/apk/release/app-release.apk ./android/app/build/outputs/apk/release/app-release.apk -# COPY android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk ./android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk - -RUN chown circleci . -RUN chmod u+x run_docker_ui_tests.sh - -ENV CI=true -ENV SIGNING_CONFIG_PATH=/inrupt-wallet-frontend/android-config/signing-config.gradle -ENV TEST_ANDROID_EMU="pixel_7" - -CMD ["bash", "-c", "./run_docker_ui_tests.sh"] From 5afcf54ec6d164b57a480a533db759fe4bfc8915 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 14:17:27 +0200 Subject: [PATCH 20/31] Setup CI keystore configuration --- .github/workflows/ci.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9827a96..a6c6951 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,10 +53,15 @@ jobs: - run: npx detox build --configuration android.emu.release # Build the docker image containing the Android emulator and all the test dependencies. - run: | - docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test . + docker build \ + --network=host \ + --tag inrupt-wallet-frontend-ui-tests:test \ + --env KEYSTORE_PATH=${{ github.workspace }}/wallet.keystore + --env KEYSTORE_PASSWORD="${{ secrets.KEYSTORE_PASSWORD }}" + . # Run the Detox tests in the emulator container. - run: | - docker run -it \ + docker run \ --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ --env EXPO_PUBLIC_WALLET_API="https://datawallet.inrupt.com" \ # FIXME read these from secrets, this is just for initial testing From 49109c79a353e48dfb725745b10b0b6a77e24e5d Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 14:18:55 +0200 Subject: [PATCH 21/31] fixup! Remove HW acceleration experiment --- .github/workflows/ci.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a6c6951..e271833 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,13 +26,6 @@ jobs: - uses: actions/setup-node@v4 - run: npm ci - hw-acceleration-sanity-check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - run: | - docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test --file=Dockerfile.minimal . ui-tests: runs-on: ubuntu-latest steps: From 2e08be653ac373844f6339beb2de5d77c747f56a Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 14:26:36 +0200 Subject: [PATCH 22/31] fixup! Setup CI keystore configuration --- .github/workflows/ci.yml | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e271833..9fa76c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,24 +36,27 @@ jobs: distribution: 'temurin' java-version: 17 cache: 'gradle' - - run: echo "${{ secrets.ENCRYPTED_KEYSTORE }}" > wallet.keystore.asc - - run: gpg -d --passphrase "${{ secrets.KEYSTORE_DECRYPTION_KEY }}" --batch wallet.keystore.asc > wallet.keystore + - name: Dump the encrypted keystore into a file + run: echo "${{ secrets.ENCRYPTED_KEYSTORE }}" > wallet.keystore.asc + - name: Decrypt the keystore into its canonical location + run: gpg -d --passphrase "${{ secrets.KEYSTORE_DECRYPTION_KEY }}" --batch wallet.keystore.asc > wallet.keystore - run: npm ci - # Build the test apk to be loaded in the container. - - run: npx expo prebuild --platform android + - name: Generate the android metadata files + run: npx expo prebuild --platform android env: + KEYSTORE_PATH: ${{ github.workspace }}/wallet.keystore + KEYSTORE_PASSWORD: "${{ secrets.KEYSTORE_PASSWORD }}" SIGNING_CONFIG_PATH: ${{ github.workspace }}/android-config/signing-config.gradle - - run: npx detox build --configuration android.emu.release - # Build the docker image containing the Android emulator and all the test dependencies. - - run: | + - name: Build the APK to be uploaded in the test container + run: npx detox build --configuration android.emu.release + - name: Build the docker image containing the Android emulator and all the test dependencies. + run: | docker build \ --network=host \ --tag inrupt-wallet-frontend-ui-tests:test \ - --env KEYSTORE_PATH=${{ github.workspace }}/wallet.keystore - --env KEYSTORE_PASSWORD="${{ secrets.KEYSTORE_PASSWORD }}" . - # Run the Detox tests in the emulator container. - - run: | + - name: Run the Detox tests in the emulator container + run: | docker run \ --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ --env EXPO_PUBLIC_WALLET_API="https://datawallet.inrupt.com" \ From a0a990e1c311cbd9433333688ab4ff5365afa71d Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 14:29:38 +0200 Subject: [PATCH 23/31] fixup! fixup! Setup CI keystore configuration --- android-config/signing-config.gradle | 4 ---- 1 file changed, 4 deletions(-) diff --git a/android-config/signing-config.gradle b/android-config/signing-config.gradle index 161d859..1bbd1d0 100644 --- a/android-config/signing-config.gradle +++ b/android-config/signing-config.gradle @@ -1,10 +1,6 @@ android { signingConfigs { release { - // inrupt.wallet.frontend.keystore.file=/inrupt-wallet-frontend/android/app/wallet.keystore - // inrupt.wallet.frontend.keystore.password= - // inrupt.wallet.frontend.key.alias=wallet - // inrupt.wallet.frontend.key.password= if (project.hasProperty('inrupt.wallet.frontend.keystore.file')) { storeFile file(inrupt.wallet.frontend.keystore.file) storePassword inrupt.wallet.frontend.keystore.password From ae0a2854e8ab7b044d77e272b6e48484412e015c Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 14:40:15 +0200 Subject: [PATCH 24/31] fixup! fixup! fixup! Setup CI keystore configuration --- android-config/signing-config.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/android-config/signing-config.gradle b/android-config/signing-config.gradle index 1bbd1d0..177b7fc 100644 --- a/android-config/signing-config.gradle +++ b/android-config/signing-config.gradle @@ -2,10 +2,10 @@ android { signingConfigs { release { if (project.hasProperty('inrupt.wallet.frontend.keystore.file')) { - storeFile file(inrupt.wallet.frontend.keystore.file) - storePassword inrupt.wallet.frontend.keystore.password - keyAlias inrupt.wallet.frontend.key.alias - keyPassword inrupt.wallet.frontend.key.password + storeFile file(project.property('inrupt.wallet.frontend.keystore.file')) + storePassword project.property('inrupt.wallet.frontend.keystore.password') + keyAlias project.property('inrupt.wallet.frontend.key.alias') + keyPassword project.property('inrupt.wallet.frontend.key.password') } } } From 32d4335ce7aeb7d60de75af85b4d8083dea50e45 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 12 Aug 2024 16:15:22 +0200 Subject: [PATCH 25/31] Document keystore management --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index aab7888..cb9af1f 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,18 @@ KEYSTORE_PATH=/inrupt-wallet-frontend/android/app/wallet.keystore KEYSTORE_PASSWORD= ``` +#### Make the keystore available to CI + +In order to make the keystore available to CI, it has to be present in the repository secret. +To +- Encrypting the keystore with a GPG key to get a Base64 representation: `gpg -c --armor wallet.keystore` +- Create Github repository secrets: + - ENCRYPTED_KEYSTORE with the Base64-encoded encrypted keystore + - KEYSTORE_DECRYPTION_KEY with the GPG key + - KEYSTORE_PASSWORD with the keystore password +- In CI, decrypt the keystore back: `gpg -d --passphrase "..." --batch wallet.keystore.asc > wallet.keystore` + + ## Running the application If you are going to run the application in an emulator or simulator, you need to build the development version using From c9bd8917703e04110b0f97128850006cb0460c90 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Tue, 13 Aug 2024 10:53:56 +0200 Subject: [PATCH 26/31] Adjust Detox tests to run in Docker --- .detoxrc.js | 23 ++++++++++++++++++++--- Dockerfile | 1 + README.md | 27 ++++++++++++++++++++++++--- e2e/pages/LoginPage.ts | 17 ++++++++--------- e2e/pages/PermissionPage.ts | 1 - run_docker_ui_tests.sh | 4 +++- 6 files changed, 56 insertions(+), 17 deletions(-) diff --git a/.detoxrc.js b/.detoxrc.js index c58a50d..27bd6b5 100644 --- a/.detoxrc.js +++ b/.detoxrc.js @@ -49,8 +49,8 @@ module.exports = { avdName: process.env.TEST_ANDROID_EMU }, // If running in CI, the emulator requires additional configuration options. - bootArgs: process.env.NODE_ENV === "development" ? "" : "-no-snapshot -noaudio -no-boot-anim -camera-back none", - headless: process.env.NODE_ENV !== "development" + bootArgs: process.env.NODE_ENV === "docker" ? "" : "-no-snapshot -noaudio -no-boot-anim -camera-back none", + headless: process.env.NODE_ENV === "docker" } }, configurations: { @@ -72,6 +72,23 @@ module.exports = { } }, custom: { - defaultTestTimeout: 5000 + defaultTestTimeout: 15000 + }, + artifacts: { + rootDir: process.env.NODE_ENV === "docker" ? "/screenshots/" : "./screenshots/", + plugins: { + log: {"enabled": true}, + uiHierarchy: {"enabled": true}, + screenshot: { + keepOnlyFailedTestsArtifacts: false, + takeWhen: { + "testStart": true, + "testDone": true + } + }, + video: { + enabled: true + } + } } }; diff --git a/Dockerfile b/Dockerfile index eb25581..63dcf88 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,5 +41,6 @@ RUN chmod u+x run_docker_ui_tests.sh ENV CI=true ENV SIGNING_CONFIG_PATH=/inrupt-wallet-frontend/android-config/signing-config.gradle ENV TEST_ANDROID_EMU="pixel_7" +ENV NODE_ENV="docker" CMD ["bash", "-c", "./run_docker_ui_tests.sh"] diff --git a/README.md b/README.md index cb9af1f..517d9ad 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,6 @@ To - KEYSTORE_PASSWORD with the keystore password - In CI, decrypt the keystore back: `gpg -d --passphrase "..." --batch wallet.keystore.asc > wallet.keystore` - ## Running the application If you are going to run the application in an emulator or simulator, you need to build the development version using @@ -114,7 +113,7 @@ The tests require access credentials for a Pod which will be used by this instan Make a copy of the provided `.env.sample` named `.env`, and replace placeholders with actual values specific to your setup. -#### Running the tests on iOS +### Running the tests on iOS To build the iOS wallet app in an iOS simulator, just run the following command: @@ -144,7 +143,7 @@ Execute the command below to start Detox test on iOS. npx detox test --configuration=ios.sim.release ``` -#### Running the tests on Android +### Running the tests on Android Ensure that a virtual device has been added to the Android emulator. @@ -177,6 +176,28 @@ After completion, the binary apps will be located in: You can share the .apk files with others who need to run the Detox tests without building the Android app locally. +### Running the tests in Docker + +The UI-based tests can be packaged to run in Docker (experimental at the time of writing). + +- Follow the build steps above (keystore, detox android build) to generate the release build with the Detox version of the APK. +- Build the docker container from the provided Dockerfile: +``` +docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test . +``` +- Run the docker container (after replacing the placeholders) +``` +docker run -it \ + --privileged \ + --device /dev/kvm \ + --mount type=bind,source=./screenshots/,target=/screenshots \ + --env TEST_ACCOUNT_USERNAME= \ + --env TEST_ACCOUNT_PASSWORD= \ + --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ + --env EXPO_PUBLIC_WALLET_API="https://datawallet.inrupt.com" \ + inrupt-wallet-frontend-ui-tests:test +``` + ## UI overview Upon execution, the application prompts the user to log in. After successful authentication, the wallet app presents various views, located in the `app/(tabs)` directory: diff --git a/e2e/pages/LoginPage.ts b/e2e/pages/LoginPage.ts index ffba44d..908fb5e 100644 --- a/e2e/pages/LoginPage.ts +++ b/e2e/pages/LoginPage.ts @@ -19,6 +19,7 @@ // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // import { by, element, expect, web } from "detox"; + import detoxConfig from "../../.detoxrc"; import HomePage from "./HomePage"; import PermissionPage from "./PermissionPage"; @@ -58,20 +59,18 @@ class LoginPage { // Perform login await expect(this.signInFormUsernameInput).toExist(); - await this.signInFormUsernameInput.runScript(`(element) => { - element.value = "${username}"; - }`); + await this.signInFormUsernameInput.replaceText(username); await expect(this.signInFormPasswordInput).toExist(); - await this.signInFormPasswordInput.runScript(`(element) => { - element.value = "${password}"; - }`); + await this.signInFormPasswordInput.replaceText(password); - await expect(this.signInSubmitButton).toExist(); - await this.signInSubmitButton.runScript((buttonElement) => { - buttonElement.click(); + await new Promise((resolve) => { + setTimeout(resolve, timeout * 5); }); + await expect(this.signInSubmitButton).toExist(); + await this.signInSubmitButton.tap(); + // Handle permission screen await new Promise((resolve) => { setTimeout(resolve, timeout); diff --git a/e2e/pages/PermissionPage.ts b/e2e/pages/PermissionPage.ts index d80bcbd..2ffe25d 100644 --- a/e2e/pages/PermissionPage.ts +++ b/e2e/pages/PermissionPage.ts @@ -32,7 +32,6 @@ class PermissionPage { async clickContinueButton() { await expect(this.continueButton).toExist(); - // await waitFor(this.continueButton).toExist().withTimeout(5000); await this.continueButton.tap(); } } diff --git a/run_docker_ui_tests.sh b/run_docker_ui_tests.sh index c483ef0..fc0dbaf 100644 --- a/run_docker_ui_tests.sh +++ b/run_docker_ui_tests.sh @@ -6,5 +6,7 @@ echo "kvm:x:200:circleci" | sudo tee -a /etc/group # Check that hardware emulation is enabled. emulator -accel-check +sudo chown circleci -R /screenshots + # Run the tests -npx detox test --configuration android.emu.release --loglevel verbose +npx detox test --configuration android.emu.release --loglevel verbose --record-logs all From 194c5c26f95bcc8573c58aae7726833a2056ec7e Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Wed, 14 Aug 2024 12:09:09 +0200 Subject: [PATCH 27/31] Delete broken CI This doesn't work, so we aren't pursuing this approach for the time being. --- .github/workflows/ci.yml | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9fa76c2..9c7480d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,45 +26,6 @@ jobs: - uses: actions/setup-node@v4 - run: npm ci - ui-tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: 17 - cache: 'gradle' - - name: Dump the encrypted keystore into a file - run: echo "${{ secrets.ENCRYPTED_KEYSTORE }}" > wallet.keystore.asc - - name: Decrypt the keystore into its canonical location - run: gpg -d --passphrase "${{ secrets.KEYSTORE_DECRYPTION_KEY }}" --batch wallet.keystore.asc > wallet.keystore - - run: npm ci - - name: Generate the android metadata files - run: npx expo prebuild --platform android - env: - KEYSTORE_PATH: ${{ github.workspace }}/wallet.keystore - KEYSTORE_PASSWORD: "${{ secrets.KEYSTORE_PASSWORD }}" - SIGNING_CONFIG_PATH: ${{ github.workspace }}/android-config/signing-config.gradle - - name: Build the APK to be uploaded in the test container - run: npx detox build --configuration android.emu.release - - name: Build the docker image containing the Android emulator and all the test dependencies. - run: | - docker build \ - --network=host \ - --tag inrupt-wallet-frontend-ui-tests:test \ - . - - name: Run the Detox tests in the emulator container - run: | - docker run \ - --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ - --env EXPO_PUBLIC_WALLET_API="https://datawallet.inrupt.com" \ - # FIXME read these from secrets, this is just for initial testing - --env TEST_ACCOUNT_USERNAME="some-username" \ - --env TEST_ACCOUNT_PASSWORD="some-password" \ - inrupt-wallet-frontend-ui-tests:test - sonarqube: name: run sonarqube if: ${{ github.actor != 'dependabot[bot]' }} From 3ff668bd253cc6600a08fd8b0f5bf9634a693e8e Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Wed, 14 Aug 2024 12:10:32 +0200 Subject: [PATCH 28/31] Gitignore screenshots folder --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 033019e..c8e4d0f 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ expo-env.d.ts .env *.keystore + +# Folder where the UI tests get stored. +screenshots/ From 6c76bb7d84d2f71b0693feb19efcc101dec4f095 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Wed, 14 Aug 2024 14:23:59 +0200 Subject: [PATCH 29/31] Added new env vars to env sample --- .env.sample | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.env.sample b/.env.sample index e000bca..0f3773f 100644 --- a/.env.sample +++ b/.env.sample @@ -8,3 +8,5 @@ TEST_IOS_SIM= # e.g. 'Android_34' or 'Pixel_3a_API_34' TEST_ANDROID_EMU= SIGNING_CONFIG_PATH=/absolute/path/to/android-config/signing-config.gradle +KEYSTORE_PATH=/absolute/path/to/wallet.keystore +KEYSTORE_PASSWORD= From 03d8ddd83346a23fe32461507325ec158865d87a Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Wed, 14 Aug 2024 16:33:37 +0200 Subject: [PATCH 30/31] Delete Dockerfile and runner script --- Dockerfile | 46 ------------------------------------------ run_docker_ui_tests.sh | 12 ----------- 2 files changed, 58 deletions(-) delete mode 100644 Dockerfile delete mode 100644 run_docker_ui_tests.sh diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 63dcf88..0000000 --- a/Dockerfile +++ /dev/null @@ -1,46 +0,0 @@ -FROM cimg/android:2024.07.1-node - -# Setup Android environment -ARG ARCH="x86_64" -ARG TARGET="google_apis_playstore" -ARG API_LEVEL="34" -ARG ANDROID_API_LEVEL="android-${API_LEVEL}" -ARG ANDROID_APIS="${TARGET};${ARCH}" -ARG EMULATOR_PACKAGE="system-images;${ANDROID_API_LEVEL};${ANDROID_APIS}" -ARG ANDROID_SDK_PACKAGES="${EMULATOR_PACKAGE}" -# Install system image for emulator. -RUN sdkmanager --verbose ${ANDROID_SDK_PACKAGES} -# Create new virtual device -RUN avdmanager --verbose create avd --name "pixel_7" --device "pixel_7" --package "system-images;android-34;google_apis_playstore;x86_64" - -WORKDIR /inrupt-wallet-frontend/ -COPY package.json package-lock.json ./ - -RUN npm ci - -COPY --chown=circleci .detoxrc.js app.config.ts metro.config.js tsconfig.json run_docker_ui_tests.sh ./ -COPY ../../android-config/ ./android-config/ -COPY api/ ./api/ -COPY app/ ./app/ -COPY assets/ ./assets/ -COPY components/ ./components/ -COPY constants/ ./constants/ -COPY e2e/ ./e2e/ -COPY hooks/ ./hooks/ -COPY plugins/ ./plugins/ -COPY types/ ./types/ -COPY utils/ ./utils/ -# The APK must be compiled beforehand -# TODO: Add a test checking for its presence -COPY android/app/build/outputs/apk/release/app-release.apk ./android/app/build/outputs/apk/release/app-release.apk -COPY android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk ./android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk - -RUN chown circleci . -RUN chmod u+x run_docker_ui_tests.sh - -ENV CI=true -ENV SIGNING_CONFIG_PATH=/inrupt-wallet-frontend/android-config/signing-config.gradle -ENV TEST_ANDROID_EMU="pixel_7" -ENV NODE_ENV="docker" - -CMD ["bash", "-c", "./run_docker_ui_tests.sh"] diff --git a/run_docker_ui_tests.sh b/run_docker_ui_tests.sh deleted file mode 100644 index fc0dbaf..0000000 --- a/run_docker_ui_tests.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /bin/bash - -# Enable QEmu hardware acceleration. -sudo chown circleci -R /dev/kvm -echo "kvm:x:200:circleci" | sudo tee -a /etc/group -# Check that hardware emulation is enabled. -emulator -accel-check - -sudo chown circleci -R /screenshots - -# Run the tests -npx detox test --configuration android.emu.release --loglevel verbose --record-logs all From e235929ab1d5e751baa1b2813b40effa9c1f768c Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Tue, 20 Aug 2024 10:15:33 +0200 Subject: [PATCH 31/31] Remove references to Docker --- .detoxrc.js | 5 +---- README.md | 22 ---------------------- 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/.detoxrc.js b/.detoxrc.js index 27bd6b5..1143c10 100644 --- a/.detoxrc.js +++ b/.detoxrc.js @@ -48,9 +48,6 @@ module.exports = { device: { avdName: process.env.TEST_ANDROID_EMU }, - // If running in CI, the emulator requires additional configuration options. - bootArgs: process.env.NODE_ENV === "docker" ? "" : "-no-snapshot -noaudio -no-boot-anim -camera-back none", - headless: process.env.NODE_ENV === "docker" } }, configurations: { @@ -75,7 +72,7 @@ module.exports = { defaultTestTimeout: 15000 }, artifacts: { - rootDir: process.env.NODE_ENV === "docker" ? "/screenshots/" : "./screenshots/", + rootDir: "./screenshots/", plugins: { log: {"enabled": true}, uiHierarchy: {"enabled": true}, diff --git a/README.md b/README.md index 517d9ad..d7d599d 100644 --- a/README.md +++ b/README.md @@ -176,28 +176,6 @@ After completion, the binary apps will be located in: You can share the .apk files with others who need to run the Detox tests without building the Android app locally. -### Running the tests in Docker - -The UI-based tests can be packaged to run in Docker (experimental at the time of writing). - -- Follow the build steps above (keystore, detox android build) to generate the release build with the Detox version of the APK. -- Build the docker container from the provided Dockerfile: -``` -docker build --network=host --tag inrupt-wallet-frontend-ui-tests:test . -``` -- Run the docker container (after replacing the placeholders) -``` -docker run -it \ - --privileged \ - --device /dev/kvm \ - --mount type=bind,source=./screenshots/,target=/screenshots \ - --env TEST_ACCOUNT_USERNAME= \ - --env TEST_ACCOUNT_PASSWORD= \ - --env EXPO_PUBLIC_LOGIN_URL="https://datawallet.inrupt.com/oauth2/authorization/wallet-app" \ - --env EXPO_PUBLIC_WALLET_API="https://datawallet.inrupt.com" \ - inrupt-wallet-frontend-ui-tests:test -``` - ## UI overview Upon execution, the application prompts the user to log in. After successful authentication, the wallet app presents various views, located in the `app/(tabs)` directory: