Search code examples
react-nativeexpoeas

Converting Expo Classic's Release Channel to EAS


I have converted our old mobile app to the latest version of expo. Seeing that a lot of things had been deprecated including expo publish, I'm now integrating the eas build to my workflow

In my code before, I have been using Updates.releaseChannel before for my env specific config. See code below:

export function getEnvConst() {
  if (Updates.releaseChannel.startsWith("prod")) {
    return { apiUrl: "https://prodUrl.com/" };
  } else if (Updates.releaseChannel.startsWith("staging")) {
    return { apiUrl: "https://stagingUrl.com/" };
  } else if (Updates.releaseChannel.startsWith("uat")) {
    return { apiUrl: "https://uatUrl.com/" };
  } else {
    return { apiUrl: "https://devUrl.com/" };
  }
}

and I get to select which channel via the following commands:

expo publish --release-channel prod
expo publish --release-channel uat
expo publish --release-channel staging

This setup allows me to switch ApiUrl base on releaseChannel and at the same time, during development (npm start) the else statement kicks in to run using dev url (since no release channel)

I can't seem to replicate this setup using eas build. What I've tried is to add eas.json and added a bunch of profile and bunch of env. These env doesn't seem to be accessible to the javascript code as well?

What I tried:

  1. Add profile and used channel. Literally used the same getEnvConst function above and replaced releaseChannel with channel. The channel doesn't seem to be working. I use the following command for publishing eas build -p android --profile staging The eas.json contains the following:
{
  "cli": {
    "version": ">= 3.8.1"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal",
      "ios": {
        "resourceClass": "m-medium"
      },
      "channel": "dev",
    },
    "staging": {
      "android": {
        "buildType": "apk"
      },
      "ios": {
        "resourceClass": "m-medium"
      },
      "channel": "staging",
    },
    "uat": {
      "distribution": "internal",
      "ios": {
        "resourceClass": "m-medium"
      },
      "channel": "uat",
    },
    "production": {
      "ios": {
        "resourceClass": "m-medium"
      },
      "channel": "production",
    }
  },
  "submit": {
    "production": {}
  },
}
  1. Tried adding env in eas.json. But this export const apiUrl = process.env.API_URL doesn't seem to get the values via npm start. Haven't tested it in eas build because it takes a lot of time to test...
{
  "cli": {
    "version": ">= 3.8.1"
  },
  //Remove other sections for brevity
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal",
      "ios": {
        "resourceClass": "m-medium"
      },
      "channel": "dev",
      "env": {
        "API_URL": "http://devUrl.com/"
      }
    },
    "production": {
      "ios": {
        "resourceClass": "m-medium"
      },
      "channel": "production",
      "env": {
        "API_URL": "https://prodUrl.com/"
      }
    }
  },
  "submit": {
    "production": {}
  },
  "development": {
    "client": "local"
  },
  "env": {
    "development": {
      "API_URL": "https://devUrl.com/"
    }
  }
}

Honestly I'm just confused with all of this and it's taking me a lot of time than I want to admit, even after reading the documentation. It seems I'm missing the fundamentals of expo that the document assumes I'm aware of so what it says doesn't connect to me.


Solution

  • I was able to proceed with that I wanted to happen.

    This SO answer was the one that solved my problem. It said that I need to add a branch first then link my channel to it using this command:

    eas update --branch staging
    eas channel:edit staging --branch staging
    

    What tripped me before was whenever I run eas build -p android --profile staging it doesn't say any warning or error and just completes successfully. This gives me a false idea that my profile's channel should take effect. After creating the branch and linking my channel to it, the Updates.channel now contains the channel in the eas.json.

    However, whenever I run eas update --channel staging --platform android, the Updates.channel is still null. I just ended up commenting/uncommenting the return of the else when I do eas update which works for now.

    It seems there's not a direct replacement to expo publish and releaseChannel the way it used before.

    My eas.json is still similar from before:

    {
      "cli": {
        "version": ">= 3.8.1"
      },
      "build": {
        "development": {
          "developmentClient": true,
          "distribution": "internal",
          "ios": {
            "resourceClass": "m-medium"
          },
          "channel": "dev"
        },
        "staging": {
          "distribution": "internal",
          "ios": {
            "resourceClass": "m-medium"
          },
          "channel": "staging"
        },
        "uat": {
          "distribution": "internal",
          "ios": {
            "resourceClass": "m-medium"
          },
          "channel": "uat"
        },
        "production": {
          "ios": {
            "resourceClass": "m-medium"
          },
          "channel": "production"
        }
      },
      "submit": {
        "production": {}
      }
    }