如何通过GitHub Action为Firebase App Distribution设置版本号?
解决方案
Firebase App Distribution 的 appdistribution:distribute 命令默认读取安装包内的版本信息,但如果要自定义控制台显示的版本号,可使用 --version-name 参数手动指定。同时修正版本号提取的脚本错误,以下是调整后的完整 GitHub Action 脚本:
# Extract Version from Git Tag - name: Extract Version from Tag id: extract_version run: echo "::set-output name=version::$(echo ${{ github.ref }} | sed -n 's/^refs\/tags\/v//p')" # Extract Release Notes from Tag Message - name: Extract Release Notes from Tag id: get_tag_message run: | tag_message=$(git log -1 --pretty=%B) echo "::set-output name=tag-message::$tag_message" # Upload APK to Firebase App Distribution - name: Upload APK to Firebase App Distribution run: | firebase appdistribution:distribute build/app/outputs/flutter-apk/app-release.apk \ --app "${{ secrets.APPID }}" \ --groups "testers" \ --debug \ --version-name "${{ steps.extract_version.outputs.version }}" \ --release-notes "Version: ${{ steps.extract_version.outputs.version }} | Release Notes: ${{ steps.get_tag_message.outputs.tag-message }}"
关键调整说明
- 修正版本号提取逻辑:原
sed命令写法有误,改为s/^refs\/tags\/v//p,可正确从refs/tags/v1.0.0这类标签中提取出纯版本号(如1.0.0)。 - 添加自定义版本号参数:新增
--version-name "${{ steps.extract_version.outputs.version }}",该参数会将 Git Tag 提取的版本号设置为 Firebase App Distribution 控制台显示的版本名称,对应你截图中的目标位置。 - 可选:自定义版本代码:如果需要覆盖安装包的版本代码,可额外添加
--version-code <你的版本代码>参数,版本代码可从 Tag 或其他渠道提取传入。
内容的提问来源于stack exchange,提问作者mnhmilu
相关产品推荐
相关产品推荐

