将Expo Classic的发布通道转换为EAS

huangapple go评论59阅读模式
英文:

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.

英文:

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.

答案1

得分: 0

以下是翻译好的部分:

  • "This SO answer was the one that solved my problem.":这个 SO 答案解决了我的问题。
  • "It said that I need to add a branch first then link my channel to it using this command:":它说我需要先添加一个 branch,然后使用以下命令将我的 channel 链接到它:
  • "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.":之前让我困惑的是,每当我运行 eas build -p android --profile staging 时,它既不显示警告也不显示错误,只是顺利完成。
  • "This gives me a false idea that my profile's channel should take effect.":这让我错误地认为我的配置文件的 channel 应该生效。
  • "After creating the branch and linking my channel to it, the Updates.channel now contains the channel in the eas.json.":创建了 branch 并将我的 channel 链接到它后,eas.json 中的 Updates.channel 现在包含了该渠道。
  • "However, whenever I run eas update --channel staging --platform android, the Updates.channel is still null.":然而,每当我运行 eas update --channel staging --platform android 时,Updates.channel 仍然为空。
  • "It seems there's not a direct replacement to expo publish and releaseChannel the way it used before.":看来没有直接替代 expo publish 和之前使用的 releaseChannel 的方式。
  • "My eas.json is still similar from before:":我的 eas.json 仍然与以前相似。

希望这些翻译对您有所帮助。

英文:

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": {}
  }
}

huangapple
  • 本文由 发表于 2023年4月4日 18:19:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75928198.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定