Skip to content

Commit

Permalink
优化github ci
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Aug 29, 2021
1 parent 4d37fd8 commit 5d72c12
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 46 deletions.
5 changes: 2 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ config.yaml
*.zip
*.exe

scriptcat
cloudcat
/cloudcat

cloudcat.db
cloudcat.db
36 changes: 36 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: GoBuild

on:
push:
branches:
- main
- develop/*
pull_request:
branches:
- main
- develop/*

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16

- name: Build
run: make build

- name: Test
run: go test -v ./...
81 changes: 81 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: release

on:
push:
tags:
- '*'
workflow_dispatch:

jobs:

release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16

- name: Build
run: make build

- name: Test
run: go test -v ./...

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF:10}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
tags: codfrm/cloudcat:${{ steps.get_version.outputs.VERSION }}

- name: Create Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: scriptcat-${{ github.ref }}
body: |
'no description'
draft: false
prerelease: false

- name: Build Target
run: |
VERSION=${{ steps.get_version.outputs.VERSION }} GOOS=linux GOARCH=amd64 make target
tar -zcvf cloudcat-${{ steps.get_version.outputs.VERSION }}-linux-amd64.tar.gz cloudcat-${{ steps.get_version.outputs.VERSION }}-linux-amd64
- name: Upload Release Asset zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: cloudcat-${{ steps.get_version.outputs.VERSION }}-linux-amd64.tar.gz
asset_name: cloudcat-${{ steps.get_version.outputs.VERSION }}-linux-amd64.tar.gz
asset_content_type: application/tar+gz
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ config.yaml
*.zip
*.exe

scriptcat
cloudcat
/cloudcat

cloudcat.db
cloudcat.db
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ FROM ${ARCH}busybox:1.33.1-musl

WORKDIR /cloudcat

COPY --from=build /cloudcat/scriptcat .

COPY --from=build /cloudcat/cloudcat .

RUN ls -l && chmod +x scriptcat cloudcat
RUN ls -l && chmod +x cloudcat

ENTRYPOINT ["./scriptcat"]
ENTRYPOINT ["./cloudcat"]
17 changes: 9 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
VERSION=0.1.0
GOOS=linux
GOARCH=amd64
VERSION=v0.1.0
DOCKER_REPO=codfrm
REMOTE_REPO=$(DOCKER_REPO)/cloudcat:$(VERSION)

build: swagger scriptcat cloudcat
test:
go test -v ./...

.PHONY: scriptcat
scriptcat:
CGO_LDFLAGS="-static" go build -o scriptcat ./cmd/scriptcat

.PHONY: cloudcat
cloudcat:
build:
CGO_LDFLAGS="-static" go build -o cloudcat ./cmd/app

target:
CGO_LDFLAGS="-static" go build -o cloudcat-$(VERSION)-$(GOOS)-$(GOARCH)/cloudcat ./cmd/app

docker:
docker build -t cloudcat .

Expand Down
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@


# CloudCat

> 一个用于 **[ScriptCat脚本猫](https://docs.scriptcat.org/)** 扩展云端执行脚本的服务
![](https://img.shields.io/github/stars/scriptscat/cloudcat.svg)![](https://img.shields.io/github/v/tag/scriptscat/cloudcat.svg?label=version&sort=semver)



## 编译



```shell
make build
```
\* Windows编译需要安装Mingw64



## 运行

### ScriptCat运行



```
scriptcat bilibili.zip
```



### Docker运行

> 请注意Docker中时区问题


```shell
docker pull codfrm/cloudcat:0.1.0
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
```



File renamed without changes.
18 changes: 11 additions & 7 deletions cmd/app/main.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package main

import (
"github.com/scriptscat/cloudcat/internal/app"
"github.com/scriptscat/cloudcat/internal/pkg/config"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

func main() {
cfg, err := config.Init("config.yaml")
if err != nil {
logrus.Fatalln(err)
rootCmd := &cobra.Command{
Use: "cloudcat",
}

if err := app.Run(cfg); err != nil {
logrus.Fatalf("app start err: %v", err)
execCmd := newExecCmd()
serveCmd := newServeCmd()

rootCmd.AddCommand(execCmd.Commands()...)
rootCmd.AddCommand(serveCmd.Commands()...)

if err := rootCmd.Execute(); err != nil {
logrus.Fatalln(err)
}
}
40 changes: 40 additions & 0 deletions cmd/app/serve.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"fmt"

"github.com/scriptscat/cloudcat/internal/app"
"github.com/scriptscat/cloudcat/internal/pkg/config"
"github.com/spf13/cobra"
)

type serveCmd struct {
config string
}

func newServeCmd() *serveCmd {
return &serveCmd{}
}

func (s *serveCmd) Commands() []*cobra.Command {
ret := &cobra.Command{
Use: "serve [flag]",
Short: "运行脚本猫服务",
RunE: s.serve,
}
ret.Flags().StringVarP(&s.config, "config", "c", "config.yaml", "配置文件")

return []*cobra.Command{ret}
}

func (s *serveCmd) serve(cmd *cobra.Command, args []string) error {
cfg, err := config.Init(s.config)
if err != nil {
return err
}

if err := app.Run(cfg); err != nil {
return fmt.Errorf("app start err: %v", err)
}
return nil
}
20 changes: 0 additions & 20 deletions cmd/scriptcat/main.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/executor/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func Console() Option {
return func(opts *Options) {
if opts.log == nil {
if opts._log == nil {
return
}
console, _ := v8go.NewObjectTemplate(opts.iso)
Expand Down

0 comments on commit 5d72c12

Please sign in to comment.