Skip to content

Commit 5d72c12

Browse files
committed
优化github ci
1 parent 4d37fd8 commit 5d72c12

12 files changed

Lines changed: 228 additions & 46 deletions

File tree

.dockerignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ config.yaml
66
*.zip
77
*.exe
88

9-
scriptcat
10-
cloudcat
9+
/cloudcat
1110

12-
cloudcat.db
11+
cloudcat.db

.github/workflows/build.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: GoBuild
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop/*
8+
pull_request:
9+
branches:
10+
- main
11+
- develop/*
12+
13+
jobs:
14+
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
- uses: actions/cache@v2
20+
with:
21+
path: |
22+
~/.cache/go-build
23+
~/go/pkg/mod
24+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
25+
restore-keys: |
26+
${{ runner.os }}-go-
27+
- name: Set up Go
28+
uses: actions/setup-go@v2
29+
with:
30+
go-version: 1.16
31+
32+
- name: Build
33+
run: make build
34+
35+
- name: Test
36+
run: go test -v ./...

.github/workflows/release.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
11+
release:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/cache@v2
16+
with:
17+
path: |
18+
~/.cache/go-build
19+
~/go/pkg/mod
20+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
21+
restore-keys: |
22+
${{ runner.os }}-go-
23+
- name: Set up Go
24+
uses: actions/setup-go@v2
25+
with:
26+
go-version: 1.16
27+
28+
- name: Build
29+
run: make build
30+
31+
- name: Test
32+
run: go test -v ./...
33+
34+
- name: Set up QEMU
35+
uses: docker/setup-qemu-action@v1
36+
- name: Set up Docker Buildx
37+
uses: docker/setup-buildx-action@v1
38+
- name: Login to DockerHub
39+
uses: docker/login-action@v1
40+
with:
41+
username: ${{ secrets.DOCKERHUB_USERNAME }}
42+
password: ${{ secrets.DOCKERHUB_TOKEN }}
43+
44+
- name: Get version
45+
id: get_version
46+
run: echo ::set-output name=VERSION::${GITHUB_REF:10}
47+
48+
- name: Build and push
49+
id: docker_build
50+
uses: docker/build-push-action@v2
51+
with:
52+
push: true
53+
tags: codfrm/cloudcat:${{ steps.get_version.outputs.VERSION }}
54+
55+
- name: Create Release
56+
id: create_release
57+
uses: actions/create-release@latest
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
with:
61+
tag_name: ${{ github.ref }}
62+
release_name: scriptcat-${{ github.ref }}
63+
body: |
64+
'no description'
65+
draft: false
66+
prerelease: false
67+
68+
- name: Build Target
69+
run: |
70+
VERSION=${{ steps.get_version.outputs.VERSION }} GOOS=linux GOARCH=amd64 make target
71+
tar -zcvf cloudcat-${{ steps.get_version.outputs.VERSION }}-linux-amd64.tar.gz cloudcat-${{ steps.get_version.outputs.VERSION }}-linux-amd64
72+
73+
- name: Upload Release Asset zip
74+
uses: actions/upload-release-asset@v1
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
with:
78+
upload_url: ${{ steps.create_release.outputs.upload_url }}
79+
asset_path: cloudcat-${{ steps.get_version.outputs.VERSION }}-linux-amd64.tar.gz
80+
asset_name: cloudcat-${{ steps.get_version.outputs.VERSION }}-linux-amd64.tar.gz
81+
asset_content_type: application/tar+gz

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ config.yaml
66
*.zip
77
*.exe
88

9-
scriptcat
10-
cloudcat
9+
/cloudcat
1110

12-
cloudcat.db
11+
cloudcat.db

Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ FROM ${ARCH}busybox:1.33.1-musl
1818

1919
WORKDIR /cloudcat
2020

21-
COPY --from=build /cloudcat/scriptcat .
22-
2321
COPY --from=build /cloudcat/cloudcat .
2422

25-
RUN ls -l && chmod +x scriptcat cloudcat
23+
RUN ls -l && chmod +x cloudcat
2624

27-
ENTRYPOINT ["./scriptcat"]
25+
ENTRYPOINT ["./cloudcat"]

Makefile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
VERSION=0.1.0
1+
GOOS=linux
2+
GOARCH=amd64
3+
VERSION=v0.1.0
24
DOCKER_REPO=codfrm
35
REMOTE_REPO=$(DOCKER_REPO)/cloudcat:$(VERSION)
46

5-
build: swagger scriptcat cloudcat
7+
test:
8+
go test -v ./...
69

7-
.PHONY: scriptcat
8-
scriptcat:
9-
CGO_LDFLAGS="-static" go build -o scriptcat ./cmd/scriptcat
10-
11-
.PHONY: cloudcat
12-
cloudcat:
10+
build:
1311
CGO_LDFLAGS="-static" go build -o cloudcat ./cmd/app
1412

13+
target:
14+
CGO_LDFLAGS="-static" go build -o cloudcat-$(VERSION)-$(GOOS)-$(GOARCH)/cloudcat ./cmd/app
15+
1516
docker:
1617
docker build -t cloudcat .
1718

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
1+
2+
13
# CloudCat
24

5+
> 一个用于 **[ScriptCat脚本猫](https://docs.scriptcat.org/)** 扩展云端执行脚本的服务
6+
7+
![](https://img.shields.io/github/stars/scriptscat/cloudcat.svg)![](https://img.shields.io/github/v/tag/scriptscat/cloudcat.svg?label=version&sort=semver)
8+
9+
10+
11+
## 编译
12+
13+
14+
15+
```shell
16+
make build
17+
```
18+
\* Windows编译需要安装Mingw64
19+
20+
21+
22+
## 运行
23+
24+
### ScriptCat运行
25+
26+
27+
28+
```
29+
scriptcat bilibili.zip
30+
```
31+
32+
33+
34+
### Docker运行
35+
36+
> 请注意Docker中时区问题
37+
38+
39+
40+
```shell
41+
docker pull codfrm/cloudcat:0.1.0
42+
docker run -it -v $(PWD)/bilibili.zip:/cloudcat/bilibili.zip -v /etc/localtime:/etc/localtime -v /etc/timezone:/etc/timezone codfrm/cloudcat:0.1.0 exec bilibili.zip
43+
```
44+
45+
46+
File renamed without changes.

cmd/app/main.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
package main
22

33
import (
4-
"github.com/scriptscat/cloudcat/internal/app"
5-
"github.com/scriptscat/cloudcat/internal/pkg/config"
64
"github.com/sirupsen/logrus"
5+
"github.com/spf13/cobra"
76
)
87

98
func main() {
10-
cfg, err := config.Init("config.yaml")
11-
if err != nil {
12-
logrus.Fatalln(err)
9+
rootCmd := &cobra.Command{
10+
Use: "cloudcat",
1311
}
1412

15-
if err := app.Run(cfg); err != nil {
16-
logrus.Fatalf("app start err: %v", err)
13+
execCmd := newExecCmd()
14+
serveCmd := newServeCmd()
15+
16+
rootCmd.AddCommand(execCmd.Commands()...)
17+
rootCmd.AddCommand(serveCmd.Commands()...)
18+
19+
if err := rootCmd.Execute(); err != nil {
20+
logrus.Fatalln(err)
1721
}
1822
}

cmd/app/serve.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/scriptscat/cloudcat/internal/app"
7+
"github.com/scriptscat/cloudcat/internal/pkg/config"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
type serveCmd struct {
12+
config string
13+
}
14+
15+
func newServeCmd() *serveCmd {
16+
return &serveCmd{}
17+
}
18+
19+
func (s *serveCmd) Commands() []*cobra.Command {
20+
ret := &cobra.Command{
21+
Use: "serve [flag]",
22+
Short: "运行脚本猫服务",
23+
RunE: s.serve,
24+
}
25+
ret.Flags().StringVarP(&s.config, "config", "c", "config.yaml", "配置文件")
26+
27+
return []*cobra.Command{ret}
28+
}
29+
30+
func (s *serveCmd) serve(cmd *cobra.Command, args []string) error {
31+
cfg, err := config.Init(s.config)
32+
if err != nil {
33+
return err
34+
}
35+
36+
if err := app.Run(cfg); err != nil {
37+
return fmt.Errorf("app start err: %v", err)
38+
}
39+
return nil
40+
}

0 commit comments

Comments
 (0)