Closed TieWay59 closed 1 year ago
51255903048 仓库链接:https://github.com/DarkHighness/darkhighness.github.io 报告链接:https://twiliness.site/2023/05/15/github-action/
liao old NB!!!
共计 12 人次参与了报告评论
login | 学号 | 仓库链接 -- | -- | -- DarkHighness | 51255903048 | 仓库链接:https://github.com/DarkHighness/darkhighness.github.io abcdabcd3899 | 52265903006 | 仓库链接: https://github.com/abcdabcd3899/abcdabcd3899.github.io yygs-yyss | 51255903017 | 仓库链接:https://github.com/yygs-yyss/test_action springyulu | 51255903026 | 仓库链接:https://github.com/springyulu/test-action lroethan | 52265903002 | 仓库链接:https://github.com/lroethan/OSS-toy-action-example LinRS1999 | 51255903040 | 仓库链接:https://github.com/LinRS1999/test_action JinaoLiu | 51255903038 | 仓库链接:https://github.com/JinaoLiu/JinaoLiu.github.io momentNi | 51255903022 | 仓库链接:https://github.com/momentNi/momentni.github.io nicole01101101zke | 51255903101 | 仓库链接:https://github.com/nicole01101101zke/Test-For-Github-Action tyxtyxtyxtyx | 52265903007 | 仓库链接:https://github.com/tyxtyxtyxtyx/tyxtyxtyxtyx.github.io Kongbaimoon | 52265903009 | 仓库链接:https://github.com/Kongbaimoon/blog_hw JackWeiw | 51255903105 | 仓库链接:https://github.com/JackWeiw/JackWeiw.github.io
目标
写一个 github action,监听 issue comment 的创建事件,假如 comment 归属某些用户,那么就给这个 issue comment 添加一个互动 reaction,比如 eyes。
目的是帮助同学练习和深入理解 github action 的使用。
实现
https://github.com/X-lab2017/oss101/blob/b8024157f299d606ca8b2501382260085ffe481b/.github/workflows/add-reaction.yaml#L1-L22
示例仓库:TieWay59/issue-action-test
原理是借助环境变量筛选条件然后 curl github api。
Reaction API[^1]
其中:
application/vnd.github+json
是 Github API 使用的自定义媒体类型[^2]。它允许指定 API 版本和返回数据的格式。vnd 是 vendor 的缩写,表示这是一个供应商特定的媒体类型。<YOUR-TOKEN>
如果想要在 action 脚本中使用用户的 token,需要创建一个属于该用户的 Personal Access Token (PAT),然后将它存储在仓库或组织的 secrets 中,然后在 action 中使用${{ secrets.PAT_NAME }}
来引用它。上面的secrets.TIEWAY59_PAT
就是我个人的 token。Personal Access Token[^3]
相关的设置藏在
Settings > Developer settings > Personal access tokens
小节中。创建 Fine-grained PAT 需要定制需要启用的读写权限,这一步需要稍微注意一些。创建 PAT 以后, 打开仓库设置
Settings > secrets > Actions
点击new repository secret
添加 PAT。这里设置的变量名就是之后脚本中secrets.
可以访问的变量名。实践任务
(基础版)阅读以上材料,个人向课程仓库提交 PR,把自己的用户 login 加入到监听列表。
ci: add `<YOUR-LOGIN>` to reaction list
,比如ci: add `tieway59` to reaction list
。 PR 标题与此 commit 标题一致。.github/workflows/add-reaction.yml
文件,并且只会添加一行修改。(进阶版-选做)在自己的某个仓库加入类似的功能,提交简单的报告,以博客链接的形式放到本 issue 下方。
截止时间:5 月 28 日 23:59,请在截止日期前提交 PR,并确保 PR 能够被合并。逾期提交或提交失败的作业将不予评分。
[^1]: Create reaction for an issue comment [^2]: What is the application/vnd.github+json media type? - Stack Overflow [^3]: Creating a personal access token - GitHub Docs