Skip to content

Commit

Permalink
Gowork (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
duc-cnzj committed Apr 26, 2024
1 parent 6389a62 commit e0152b7
Show file tree
Hide file tree
Showing 293 changed files with 3,272 additions and 812 deletions.
36 changes: 12 additions & 24 deletions .github/workflows/release.yaml
@@ -1,8 +1,9 @@
name: release
on:
push:
tags:
- "v*"
tags-ignore:
- 'api/*'

jobs:
build-frontend:
name: build-frontend
Expand Down Expand Up @@ -141,34 +142,21 @@ jobs:
artifacts: "/tmp/app*"
token: ${{ secrets.GITHUB_TOKEN }}

release-client:
release-sdk:
needs: [release]
runs-on: ubuntu-latest
steps:
- name: Set output
id: vars
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- uses: actions/checkout@v3
- run: |
- name: tag sdk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.email "1025434218@qq.com"
git config --global user.name "release-robot"
git config --global user.name "duc"
git config --global init.defaultBranch "master"
git clone https://${{ secrets.MARS_CLIENT_REPO_ACCESS_TOKEN }}@github.com/DuC-cnZj/mars-client.git /tmp/client && \
(mkdir /tmp/new-client && \
cp -r ./pkg/* /tmp/new-client && \
mv /tmp/client/.git /tmp/new-client && \
cd /tmp/new-client && \
echo ${{ env.tag }} > /tmp/new-client/README.md && \
git add . && \
git commit -am "release ${{ env.tag }}" && \
git push origin master) || \
(mkdir /tmp/new-client && \
cp -r ./pkg/* /tmp/new-client && \
cd /tmp/new-client && \
git init && \
echo ${{ env.tag }} > /tmp/new-client/README.md && \
git add . && \
git commit -am "release ${{ env.tag }}" && \
git remote add origin https://${{ secrets.MARS_CLIENT_REPO_ACCESS_TOKEN }}@github.com/DuC-cnZj/mars-client.git && \
git push -u origin master)
cd /tmp/new-client && git tag ${{ env.tag }} && git push --tag
git tag api/$tag
git push origin api/$tag
57 changes: 54 additions & 3 deletions Makefile
@@ -1,4 +1,5 @@
VERSION_PATH=$(shell go list -m -f "{{.Path}}")/version
PROTO_FILES=$(shell find api -name *.proto)
LDFLAGS=-w -s \
-X ${VERSION_PATH}.gitBranch=$(shell git rev-parse --abbrev-ref HEAD) \
-X ${VERSION_PATH}.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
Expand All @@ -20,9 +21,59 @@ build_tools:
github.com/securego/gosec/v2/cmd/gosec \
github.com/golang/mock/mockgen


.PHONY: gen_proto
gen_proto:
cd hack && ./gen_proto.sh && cd ../ && make fmt
protoc \
--proto_path=./api \
--proto_path ./third_party/protos \
--go_out=paths=source_relative:./api \
--go-grpc_out=paths=source_relative:./api \
--openapiv2_out=./doc \
--openapiv2_opt logtostderr=true \
--openapiv2_opt json_names_for_fields=false \
--grpc-gateway_out=paths=source_relative:./api \
--grpc-gateway_opt logtostderr=true \
--grpc-gateway_opt paths=source_relative \
--grpc-gateway_opt generate_unbound_methods=true \
--validate_out=lang=go,paths=source_relative:./api \
$(PROTO_FILES)

./frontend/node_modules/.bin/pbjs -t static-module -o ./frontend/src/api/compiled.js -w es6 ./api/**/*.proto \
--keep-case \
--no-verify \
--no-convert \
--no-create \
--force-number \
--force-message \
--no-delimited
# --no-encode \
# --no-decode \
# https://github.com/protobufjs/protobuf.js/blob/master/cli/README.md#reflection-vs-static-code
# Static targets only:
#
# --no-create Does not generate create functions used for reflection compatibility.
# --no-encode Does not generate encode functions.
# --no-decode Does not generate decode functions.
# --no-verify Does not generate verify functions.
# --no-convert Does not generate convert functions like from/toObject
# --no-delimited Does not generate delimited encode/decode functions.
# --no-beautify Does not beautify generated code.
# --no-comments Does not output any JSDoc comments.
# --no-service Does not output service classes.
#
# --force-long Enforces the use of 'Long' for s-/u-/int64 and s-/fixed64 fields.
# --force-number Enforces the use of 'number' for s-/u-/int64 and s-/fixed64 fields.
# --force-message Enforces the use of message instances instead of plain objects.

./frontend/node_modules/.bin/pbts -o ./frontend/src/api/compiled.d.ts ./frontend/src/api/compiled.js --keep-case

swagger mixin --ignore-conflicts ./third_party/doc/data/api.json ./doc/**/*.json > ./third_party/doc/data/swagger.json

.PHONY: clear_proto
clear_proto:
rm -rf ./api/**/*.go

.PHONY: gen
gen:
Expand All @@ -41,7 +92,7 @@ release: build_linux_amd64 build_darwin_amd64 build_darwin_arm64

.PHONY: fmt
fmt:
gofmt -s -w ./pkg && \
gofmt -s -w ./api && \
gofmt -s -w -r 'interface{} -> any' ./internal ./plugins ./tools ./version ./third_party ./cmd && \
goimports -w ./

Expand Down Expand Up @@ -83,4 +134,4 @@ build_darwin_arm64:

.PHONY: build_windows
build_windows:
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o app.exe main.go
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o app.exe main.go
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -67,14 +67,14 @@ web 页面配置项目,开启全局配置。
## 🍀 go-sdk 接入

```
go get -u github.com/duc-cnzj/mars-client/v4
go get -u github.com/duc-cnzj/mars/api/v4
```

```golang
package main

import (
client "github.com/duc-cnzj/mars-client/v4"
client "github.com/duc-cnzj/mars/api/v4"
)

func main() {
Expand Down
10 changes: 5 additions & 5 deletions pkg/auth/auth.pb.go → api/auth/auth.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
Expand Up @@ -6,7 +6,7 @@ import "google/api/annotations.proto";
import "protoc-gen-openapiv2/options/annotations.proto";
import "validate/validate.proto";

option go_package = "github.com/duc-cnzj/mars-client/v4/auth;auth";
option go_package = "github.com/duc-cnzj/mars/api/v4/auth;auth";

message LoginRequest {
string username = 1 [(validate.rules).string.min_bytes = 1];
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/auth_grpc.pb.go → api/auth/auth_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions pkg/changelog/changelog.pb.go → api/changelog/changelog.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
Expand Up @@ -6,7 +6,7 @@ import "google/api/annotations.proto";
import "validate/validate.proto";
import "types/types.proto";

option go_package = "github.com/duc-cnzj/mars-client/v4/changelog;changelog";
option go_package = "github.com/duc-cnzj/mars/api/v4/changelog;changelog";

message ShowRequest {
int64 project_id = 1 [(validate.rules).int64.gt = 0];
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions pkg/client.go → api/client.go
Expand Up @@ -18,21 +18,21 @@ import (
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"

"github.com/duc-cnzj/mars-client/v4/auth"
"github.com/duc-cnzj/mars-client/v4/changelog"
"github.com/duc-cnzj/mars-client/v4/cluster"
"github.com/duc-cnzj/mars-client/v4/container"
"github.com/duc-cnzj/mars-client/v4/endpoint"
"github.com/duc-cnzj/mars-client/v4/event"
"github.com/duc-cnzj/mars-client/v4/file"
"github.com/duc-cnzj/mars-client/v4/git"
"github.com/duc-cnzj/mars-client/v4/gitconfig"
"github.com/duc-cnzj/mars-client/v4/metrics"
"github.com/duc-cnzj/mars-client/v4/namespace"
"github.com/duc-cnzj/mars-client/v4/picture"
"github.com/duc-cnzj/mars-client/v4/project"
"github.com/duc-cnzj/mars-client/v4/token"
"github.com/duc-cnzj/mars-client/v4/version"
"github.com/duc-cnzj/mars/api/v4/auth"
"github.com/duc-cnzj/mars/api/v4/changelog"
"github.com/duc-cnzj/mars/api/v4/cluster"
"github.com/duc-cnzj/mars/api/v4/container"
"github.com/duc-cnzj/mars/api/v4/endpoint"
"github.com/duc-cnzj/mars/api/v4/event"
"github.com/duc-cnzj/mars/api/v4/file"
"github.com/duc-cnzj/mars/api/v4/git"
"github.com/duc-cnzj/mars/api/v4/gitconfig"
"github.com/duc-cnzj/mars/api/v4/metrics"
"github.com/duc-cnzj/mars/api/v4/namespace"
"github.com/duc-cnzj/mars/api/v4/picture"
"github.com/duc-cnzj/mars/api/v4/project"
"github.com/duc-cnzj/mars/api/v4/token"
"github.com/duc-cnzj/mars/api/v4/version"
)

type Interface interface {
Expand Down
12 changes: 6 additions & 6 deletions pkg/cluster/cluster.pb.go → api/cluster/cluster.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
Expand Up @@ -5,7 +5,7 @@ package cluster;
import "google/api/annotations.proto";
import "protoc-gen-openapiv2/options/annotations.proto";

option go_package = "github.com/duc-cnzj/mars-client/v4/cluster;cluster";
option go_package = "github.com/duc-cnzj/mars/api/v4/cluster;cluster";

enum Status {
StatusUnknown = 0;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pkg/container/container.pb.go → api/container/container.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
Expand Up @@ -5,7 +5,7 @@ package container;
import "google/api/annotations.proto";
import "validate/validate.proto";

option go_package = "github.com/duc-cnzj/mars-client/v4/container;container";
option go_package = "github.com/duc-cnzj/mars/api/v4/container;container";

message CopyToPodRequest {
int64 file_id = 1 [(validate.rules).int64.gt = 0];
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e0152b7

Please sign in to comment.