bamlab / flashlight

📱⚡️ Lighthouse for Mobile - audits your app and gives a performance score to your Android apps (native, React Native, Flutter..). Measure performance on CLI, E2E tests, CI...
https://docs.flashlight.dev
MIT License
1.17k stars 29 forks source link

An ability to customize `binaryFolder` #296

Closed kirillzyusko closed 2 months ago

kirillzyusko commented 3 months ago

In

https://github.com/bamlab/flashlight/blob/8aee5ec25e13511bb9c20f1d43cd3ff94b02e407/packages/platforms/android/src/commands/platforms/UnixProfiler.ts#L29-L31

we kind of predefine the path for cpp binaries. It works really well when we have an access to node_modules and run locally, in this case global.Flipper === false and we add ../../../ prefix.

But we have a custom pipeline/e2e test runner, so when we run the e2e tests on AWS we pack everything into a single .zip archive and then execute our tests based on the content of this archive.

The problem here is that we still add ../../../ prefix and when we unpack the content we search for binaries in a root folder of a runner (and of course we can not copy files there because of security reasons).

To overcome this problem I fixed it in following way:

Just curious if I can submit this fix to the repository (maybe use a different name like prcoess.env.USE_BIN_FOLDER)?

Almouro commented 3 months ago

Hi @kirillzyusko, I'm not sure I understand the issue correctly, how are you packaging the .zip and then installing on AWS?

Technically the CI on this repo is running on AWS https://github.com/bamlab/flashlight/blob/main/package.json#L30 with our undocumented AWS Device Farm plugin https://github.com/bamlab/flashlight/blob/main/packages/plugins/aws-device-farm/src/bin.ts#L11 and we don't seem to have an issue there

kirillzyusko commented 3 months ago

how are you packaging the .zip and then installing on AWS?

This is the script for installation + run:

      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: us-west-2

      - name: Schedule AWS Device Farm test run on main branch
        uses: realm/aws-devicefarm/test-application@7b9a91236c456c97e28d384c9e476035d5ea686b
        id: schedule-awsdf-main
        with:
          name: App E2E Performance Regression Tests
          project_arn: ${{ secrets.AWS_PROJECT_ARN }}
          device_pool_arn: ${{ secrets.AWS_DEVICE_POOL_ARN }}
          app_file: zip/app-e2eRelease.apk
          app_type: ANDROID_APP
          test_type: APPIUM_NODE
          test_package_file: App.zip
          test_package_type: APPIUM_NODE_TEST_PACKAGE
          test_spec_file: tests/e2e/TestSpec.yml
          test_spec_type: APPIUM_NODE_TEST_SPEC
          remote_src: false
          file_artifacts: |
            Customer Artifacts.zip
            Test spec output.txt
          log_artifacts: debug.log
          cleanup: true
          timeout: 5400

Into zip we are packing apks (two apk to check performance regressions between them) + node script (for tests execution) into zip archive:

Then we upload it and execute (tests/e2e/TestSpec.yml) our test as:

node testRunner.ts -- --mainAppPath app-e2eRelease.apk --deltaAppPath app-e2edeltaRelease.apk

The testRunner.ts is a compiled TS file.

I hope these code snippets will give you a better understanding of what we are doing 😅

Almouro commented 3 months ago

But you are also packing the node_modules (which should contain the @perf-profiler/android package for instance) inside App.zip right? Shouldn't it also include the binaries? 🤔

kirillzyusko commented 3 months ago

@Almouro this it the problem that we are not packing node_modules 🙈 We are using compiler and in the output we have a big single .ts file that contains all the necessary code (including code from node_modules) and in this case it doesn't include binaries (we have to copy it themselves).

Almouro commented 3 months ago

ah I see! We're using npm-bundle to package everything https://github.com/bamlab/flashlight/blob/main/packages/plugins/aws-device-farm/src/zipTestFolder.ts#L7 but I'm guessing a bundler would improve the general execution speed in the AWS machine? What bundler are you using?

I think in this case it would make more sense to use a process.env.FLASHLIGHT_BINARY_PATH variable to make it more flexible and fallback on default values, what do you think? Feel free to submit a PR! You can also get rid of the flipper condition since we don't maintain the flipper package anymore

kirillzyusko commented 3 months ago

What bundler are you using?

We are using ncc. Not sure why we've chosen such way, maybe for faster uploading to AWS, because packing all node_modules seems to be extremely expensive operation.

I think in this case it would make more sense to use a process.env.FLASHLIGHT_BINARY_PATH variable to make it more flexible and fallback on default values, what do you think?

Yep, I agree 👍

Feel free to submit a PR! You can also get rid of the flipper condition since we don't maintain the flipper package anymore

Done! Opened a PR here: https://github.com/bamlab/flashlight/pull/300