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

EAS_BUILD_PROFILE and EAS_BUILD_PLATFORM are not always set when running EAS cloud builds #2112

Open
adipascu opened this issue Nov 5, 2023 · 7 comments
Labels
eas build needs review Issue is ready to be reviewed by a maintainer

Comments

@adipascu
Copy link

adipascu commented Nov 5, 2023

Build/Submit details page URL

here

Summary

We have encountered a recurring issue where the EAS_BUILD_PROFILE and EAS_BUILD_PLATFORM environment variables are not always being set during the execution of EAS cloud builds. Specifically, these variables appear to be missing or not populated in some instances when referenced within the app.config.ts file. This inconsistency is leading to configuration issues and unpredictable build behaviors.

Managed or bare?

Managed

Environment

expo-env-info 1.0.5 environment info:
System:
OS: Linux 6.2 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 20.1.0 - ~/n/bin/node
Yarn: 1.22.15 - ~/n/bin/yarn
npm: 9.6.4 - ~/n/bin/npm
SDKs:
Android SDK:
API Levels: 29, 31, 32, 33
Build Tools: 30.0.3, 32.0.0, 33.0.1
System Images: android-24 | Google Play Intel x86 Atom, android-30 | Google TV Intel x86 Atom
npmPackages:
expo: ~49.0.16 => 49.0.16
react: 18.2.0 => 18.2.0
react-native: 0.72.6 => 0.72.6
Expo Workflow: managed

npx expo-doctor
✔ Check Expo config for common issues
✔ Check package.json for common issues
✔ Check dependencies for packages that should not be installed directly
✔ Check for common project setup issues
✔ Check npm/ yarn versions
✔ Check Expo config (app.json/ app.config.js) schema
✔ Check for legacy global CLI installed locally
✔ Check that native modules do not use incompatible support packages
✔ Check that packages match versions required by installed Expo SDK
✔ Check that native modules use compatible support package versions for installed Expo SDK

Didn't find any issues with the project!

Error output

No response

Reproducible demo or steps to reproduce from a blank project

app.config.ts file:

export default (context: ConfigContext): ExpoConfig => {
  const { EAS_BUILD_PROFILE, EAS_BUILD_PLATFORM } = process.env;
  const APP_NAME = "MyApp";
  const name = (() => {
    if (EAS_BUILD_PLATFORM === "ios") {
      return APP_NAME;
    }
    switch (EAS_BUILD_PROFILE) {
      case "staging":
        return `${APP_NAME} (Staging)`;
      case "production":
        return APP_NAME;
      case undefined:
        return `${APP_NAME} (Dev)`;
      default:
        throw new Error(`Unknown EAS_BUILD_PROFILE: ${EAS_BUILD_PROFILE}`);
    }
  })();
  return {
    name,
    /// ...otherFields
  };
};

Run the build over EAS, notice that the build profiles are not reliably read, this is causing inconsistencies in the name filed and causes the iOS build to fail.

@adipascu adipascu added the needs review Issue is ready to be reviewed by a maintainer label Nov 5, 2023
@szdziedzic
Copy link
Member

Hi,

I tried to reproduce your issue based on the config that you gave me, but unfortunately, I failed to do so. I think I would need to get more details about your project to help you. Do you have the .env file in your project by any chance?

@adipascu
Copy link
Author

adipascu commented Nov 15, 2023

There is no .env file. This can be reproduced by running eas build --platform ios --profile staging --local. It can also be reproduced by running the build remotely.
Here is the content of eas.json:

{
  "cli": {
    "appVersionSource": "remote"
  },
  "build": {
    "staging": {
      "developmentClient": false,
      "distribution": "store",
      "autoIncrement": true
    }
  }
}

@szdziedzic
Copy link
Member

I think that the issue for you can be that because you don't have these env vars in your env when running the EAS CLI locally to trigger the build, it can prepare credentials for a different target (probably dev one, because the values which you are relying on are undefined at this moment), but if the env vars are present on EAS. server the target bundle identifier etc. becomes different.

@adipascu
Copy link
Author

adipascu commented Nov 15, 2023

Some of variables specified in the documentation (like EAS_BUILD_PROFILE) are unusable in the app.config.ts file in both local and remote builds. If its working as expected, we should document it.

@szdziedzic
Copy link
Member

I'm so sorry, but I truly can't replicate it in my project. I ran a couple of builds, and I was always able to use these vars in my app.config.ts even using parts of your config relying on these vars. I'm wondering what can be causing issues for you. You can even see that they are set in the Spin up build environment phase on the server in your build 🤔.
Screenshot 2023-11-15 at 19 53 45

Could you explain one more time what you expected that will happen in https://expo.dev/accounts/goveni/projects/fairytell/builds/4bafe95a-1542-488b-aa1f-8438c1f17d83 and what went wrong, please?

Regarding documentation: It's documented that they are not available when evaluating app.config.js locally (ex. when triggering your build using EAS CLI) but they are available during the build process itself. As far as I know, the docs are accurate here. Let me know if some part of these docs is not clear to you, so I can try to add something here to make it better!
https://docs.expo.dev/build-reference/variables/#built-in-environment-variables
Screenshot 2023-11-15 at 19 33 28

@carleberg
Copy link

carleberg commented Dec 5, 2023

Regarding documentation: It's documented that they are not available when evaluating app.config.js locally (ex. when triggering your build using EAS CLI) but they are available during the build process itself. As far as I know, the docs are accurate here. Let me know if some part of these docs is not clear to you, so I can try to add something here to make it better!
https://docs.expo.dev/build-reference/variables/#built-in-environment-variables

The linked docs about built-in environment variables says:

The following environment variables are exposed to each build job and can be used within any build step. They are not set when evaluating app.config.js locally

But what does "when evaluating app.config.js locally" actually mean? I thought it meant that it won't evaluate when I run npx expo config. I'm having issues where EAS_BUILD_PROFILE is undefined in my app.config.js when I'm running npx eas build --local - is that what the docs are referring to, that local EAS builds don't have built-in environment variables?

@adipascu
Copy link
Author

adipascu commented Feb 7, 2024

@carleberg can you take a look at expo/expo#24061, it's the same issue and comes with a minimally reproducible example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eas build needs review Issue is ready to be reviewed by a maintainer
Projects
None yet
Development

No branches or pull requests

3 participants