- 生成 release log automatically-generated-release-notes
- Anyway to check the error message and retry?
- 输入输出多行
- 如何上传可执行文件到 release 中 (draft)
- action 不再允许 if 中使用 secrets 参数进行判断12
- Action Cache
- Auto upload to Marketplace
- Reusable Workflow
- 输入参数多行
- echo multiline strings in github action
- 同样的问题还出现在 setting error message 中(这里只讨论直接在 yaml 文件中输出的情况), 输出
\n的文件只会输出第一行, 用如下方式解决:
ERR_MSG=$(cat err.log)
ERR_MSG="${ERR_MSG//'%'/'%25'}"
ERR_MSG="${ERR_MSG//$'\n'/'%0A'}"
ERR_MSG="${ERR_MSG//$'\r'/'%0D'}"
echo "::error title=err::$ERR_MSG"
- Anyway to check the error message and retry?
- 社区里面用
||来 retry 命令, 但是我这个 shell 着实繁琐又不想写个 sh 文件, 忽略3 - 还有种思路就是利用
2> file输出错误信息, 判断4, 然后利用 workflow 的 API 来重新调用5, 调用代码如下- 注意
failure()标识 此 job 中存在失败 ${{ secrets.GH_PAT }}注意给 workflow 的权限workflow_id目前好像只能通过 list workflows 的 API 来获取- 可能导致无限调用, 但是可以将 retry 次数当做 input 传入, 然后判断大于多少次直接
exit 1 continue-on-error: true6 会导致failure判断失效
- 注意
- 社区里面用
- name: Failed
if: ${{ failure() }}
run: |
if grep -q 'errorMessage' err.log;
then curl --location --request POST 'https://api.github.com/repos/xxx/xxx/actions/workflows/xxxx/dispatches' \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Authorization: token ${{ secrets.GH_PAT }}' \
--header 'Content-Type: application/json' \
--data-raw '{
"ref": "main",
"inputs": {
"xxx": "${{github.event.inputs.xxx}}"
}
}'
fi
- 注意一点,
workflow_call不允许自己调用自己(错误信息如下), 所以可能只有上述方法可行
error parsing called workflow "bxb100/xxx/.github/workflows/download.yml@main": job "retry" calls workflow "bxb100/xxx/.github/workflows/download.yml@main", but doing so would exceed the limit on called workflow depth of 2
如何上传可执行文件到 release 中 (draft)
- 首先需要先创建一个 git ref tag 对应的 draft release, 注意此时的 tag 如果没有的话 GitHub 也不会主动给你绑定

see https://gist.github.com/bxb100/d2fedcb3cdc897062ee03920d6ae83be
- upload the artifact
- download artifacts, and compress them
- using
ghupload to the release
- name: Upload
run: |
until gh release upload --clobber --repo ${{ github.repository }} ${{ github.event.inputs.tag }} *.zip *.tar.gz; do
echo "Attempt $((++attempts)) to upload release artifacts failed. Will retry in 20s"
sleep 20
done
timeout-minutes: 10
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Examples
Github Action Cache Path
https://github.com/actions/toolkit/blob/e98bae803b6520b2a331f66011d812c3af8bf6ae/packages/cache
At the beginning, I tried to understand this path as a specified file glob expression, like this: ~/.m2/repository/**
but correct the way is upload directory like this: ~/.m2/repository/*/*/*
So don’t miss the point of what your need
Auto push to Marketplace
一般来说, GitHub action 如果要上传到 marketplace 的话需要生成 dist 目录, 但是可以通过 https://github.com/JasonEtco/build-and-tag-action 项目自动生成 dist 然后自动上传 (去除了非 dist, action.xml, 仓库大小减少了~~)
注意默认 github.token 权限问题: https://github.com/JasonEtco/build-and-tag-action/issues/40 注意一定要有 write 权限…
Reusable workflow
If you using a useable workflow, input with env will cause an error (test secrets, needs.xx.outputs.xxx working now)7
The workflow is not valid. xxxx: Unrecognized named-value: 'env'.
My work on https://github.com/BurtonQin/lockbud/pull/49 show that problems
solve the problem using a config like this:
with:
rust_version: ${{ needs.test.outputs.rust_version }}
Docker
In the Action, we have three ways to use the docker
- using container8, need to notice that runner is running a docker image
- using service9, it like expose a port to workflow runtime, so we don’t change the runner env
- using docker action10
在 PR 中使用 secret 的一些手段
- 使用
pull_request_target11, 我在 https://github.com/bxb100/action-test/pull/16/checks 中测试过, 需要配合 enviroment secret 的授权来做更严格的限制 - 通过
repository_dispatch触发12, 可以参看 https://github.com/1Password/load-secrets-action/blob/85e0e789db06bad7e43b5f7b0c36700967d04155/.github/workflows/ok-to-test.yml 用例, 可以通过 api 也可以通过一个新的 action 来 trigger (没想到的地方是, 这个能关联到正确的 commit-hash 中, 需要进步理解)
Footnotes
-
https://docs.github.com/en/actions/security-guides/encrypted-secrets#:~:text=Secrets%20cannot%20be%20directly%20referenced%20in%20if%3A%20conditionals.%20Instead%2C%20consider%20setting%20secrets%20as%20job%2Dlevel%20environment%20variables%2C%20then%20referencing%20the%20environment%20variables%20to%20conditionally%20run%20steps%20in%20the%20job. ↩
-
https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-secrets ↩
-
https://github.community/t/how-to-retry-a-failed-step-in-github-actions-workflow/125880 ↩
-
https://stackoverflow.com/questions/11287861/how-to-check-if-a-file-contains-a-specific-string-using-bash ↩
-
https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event Create a workflow dispatch event ↩
-
https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context ↩
-
https://docs.github.com/en/actions/using-jobs/running-jobs-in-a-container ↩
-
https://docs.github.com/en/actions/using-containerized-services/about-service-containers ↩
-
https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action ↩
-
https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request_target ↩
-
https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#repository_dispatch ↩