Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flask] bitrise pipelines #6645

Merged
merged 39 commits into from
Jul 14, 2023
Merged

[Flask] bitrise pipelines #6645

merged 39 commits into from
Jul 14, 2023

Conversation

owencraston
Copy link
Contributor

@owencraston owencraston commented Jun 20, 2023

Development & PR Process

  1. Follow MetaMask Mobile Coding Standards
  2. Add release-xx label to identify the PR slated for a upcoming release (will be used in release discussion)
  3. Add needs-dev-review label when work is completed
  4. Add needs-qa label when dev review is completed
  5. Add QA Passed label when QA has signed off

Description

Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions,
1. What is the reason for the change?

  • This allows us to run flask builds/releases on bitrise
  • it will enable the smooth rollout of flask and should handle all the environment setup.
    2. What is the improvement/solution?
  • modify the build.sh to build flask on android/ios in release mode. For this I followed the exact patterns that were already in place for the qa/release versions of the app.
  • created yarn scripts to call our build.sh with the correct arguments
  • created bitrise workflows and pipelines to create the builds for us
  • created a release pipeline that takes the builds and releases it to the stores.
  • updated the signing for MetaMask-Flask in xcode which modified the .xcodeproject file
  • Modified the sentry environment variable to handle the different types of flask releases
  • I was getting the error "Invalid App Store Icon. The App Store Icon in the asset catalog in 'MetaMask-Flask.app' can't be transparent nor contain an alpha channel. (ID: 9e93a511-109f-43f3-b3a5-a80ee40734cd)"; when I tried to upload to testflight so I needed to modify the ios app icons to remove the alpha.
Screenshot 2023-06-27 at 11 55 26 AM

Test Builds

Issue

Progresses https://github.com/MetaMask/mobile-planning/issues/1044
Progresses https://app.zenhub.com/workspaces/metamask-accounts-team-62505028c3853700162f65e0/issues/gh/metamask/mobile-planning/1043

Checklist

  • There is a related GitHub issue
  • Tests are included if applicable
  • Any added code is fully documented

@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@owencraston owencraston changed the title basic pipeline scaffold [Flask] bitrise pipelines Jun 20, 2023
@@ -8,7 +8,12 @@ FILE=./android/app/build/outputs/apk/qa/release/app-qa-release.apk
if test -f "$FILE"; then
shasum -a 512 "$FILE" > ./android/app/build/outputs/apk/qa/release/sha512sums.txt
fi
elif [ "$MODE" == "Flask" ]; then
FILE=./android/app/build/outputs/apk/flask/release/app-flask-release.apk
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Is this the correct file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be

scripts/build.sh Outdated
echo "Remapping flask env variable names to match production"

# js.env variables
remapEnvVariable "MM_FLASK_PUBNUB_SUB_KEY" "MM_PUBNUB_SUB_KEY"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove PubNub keys

bitrise.yml Outdated
- pipeline_intermediate_files: ios/build/output/MetaMask-QA.ipa:BITRISE_APP_STORE_IPA_PATH
- deploy_path: ios/build/output/MetaMask-QA.ipa
- pipeline_intermediate_files: ios/build/output/MetaMask.ipa:BITRISE_APP_STORE_IPA_PATH
- deploy_path: ios/build/output/MetaMask.ipa
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be MetaMask-Flask.ipa

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I accidentally edited the QA steps here. I will remove these.

bitrise.yml Outdated
is_always_run: false
is_skippable: true
inputs:
- deploy_path: ios/build/MetaMask.xcarchive
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same name update here

bitrise.yml Outdated
inputs:
- deploy_path: ios/build/MetaMask-QA.xcarchive
inputs:
- pipeline_intermediate_files: ios/build/output/MetaMask.ipa:BITRISE_APP_STORE_IPA_PATH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

bitrise.yml Outdated
is_always_run: false
is_skippable: true
inputs:
- deploy_path: ios/build/MetaMask.xcarchive
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

