-
Notifications
You must be signed in to change notification settings - Fork 530
73 lines (71 loc) · 2.63 KB
/
hub-mirror.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# workflow 名称
name: hub-mirror
# 当新建或者修改 issues 时,触发当前 workflow
on:
issues:
types: [opened, edited]
# 需要执行的任务列表
jobs:
# 镜像转换任务
mirror_transition:
# 运行环境
runs-on: ubuntu-latest
# 运行条件 => issues 的 label 包含 hub-mirror
if: contains(github.event.issue.labels.*.name, 'hub-mirror')
# 镜像转换任务的步骤列表
steps:
# 1. 切换分支(默认主分支)
- name: Check out code
uses: actions/checkout@v2
# 2. 设置 go 环境
- name: Setup go
uses: actions/setup-go@v4
with:
go-version: '1.20'
# 3. 运行 go 代码
- name: Run code
run: go run main.go --username=${{ secrets.DOCKER_USERNAME }} --password=${{ secrets.DOCKER_TOKEN }} --repository=${{ secrets.DOCKER_REPOSITORY }} --content='${{ github.event.issue.body }}' --maxContent=11 --outputPath=output.md
# 4. 当成功输出 output.md 文件时,为 issues 添加评论
- name: Add comment
if: ${{ hashFiles('output.md') }}
uses: actions/github-script@v5
with:
script: |
const fs = require('fs')
const data = fs.readFileSync('output.md', 'utf8')
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: data
})
# 5. 当以上步骤成功时,为 issues 添加 success 标签
- name: Success issues
if: ${{ success() }}
uses: actions/github-script@v5
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['success']
})
# 6. 当以上步骤失败时,为 issues 添加 failure 标签,并为其添加失败原因评论
- name: Failure issues
if: ${{ failure() }}
uses: actions/github-script@v5
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['failure']
})
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "[构建失败,点击查看](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
})