Skip to content

Commit

Permalink
fix: 实现github ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Lansongxx committed Jan 14, 2024
1 parent 49b634e commit 22b91b4
Show file tree
Hide file tree
Showing 13 changed files with 238 additions and 72 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "main" ]
tags: [ "v*.*.*" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
29 changes: 29 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI
on:
push:
branches: [ "main" ]
tags: [ "v*.*.*" ]
pull_request:
branches: [ "main" ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
run:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- linux-amd64-fmt
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
84 changes: 84 additions & 0 deletions .github/workflows/upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Upgrade

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
push:
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
REGISTRY: docker.io
USERNAME: lansongxx
IMAGE_NAME: cloudmind-sts

jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Bump Version
id: version
run: curl -s https://raw.githubusercontent.com/xh-polaris/chore/main/bump_version.sh | bash -s -- ${{ env.USERNAME }}/${{ env.IMAGE_NAME }}

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name == 'push'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.USERNAME }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
context: .
push: ${{ github.event_name == 'push' }}
tags: ${{ env.REGISTRY }}/${{ env.USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

deploy:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push'
steps:
- name: Setup Kubectl
uses: azure/setup-kubectl@v3
with:
version: ${{ vars.KUBE_VERSION }}

- name: Deploy
run: |
mkdir $HOME/.kube
echo "${{ secrets.KUBE_CONFIG }}" > $HOME/.kube/config
kubectl get deployment ${{ env.IMAGE_NAME }} -n ${{ vars.BASE_TEST_NAMESPACE }} -o yaml |\
sed 's/^\( - image: cloudmind\/${{ env.IMAGE_NAME }}:\).*$/\1${{ needs.build.outputs.version }}/' |\
kubectl apply -f -
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea
/data
/output
/output
etc
32 changes: 32 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
run:
go: '1.18'
timeout: 30m

linters:
disable-all: true
enable: # please keep this alphabetized
# Don't use soon to deprecated[1] linters that lead to false
# https://github.com/golangci/golangci-lint/issues/1841
# - deadcode
# - structcheck
# - varcheck
- ineffassign
- staticcheck
- stylecheck
- unused
- revive

linters-settings: # please keep this alphabetized
staticcheck:
checks:
- "all"
- "-SA1019" # TODO(fix) Using a deprecated function, variable, constant or field
- "-SA2002" # TODO(fix) Called testing.T.FailNow or SkipNow in a goroutine, which isn’t allowed
stylecheck:
checks:
- "ST1019" # Importing the same package multiple times.
revive:
rules:
- name: var-naming
disabled: true
arguments: [["ID", "URL", "RPC"]]
13 changes: 11 additions & 2 deletions biz/application/service/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,20 @@ func (s *AuthServiceImpl) CreateAuth(ctx context.Context, req *gensts.CreateAuth
return resp, err
}
}

auth := convertor.AuthToAuthMapper(req.AuthInfo)
_, err = s.UserMongoMapper.FindOneByAuth(ctx, auth)
switch {
case err == nil:
return resp, consts.ErrHaveExist
case errors.Is(err, consts.ErrNotFound):
break
default:
return resp, err
}
resp.UserId, err = s.UserMongoMapper.Insert(ctx, &usermapper.User{
PassWord: req.UserInfo.GetPassword(),
Role: int32(req.UserInfo.Role),
Auths: []*usermapper.Auth{convertor.AuthToAuthMapper(req.AuthInfo)},
Auths: []*usermapper.Auth{auth},
})
if err != nil {
log.CtxError(ctx, "插入用户授权信息异常[%v]\n", err)
Expand Down
5 changes: 0 additions & 5 deletions biz/infrastructure/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ type EmailConf struct {
Email string
}

type EtcdConf struct {
Hosts []string
}

type Config struct {
service.ServiceConf
ListenOn string
Expand All @@ -29,7 +25,6 @@ type Config struct {
CacheConf cache.CacheConf
Redis *redis.RedisConf
EmailConf EmailConf
EtcdConf EtcdConf
}

func NewConfig() (*Config, error) {
Expand Down
2 changes: 1 addition & 1 deletion biz/infrastructure/util/captcha/puzzle_captcha/captcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
const interferenceOptions = 1

func Run(ctx context.Context) (*CutoutRet, error) {
ctx, span := trace.TracerFromContext(ctx).Start(ctx, "captcha/Run", oteltrace.WithTimestamp(time.Now()), oteltrace.WithSpanKind(oteltrace.SpanKindClient))
_, span := trace.TracerFromContext(ctx).Start(ctx, "captcha/Run", oteltrace.WithTimestamp(time.Now()), oteltrace.WithSpanKind(oteltrace.SpanKindClient))
defer func() {
span.End(oteltrace.WithTimestamp(time.Now()))
}()
Expand Down
2 changes: 1 addition & 1 deletion biz/infrastructure/util/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
)

func SendEmail(ctx context.Context, EmailConf config.EmailConf, toEmail, subject string) (string, error) {
ctx, span := trace.TracerFromContext(ctx).Start(ctx, "auth/SendEmail", oteltrace.WithTimestamp(time.Now()), oteltrace.WithSpanKind(oteltrace.SpanKindClient))
_, span := trace.TracerFromContext(ctx).Start(ctx, "auth/SendEmail", oteltrace.WithTimestamp(time.Now()), oteltrace.WithSpanKind(oteltrace.SpanKindClient))
defer func() {
span.End(oteltrace.WithTimestamp(time.Now()))
}()
Expand Down
49 changes: 0 additions & 49 deletions etc/config.yaml

This file was deleted.

9 changes: 2 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@ module github.com/CloudStriver/cloudmind-sts
go 1.20

require (
github.com/CloudStriver/go-pkg v0.0.0-20231226132958-6fbd9aae788e
github.com/CloudStriver/service-idl-gen-go v0.0.0-20231227131904-e146acf60e9d
github.com/CloudStriver/go-pkg v0.0.0-20240114145206-6c35e12ed362
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240102102004-0a94d07773bf
github.com/cloudwego/kitex v0.8.0
github.com/google/wire v0.5.0
github.com/kitex-contrib/obs-opentelemetry v0.2.5
github.com/kitex-contrib/registry-etcd v0.2.0
github.com/pkg/errors v0.9.1
github.com/zeromicro/go-zero v1.6.1
go.mongodb.org/mongo-driver v1.13.1
go.opentelemetry.io/otel/trace v1.19.0
google.golang.org/grpc v1.60.1
)

replace (
github.com/CloudStriver/go-pkg => ../go-pkg
github.com/CloudStriver/service-idl-gen-go => ../service-idl-gen-go
)

require (
github.com/apache/thrift v0.16.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zum
git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3pc=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CloudStriver/go-pkg v0.0.0-20240101084050-e5fcface9afc h1:djrE2kATtcZaWgR7yRwkYaQ0m5lq8WvnwCpy3NM0Nw8=
github.com/CloudStriver/go-pkg v0.0.0-20240101084050-e5fcface9afc/go.mod h1:YiA6K1UfOe6dvwnWlWKY7eAmYknmM/3LjkGQN2yqjGI=
github.com/CloudStriver/go-pkg v0.0.0-20240114145206-6c35e12ed362 h1:phEgi4R337N2KeTqwp2wO/mbWeL8dlWbTPbtWLTJ3zc=
github.com/CloudStriver/go-pkg v0.0.0-20240114145206-6c35e12ed362/go.mod h1:547GMZ3ct2S2Lo40SoK//2HXR0Z6rgFiQL4XfzPZ1Bk=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240102102004-0a94d07773bf h1:qPSHaUNT6Pa/Mntvb1y0GPaJVGjtOUtOJfLINM+8euU=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240102102004-0a94d07773bf/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY=
Expand Down
Loading

0 comments on commit 22b91b4

Please sign in to comment.