bitrise.yml Show resolved Hide resolved
bitrise.yml Show resolved Hide resolved
bitrise.yml Show resolved Hide resolved
scripts/build.sh Show resolved Hide resolved
scripts/build.sh Show resolved Hide resolved
@@ -671,6 +690,115 @@ workflows:
- pipeline_intermediate_files: sourcemaps/ios/index.js.map:BITRISE_APP_STORE_SOURCEMAP_PATH
- deploy_path: sourcemaps/ios/index.js.map
title: Deploy Source Map
build_ios_flask_release:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C: I wonder if we have a way to prevent duplication of these big yaml blocks and just have one called with params. they really mostly look the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NicolasMassart regarding the sourcemap comment, yes they will be different. I am wondering if I need to change the sourcemap logic since it is failing on bitrise

const environment =
__DEV__ || !METAMASK_ENVIRONMENT ? 'development' : METAMASK_ENVIRONMENT;
__DEV__ || !METAMASK_ENVIRONMENT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests with explicit output and comments? This thing is getting out of hand.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On extension we found it easier to disable Sentry entirely in development builds (see https://github.com/MetaMask/metamask-extension/blob/230c0c6fa1626bc1afd68c22321f5c166425dd12/app/scripts/lib/setupSentry.js#L88). Most of our Sentry testing was done with QA or production-like builds as part of regression testing. On the rare occasion that we wanted to test Sentry with a development build, it's easy to comment out that line.

That would reduce this condition to a single ternary:

const environment = METAMASK_BUILD_TYPE === 'main' ?
  METAMASK_ENVIRONMENT :
  `${METAMASK_ENVIRONMENT}-${METAMASK_BUILD_TYPE}`;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to go that route here, and disable Sentry for development builds, that would be simpler to do in a separate PR. Better to keep this one focused if we can.

A more direct solution to cleaning this up for now would be to split this into two steps: determine the environment, then the sentry environment. e.g.

const metamaskEnvironment = __DEV__ || !METAMASK_ENVIRONMENT ? 'development' : METAMASK_ENVIRONMENT;

const sentryEnvironment = METAMASK_BUILD_TYPE === 'main' ?
  METAMASK_ENVIRONMENT :
  `${METAMASK_ENVIRONMENT}-${METAMASK_BUILD_TYPE}`;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have went ahead and modified this logic to live inside a function I am calling deriveSentryEnvironment.

/**
 * Derives the Sentry environment based on input parameters.
 * This function is similar to the environment logic used in MetaMask extension.
 * - https://github.com/MetaMask/metamask-extension/blob/34375a57e558853aab95fe35d5f278aa52b66636/app/scripts/lib/setupSentry.js#L91
 *
 * @param {boolean} isDev - Represents if the current environment is development (__DEV__ global variable).
 * @param {string} [metamaskEnvironment='local'] - The environment MetaMask is running in
 *                                                  (process.env.METAMASK_ENVIRONMENT).
 *                                                  It defaults to 'local' if not provided.
 * @param {string} [metamaskBuildType='main'] - The build type of MetaMask
 *                                              (process.env.METAMASK_BUILD_TYPE).
 *                                              It defaults to 'main' if not provided.
 *
 * @returns {string} - The Sentry environment. Possible values are 'development', 'local',
 *                     'production', or a string in the format `${metamaskEnvironment}-${metamaskBuildType}`.
 *                     'development' is returned if 'isDev' is true or 'metamaskEnvironment' is not provided.
 *                     'metamaskEnvironment' is returned if 'metamaskBuildType' is 'main' or undefined.
 *                     `${metamaskEnvironment}-${metamaskBuildType}` is returned for other cases,
 *                     for example 'production-flask' or 'debug-flask'.
 */
export function deriveSentryEnvironment(
  isDev,
  metamaskEnvironment = 'local',
  metamaskBuildType = 'main',
) {
  const environment =
    isDev || !metamaskEnvironment
      ? 'development'
      : metamaskBuildType === 'main'
      ? metamaskEnvironment
      : `${metamaskEnvironment}-${metamaskBuildType}`;

  return environment;
}

This function is well tested in the new sentryUtils.test.ts file. I opted to not split up the meta mask environment and sentry environment to keep continuity with what we have already published in sentry. what would be the use case for having a separate metamaskEnvironment if we don't log it in sentry?

metamaskEnvironment = 'local',
metamaskBuildType = 'main',
) {
const environment =
Copy link
Member

@Gudahtt Gudahtt Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Thoughts on splitting this up onto multiple statements? The standard metamask ESLint config (not yet used here) disallows nested ternaries. They're a bit hard to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have broken it up into multiple return statements in my latest commit.

* (process.env.METAMASK_BUILD_TYPE).
* It defaults to 'main' if not provided.
*
* @returns {string} - The Sentry environment. Possible values are 'development', 'local',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it might be better to include less specifics here, so we don't have to update it each time we add a new environment

) {
const environment =
isDev || !metamaskEnvironment
? 'development'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include the build type even for development builds? Seems like it could be useful

@Gudahtt
Copy link
Member

Gudahtt commented Jul 7, 2023

It's not yet clear to me whether the metric events are being flagged as being from Flask rather than from the main release. This is quite important. We rely on those metrics a lot, so we need to ensure we know precisely what they mean.

I'm not familiar with how metrics are setup on mobile at the moment, so I'm not sure how to approach this.

@socket-security
Copy link

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Issue Package Version Note Source
Filesystem access fast-xml-parser 4.2.4
Mild CVE fast-xml-parser 4.2.4
Unmaintained strnum 1.0.5
  • Last Publish: 12/4/2021, 10:58:54 AM

Next steps

What is filesystem access?

Accesses the file system, and could potentially read sensitive data.

If a package must read the file system, clarify what it will read and ensure it reads only what it claims to. If appropriate, packages can leave file system access to consumers and operate on data passed to it instead.

What is a mild CVE?

Contains a low severity Common Vulnerability and Exposure (CVE).

Remove or replace dependencies that include known low severity CVEs. Consumers can use dependency overrides or npm audit fix --force to remove vulnerable dependencies.

What are unmaintained packages?

Package has not been updated in more than a year and may be unmaintained. Problems with the package may go unaddressed.

Package should publish periodic maintenance releases if they are maintained, or deprecate if they have no intention in further maintenance.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore foo@1.0.0 bar@* or ignore all packages with @SocketSecurity ignore-all

  • @SocketSecurity ignore fast-xml-parser@4.2.4
  • @SocketSecurity ignore strnum@1.0.5

@owencraston
Copy link
Contributor Author

The environment production-flask is working as expected

Screenshot 2023-07-12 at 5 33 26 PM

@owencraston
Copy link
Contributor Author

I created a production testflight build of this branch (v 7.2.1 1145) and it appears that there are no "extra" environments in sentry with the new logic.
Screenshot 2023-07-13 at 11 13 04 AM

@@ -128,14 +126,16 @@
<key>test</key>
<string>$(MM_BRANCH_KEY_TEST)</string>
</dict>
<key>branch_universal_link_domains</key>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be adding the iOS bundle identifier and android apk hash to branch or deep linking won't work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will work with Andrea to get this working after we submit the builds.

scripts/build.sh Outdated

# js.env variables``
remapEnvVariable "FLASK_MOONPAY_API_KEY_STAGING" "MOONPAY_API_KEY_STAGING"
remapEnvVariable "SEGMENT_FLASK_DEV_KEY" "SEGMENT_DEV_KEY"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format error

@owencraston owencraston merged commit 5ef0e5d into flask Jul 14, 2023
@owencraston owencraston deleted the flask-pipelines branch July 14, 2023 18:20
@github-actions github-actions bot locked and limited conversation to collaborators Jul 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants