英文:
How do I get the links to the internal distribution builds with expo/expo-github-action?
问题
我正在通过GitHub操作和EAS Build为React Native Expo应用构建内部分发版本。工作流程在推送时由expo/expo-github-action@v7
触发。构建完成后,操作会记录2个URL(和2个QR码),用于下载.apk
和.ipa
文件:
我想以编程方式获取这些链接,以便在下一步中通知我的Slack频道,例如。
我已查看了文档,但它非常通用。有人可以帮忙吗?
英文:
I am building internal distribution builds for a React Native Expo app via GitHub actions and EAS Build. The workflow is triggered on push using expo/expo-github-action@v7
. Once the build is finished, the action logs 2 URLs (and 2 QR codes) where the .apk
and .ipa
can be downloaded:
I want to get those links programmatically so I can use them in the next step to notify my Slack channel, for example.
I've looked in the documentation, but it's very generic. Can anyone help?
答案1
得分: 0
我用“困难的方式”修复了这个问题,因为expo-github-action
没有任何输出。
首先,我需要将构建输出保存为JSON格式。我使用--json
开关执行了这个操作:
eas build --profile preview --platform all --non-interactive --json
其次,我将结果存储在一个变量中,像这样:
build_json=$(eas build --profile preview --platform all --non-interactive --json)
接下来,我解析了JSON并从中提取了链接:
android_link=$(echo $build_json | jq -r '.[] | select(.platform=="ANDROID") | .artifacts.applicationArchiveUrl')
ios_link=$(echo $build_json | jq -r '.[] | select(.platform=="IOS") | .artifacts.applicationArchiveUrl')
最后,我将变量分配给输出:
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "build_json<<$EOF" >> $GITHUB_OUTPUT
echo "$build_json" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
echo "android_link=$android_link" >> $GITHUB_OUTPUT
echo "ios_link=$ios_link" >> $GITHUB_OUTPUT
请注意,GitHub Actions用于创建输出的系统很脆弱,不太适用于反引号或换行符。因此,在build_json
的情况下,唯一安全的替代方法是使用随机分隔符,而不是<name>=<variable>
语法。
然后,我可以使用输出在步骤<step id>
中获取steps.<step id>.outputs.android_link
等等。
总体解决方案如下:
build_json=$(eas build --profile preview --platform all --non-interactive --json)
android_link=$(echo $build_json | jq -r '.[] | select(.platform=="ANDROID") | .artifacts.applicationArchiveUrl')
ios_link=$(echo $build_json | jq -r '.[] | select(.platform=="IOS") | .artifacts.applicationArchiveUrl')
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "build_json<<$EOF" >> $GITHUB_OUTPUT
echo "$build_json" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
echo "android_link=$android_link" >> $GITHUB_OUTPUT
echo "ios_link=$ios_link" >> $GITHUB_OUTPUT
希望这对下一个人能够节省大量的调查时间!
英文:
I fixed this the "hard way" because expo-github-action
does not have any outputs.
First, I needed to get the build output as JSON. I did so with the --json
switch:
eas build --profile preview --platform all --non-interactive --json
Second, I stored the result in a variable like so:
build_json=$(eas build --profile preview --platform all --non-interactive --json)
Next, I parsed the JSON and extracted the links out of it:
android_link=$(echo $build_json | jq -r '.[] | select(.platform=="ANDROID") | .artifacts.applicationArchiveUrl')
ios_link=$(echo $build_json | jq -r '.[] | select(.platform=="IOS") | .artifacts.applicationArchiveUrl')
Finally, I've assigned the variables to outputs:
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "build_json<<$EOF" >> $GITHUB_OUTPUT
echo "$build_json" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
echo "android_link=$android_link" >> $GITHUB_OUTPUT
echo "ios_link=$ios_link" >> $GITHUB_OUTPUT
Note that the system that GitHub Actions uses to create outputs is brittle and does not work well with apices or newlines, so in the case of build_json
, the only safe alternative is to use a random separator instead of the <name>=<variable>
syntax.
I could then use the outputs with steps.<step id>.outputs.android_link
, etc.
The overall solution looks like this:
build_json=$(eas build --profile preview --platform all --non-interactive --json)
android_link=$(echo $build_json | jq -r '.[] | select(.platform=="ANDROID") | .artifacts.applicationArchiveUrl')
ios_link=$(echo $build_json | jq -r '.[] | select(.platform=="IOS") | .artifacts.applicationArchiveUrl')
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "build_json<<$EOF" >> $GITHUB_OUTPUT
echo "$build_json" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
echo "android_link=$android_link" >> $GITHUB_OUTPUT
echo "ios_link=$ios_link" >> $GITHUB_OUTPUT
Hopefully it will help the next person save day of investigation or so!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论