Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
togettoyou committed Jan 21, 2022
0 parents commit 8ce7c14
Show file tree
Hide file tree
Showing 7 changed files with 1,279 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/ISSUE_TEMPLATE/hub-mirror.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: hub-mirror issue template
about: 用于执行 hub-mirror workflow 的 issue 模板
title: "[hub-mirror] 请求执行任务"
labels: ["hub-mirror"]
---

{
"hub-mirror": [
"你需要转换的镜像",
"你需要转换的镜像",
"最多 10 个",
"......"
]
}
87 changes: 87 additions & 0 deletions .github/workflows/hub-mirror.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# workflow 名称
name: hub-mirror

# 当新建 issues 时,触发当前 workflow
on:
issues:
types:
- opened

# 需要执行的任务列表
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@v2
with:
go-version: 1.17
# 3. 运行 go 代码
- name: Run code
run: go run main.go --username=${{ secrets.DOCKERHUB_USERNAME }} --password=${{ secrets.DOCKERHUB_TOKEN }} --content='${{ github.event.issue.body }}' --maxContent=10 --outputPath=output.sh
# 4. 当成功输出 output.sh 文件时,为 issues 添加评论
- name: Add comment
if: ${{ hashFiles('output.sh') }}
uses: actions/github-script@v5
with:
script: |
const fs = require('fs')
const data = fs.readFileSync('output.sh', 'utf8')
const body = "Hello,您可以直接执行该命令:\n" +
"\n" +
"```shell\n" +
"echo -e '" + data.replace(/\n/g, '\\n') + "' | bash\n" +
"```\n" +
"\n" +
"或是手动执行:\n" +
"\n" +
"```shell\n" +
data +
"```\n" +
"\n" +
"希望可以帮助到您,祝您周" + "日一二三四五六".charAt(new Date().getDay()) + "愉快!"
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})
# 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 }})"
})
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
.idea/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 寻寻觅觅的Gopher

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
32 changes: 32 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module hub-mirror

go 1.17

require (
github.com/docker/docker v20.10.12+incompatible
github.com/spf13/pflag v1.0.5
)

require (
github.com/Microsoft/go-winio v0.4.17 // indirect
github.com/containerd/containerd v1.5.9 // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a // indirect
google.golang.org/grpc v1.43.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gotest.tools/v3 v3.1.0 // indirect
)
Loading

0 comments on commit 8ce7c14

Please sign in to comment.