本章将介绍如何使用 github action 实现自动化操作,如自动签到、issue 机器人、pull request 机器人等。
米游社原神自动每日签到 https://github.com/y1ndan/genshin-impact-helper
项目配置 .github\ISSUE_TEMPLATE\bug_report_cn.md 用户提交 issue 时自动渲染模板即
issue form 模板
Github 最新推出了 issue 模板功能,可以在 .github/ISSUE_TEMPLATE 目录下创建yml 模板文件,当用户新建 issue 时,会自动渲染模板内容。
相比较于 issue 模板,issue form 模板更加灵活,可以根据用户输入的内容,自动触发事件。
name: Report Bug | 报告BUG
description: "Report bug"
title: "[Bug]: "
labels: []
body:
  - type: dropdown
    id: download
    attributes:
      label: Installation Method | 安装方法与平台
      options:
        - Please choose | 请选择
        - Pip Install (I ignored requirements.txt)
        - Pip Install (I used latest requirements.txt)
        - OneKeyInstall (一键安装脚本-windows)
        - OneKeyInstall (一键安装脚本-mac)
        - Anaconda (I ignored requirements.txt)
        - Anaconda (I used latest requirements.txt)
        - Docker(Windows/Mac)
        - Docker(Linux)
        - Docker-Compose(Windows/Mac)
        - Docker-Compose(Linux)
        - Huggingface
        - Others (Please Describe)
    validations:
      required: true
其中 type 为输入框类型(dropdown, textarea),id 为输入框 id,label 为输入框标题,options 为下拉框选项。
## issue 机器人
根据操作自动回复,自动触发事件。如 issue 标记未 duplicate 自动关闭; 
配置文件 `.github\stale.yml`
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
https://github.com/features/actions
目前机器人都由 github action 实现,创建一个 `.github\workflows\close_issues.yml` 文件,即可实现自动化操作。
yml on: issues:
types: [opened]
pull_request_target:
types: [opened]
每隔 5 分钟检查一次 issue,如果 issue 未标记为 duplicate,自动关闭 issue。
yml on: schedule:
- cron: '*/5 * * * *'
jobs: stale:
runs-on: ubuntu-latest
steps:
  - uses: actions/stale@v8
    with:
      stale-issue-message: 'This issue is stale because it has been open 100 days with no activity. Remove stale label or comment or this will be closed in 1 days.'
      days-before-stale: 100
      days-before-close: 1
      debug-only: true
## pull request 机器人
用户发起 pull request 后,自动检查代码规范,自动合并代码,自动发布到 npm 等。如果 pull request结束后,自动关闭相关 issue。
```
配置 .github\FUNDING.yml 用于接受捐赠