Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Github actions of the release event. #238

Merged
merged 1 commit into from
Apr 19, 2020
Merged

Add Github actions of the release event. #238

merged 1 commit into from
Apr 19, 2020

Conversation

tomac4t
Copy link
Contributor

@tomac4t tomac4t commented Apr 17, 2020

  • Github workflows file.
  • Debian package script.
  • Assets upload script.

@tomac4t
Copy link
Contributor Author

tomac4t commented Apr 17, 2020

大概的过程是发布一个新 Release (不能是草稿)会触发 Github actions 事件,在名为 debiab-busterjobs 里会启动一个 debian:buster docker 容器(未来可以加其他容器方便在其他发行版中打包),在容器里面打包,调用 REST API 上传生成的文件(需要 token,使用 ${{ secrets.GITHUB_TOKEN }} 可以在 Github actions 里自动生成一个,不需要手动生成 Personal access tokens,60 分钟后失效)。

ncipollo/release-action@v1 是根据 Tag 事件触发后,自动 create release,再上传 assets。功能很丰富,支持 Changelog。我认为它没法在多个 jobs 里使用,因为 Release 会重复。

官方的 actions/upload-release-asset@v1 则更中规中举,REST API 需要什么就有哪些选项,所以无法像前者一样上传某一目录下所有 assets。

所以就用 python 自己写了上传脚本。

@tomac4t tomac4t marked this pull request as ready for review April 17, 2020 02:06
@SilverRainZ SilverRainZ self-requested a review April 17, 2020 02:18
@tomac4t
Copy link
Contributor Author

tomac4t commented Apr 17, 2020

One problem when I check build log: the tag (1.0.2-4) created on Web UI didn't fetch, Strange.
是两个 Tags 都在同一个 commit 上造成的,不过现实中一般不会发生。
https://github.com/tomac4t/srain/runs/593968735?check_suite_focus=true#step:5:35

@tomac4t
Copy link
Contributor Author

tomac4t commented Apr 18, 2020

I commit the personal token for test by accident. Fortunately, GitHub System immediately revoke my token:

Screenshot_2020-04-18 Build software better, together

@SilverRainZ
Copy link
Member

Q_Q 辛苦托马猫。

@SilverRainZ
Copy link
Member

官方的 actions/upload-release-asset@v1 则更中规中举,REST API 需要什么就有哪些选项,所以无法像前者一样上传某一目录下所有 assets。
所以就用 python 自己写了上传脚本。

我理解这是为了以后可能有多个 artifacts 做准备?用多个 upload-release-assert steps 能不能做到呢?

@tomac4t
Copy link
Contributor Author

tomac4t commented Apr 19, 2020

我理解这是为了以后可能有多个 artifacts 做准备?用多个 upload-release-assert steps 能不能做到呢?

是的,目前只有 amd64 的包, i386 的包我还没搞明白。upload-release-assert 多个 step 确实可以,但还有一个问题是文件名不是固定的(debian 包生成的文件名取决于 changlog 的版本号和 CPU 架构;他们那边也有类似的 issue,Dynamic Filenames:actions/upload-release-asset#4 ),不过似乎可以通过环境变量获取,就是有些麻烦了。

- Github workflows file.
- Debian package script.
- Assets upload script.
@SilverRainZ
Copy link
Member

明白了,既然他们还不够完善我们就用脚本吧,可以合了?

@tomac4t
Copy link
Contributor Author

tomac4t commented Apr 19, 2020

我觉得可以合了,我新开了一个 Private 仓库(怕刷了太多时间线和邮件)测试,目前没有发现问题。

做几个记录:

  • Upload a release asset 的 API 必须要求 Content-Type header,这里使用了 python mimetypes 库去判断文件类型。它纯粹是根据文件后缀判断的,如果遇到 README 这种没有后缀的就没有输出了。这一点比不上 file --mime-type [filename] 命令。所以没有的情况我设置成 application/octet-stream,不过未来应该不会遇到这种情况。
  • 在 API 中使用 ${{ secrets.GITHUB_TOKEN }} 生成的 token 都被记录为 github-actions[bot] 的操作,而不是其他人。

release:
types: [created]
jobs:
debiab-buster:
Copy link
Contributor Author

@tomac4t tomac4t Apr 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debiab-buster 这个 <job_id> 是我自己取的(也不知道合不合适),未来可以加更多 job,比如用其他 docker 容器打其他发行版的包。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get it.

@SilverRainZ SilverRainZ merged commit 5bb3d06 into SrainApp:master Apr 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants