如何获取使用 expo/expo-github-action 的内部分发构建的链接?

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

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文件:

如何获取使用 expo/expo-github-action 的内部分发构建的链接?

我想以编程方式获取这些链接,以便在下一步中通知我的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:

如何获取使用 expo/expo-github-action 的内部分发构建的链接?

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 &#39;.[] | select(.platform==&quot;ANDROID&quot;) | .artifacts.applicationArchiveUrl&#39;)
ios_link=$(echo $build_json | jq -r &#39;.[] | select(.platform==&quot;IOS&quot;) | .artifacts.applicationArchiveUrl&#39;)

Finally, I've assigned the variables to outputs:

EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo &quot;build_json&lt;&lt;$EOF&quot; &gt;&gt; $GITHUB_OUTPUT
echo &quot;$build_json&quot; &gt;&gt; $GITHUB_OUTPUT
echo &quot;$EOF&quot; &gt;&gt; $GITHUB_OUTPUT
echo &quot;android_link=$android_link&quot; &gt;&gt; $GITHUB_OUTPUT
echo &quot;ios_link=$ios_link&quot; &gt;&gt; $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 &lt;name&gt;=&lt;variable&gt; syntax.

I could then use the outputs with steps.&lt;step id&gt;.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 &#39;.[] | select(.platform==&quot;ANDROID&quot;) | .artifacts.applicationArchiveUrl&#39;)
ios_link=$(echo $build_json | jq -r &#39;.[] | select(.platform==&quot;IOS&quot;) | .artifacts.applicationArchiveUrl&#39;)
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo &quot;build_json&lt;&lt;$EOF&quot; &gt;&gt; $GITHUB_OUTPUT
echo &quot;$build_json&quot; &gt;&gt; $GITHUB_OUTPUT
echo &quot;$EOF&quot; &gt;&gt; $GITHUB_OUTPUT
echo &quot;android_link=$android_link&quot; &gt;&gt; $GITHUB_OUTPUT
echo &quot;ios_link=$ios_link&quot; &gt;&gt; $GITHUB_OUTPUT

Hopefully it will help the next person save day of investigation or so!

huangapple
  • 本文由 发表于 2023年3月7日 23:45:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75664163.html
匿名

发表评论

匿名网友

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

确定