X-lab2017 / oss101

开源软件通识三部曲
121 stars 155 forks source link

第九讲课后作业(截止时间5月28日) #139

Closed TieWay59 closed 1 year ago

TieWay59 commented 1 year ago

实践任务部分见文章末尾

目标

写一个 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

name: Add reaction
on:
  issue_comment:
    types: [created]
jobs:
  reaction:
    runs-on: ubuntu-latest
    if: |
      contains(fromJson('
        [
          "tc2000731",
          "will-ww",
        ]'), github.event.sender.login)
    steps:
      - name: Add reaction
        run: |
          curl -X POST \
            -H "Accept: application/vnd.github+json" \
            -H "Authorization: token ${{ secrets.TIEWAY59_PAT }}" \
            -H "X-GitHub-Api-Version: 2022-11-28" \
            https://api.github.com/repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions \
            -d '{"content": "eyes"}'

示例仓库:TieWay59/issue-action-test

原理是借助环境变量筛选条件然后 curl github api。

Reaction API[^1]

curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/OWNER/REPO/issues/comments/COMMENT_ID/reactions \
  -d '{"content":"heart"}'

其中:

Personal Access Token[^3]

相关的设置藏在 Settings > Developer settings > Personal access tokens 小节中。创建 Fine-grained PAT 需要定制需要启用的读写权限,这一步需要稍微注意一些。

创建 PAT 以后, 打开仓库设置 Settings > secrets > Actions 点击 new repository secret 添加 PAT。这里设置的变量名就是之后脚本中 secrets. 可以访问的变量名。

实践任务

  1. (基础版)阅读以上材料,个人向课程仓库提交 PR,把自己的用户 login 加入到监听列表。

    1. https://github.com/X-lab2017/oss101/blob/b8024157f299d606ca8b2501382260085ffe481b/.github/workflows/add-reaction.yaml#L10-L13
    2. 本作业的 PR 应该只包含一个 commit 名为 ci: add `<YOUR-LOGIN>` to reaction list,比如 ci: add `tieway59` to reaction list。 PR 标题与此 commit 标题一致。
    3. PR 正文部分可以留空。
    4. 作业 PR 应该只修改 .github/workflows/add-reaction.yml 文件,并且只会添加一行修改。
    5. 由于可能出现冲突的情况,助教建议采用强制提交修改历史的操作保持 PR 的原子性。
  2. (进阶版-选做)在自己的某个仓库加入类似的功能,提交简单的报告,以博客链接的形式放到本 issue 下方。

    1. 不必和课程提供的练习一致,比如 reaction 内容还有 heart 等其他选择。
    2. 反馈格式:
    51215903062
    仓库链接: https://github.com/TieWay59/issue-action-test
    报告链接: https://github.com/TieWay59/issue-action-test
  3. 截止时间: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

DarkHighness commented 1 year ago

51255903048 仓库链接:https://github.com/DarkHighness/darkhighness.github.io 报告链接:https://twiliness.site/2023/05/15/github-action/

abcdabcd3899 commented 1 year ago

52265903006 仓库链接: https://github.com/abcdabcd3899/abcdabcd3899.github.io 报告链接: https://github.com/abcdabcd3899/abcdabcd3899.github.io/actions/runs/5002351065 https://abcdabcd3899.github.io/blog-post-3/

yygs-yyss commented 1 year ago

51255903017 仓库链接:https://github.com/yygs-yyss/test_action 报告链接:https://yygs-yyss.github.io/2023/05/21/github_action/

springyulu commented 1 year ago

51255903026 仓库链接:https://github.com/springyulu/test-action 报告链接:https://springyulu.github.io/2023/05/23/github-actions/

lroethan commented 1 year ago

52265903002 仓库链接:https://github.com/lroethan/OSS-toy-action-example 报告链接:https://github.com/lroethan/OSS-toy-action-example/blob/master/README.md

LinRS1999 commented 1 year ago

51255903040 仓库链接:https://github.com/LinRS1999/test_action 报告链接:https://linrs1999.github.io/2023/05/23/github_action_demo/

JinaoLiu commented 1 year ago

51255903038 仓库链接:https://github.com/JinaoLiu/JinaoLiu.github.io 报告链接:https://jinaoliu.github.io/2023/05/24/GitHub-Actions%E4%BD%BF%E7%94%A8/

momentNi commented 1 year ago

51255903022 仓库链接:https://github.com/momentNi/momentni.github.io 报告链接:https://github.com/momentNi/momentni.github.io/blob/main/.github/workflows/README.md

JackWeiw commented 1 year ago

51255903048 仓库链接:https://github.com/DarkHighness/darkhighness.github.io 报告链接:https://twiliness.site/2023/05/15/github-action/

liao old NB!!!

nicole01101101zke commented 1 year ago

51255903101 仓库链接:https://github.com/nicole01101101zke/Test-For-Github-Action 报告链接:https://nicole01101101zke.github.io/2023/05/Github-Actions%E6%8A%A5%E5%91%8A/

tyxtyxtyxtyx commented 1 year ago

52265903007 仓库链接:https://github.com/tyxtyxtyxtyx/tyxtyxtyxtyx.github.io 报告链接:https://github.com/tyxtyxtyxtyx/tyxtyxtyxtyx.github.io/blob/main/readme.md

Kongbaimoon commented 1 year ago

52265903009 仓库链接:https://github.com/Kongbaimoon/blog_hw 报告链接:https://github.com/Kongbaimoon/blog_hw/blob/main/action.md

JackWeiw commented 1 year ago

51255903105 仓库链接 报告链接

TieWay59 commented 1 year ago

共计 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