diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index cc37540..c6164fd 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.20' + go-version: '1.23.1' - name: Build run: go build -v ./... diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 84ddaaf..3f61c18 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -20,14 +20,9 @@ concurrency: jobs: golangci: name: lint - runs-on: [self-hosted, Linux] + runs-on: self-hosted steps: - uses: actions/checkout@v4 - - name: config github - env: - TOKEN: ${{ secrets.ACCESS_TOKEN }} - USER: ${{ secrets.USER_NAME }} - run: echo "machine github.com login $USER password $TOKEN" > ~/.netrc - name: golangci-lint uses: golangci/golangci-lint-action@master with: @@ -43,11 +38,9 @@ jobs: - name: Run Gosec Security Scanner uses: securego/gosec@master - env: - GITHUB_AUTHENTICATION_TOKEN: ${{ secrets.ACCESS_TOKEN }} with: - args: -exclude-dir api -exclude-dir tests ./... + args: -exclude-dir BigFiles -exclude-dir utils ./... - name: Unit tests run: go test -race -count=1 -v ./... - name: cleanup - run: rm -f ~/.netrc + run: rm -f ~/.netrc \ No newline at end of file diff --git a/.github/workflows/moderation_tag_check.yml b/.github/workflows/moderation_tag_check.yml new file mode 100644 index 0000000..ce7bee4 --- /dev/null +++ b/.github/workflows/moderation_tag_check.yml @@ -0,0 +1,30 @@ +name: Check Moderation Tag + +on: + workflow_dispatch: + pull_request: + branches: [ '*' ] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + + build: + + runs-on: self-hosted + + steps: + - uses: actions/checkout@v4 + - name: config github + env: + TOKEN: ${{ secrets.PKKING_PERSONAL_TOKEN }} + USER: ${{ secrets.USER_NAME }} + run: echo "machine github.com login $USER password $TOKEN" > ~/.netrc && chmod 400 ~/.netrc + - name: Run moderation tag check script + run: cd scripts && bash -x moderation_tag_check.sh + - name: Self Hosted Runner Post Job Cleanup Action + uses: TooMuch4U/actions-clean@master + - name: cleanup + run: rm -rf ~/.netrc \ No newline at end of file diff --git a/.github/workflows/typos.yml b/.github/workflows/typos.yml index 82fec9a..a1d3486 100644 --- a/.github/workflows/typos.yml +++ b/.github/workflows/typos.yml @@ -6,21 +6,21 @@ jobs: name: Spell Check with Typos runs-on: self-hosted steps: - - name: Checkout Actions Repository - uses: actions/checkout@v4 + - name: Checkout Actions Repository + uses: actions/checkout@v4 - - name: Check spelling - uses: crate-ci/typos@master - with: - files: ./ + - name: Check spelling + uses: crate-ci/typos@master + with: + files: ./ - - name: Use custom config file - uses: crate-ci/typos@master - with: - files: ./ - config: ./typos.toml + - name: Use custom config file + uses: crate-ci/typos@master + with: + files: ./ + config: ./typos.toml - - name: Writes changes in the local checkout - uses: crate-ci/typos@master - with: - write_changes: true \ No newline at end of file + - name: Writes changes in the local checkout + uses: crate-ci/typos@master + with: + write_changes: true \ No newline at end of file diff --git a/scripts/moderation_tag_check.sh b/scripts/moderation_tag_check.sh new file mode 100644 index 0000000..a342fc4 --- /dev/null +++ b/scripts/moderation_tag_check.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +PATH_CURRUNT=$(pwd) +CODE_HOME="$PATH_CURRUNT/../../" + +function main() +{ + cd $CODE_HOME 2>&1 >/dev/null + + # 遍历当前目录下所有的go文件 + for file in $(find . -name "*.go"); do + + # 使用awk来查找结构体定义 + awk ' + BEGIN { inside_struct = 0; moderation_count = 0; } + /type [A-Za-z0-9_]+ struct {/ { inside_struct = 1; moderation_count = 0; } + /}/ { + if (inside_struct && moderation_count > 1) { + print "File " FILENAME " has a struct with multiple binding:\"moderationcheck\" tags"; + exit 1; + } + inside_struct = 0; + } + { + if (inside_struct && /binding:"moderationcheck"/) { + moderation_count++; + } + } + ' FILENAME=$file $file + + # 检查awk的退出状态 + if [ $? -ne 0 ]; then + echo "do check moderation tag failed" + exit 127 + fi + done + + echo "All structs are valid" +} + +main \ No newline at end of file diff --git a/typos.toml b/typos.toml new file mode 100644 index 0000000..9a1e9b4 --- /dev/null +++ b/typos.toml @@ -0,0 +1,33 @@ +[files] +extend-exclude = [ +"*.yaml", +"*.yml", +"*.md", +"*.sh", +"*.tpl", +"go.mod", +"go.sum", +"tests/", +"api/", +] +ignore-hidden = true +ignore-files = true +ignore-dot = true +ignore-vcs = true +ignore-global = true +ignore-parent = true + +[default] +locale = "en" +extend-glob = [] +extend-ignore-identifiers = [] +extend-ignore-words-re = [] +extend-ignore-re = [] + +[default.extend-identifiers] +cann_version = "cann_version" +CannVersion = "CannVersion" +Encrypter = "Encrypter" +NotificatonWeb = "NotificatonWeb" +Mininum = "Mininum" +cannVersion = "cannVersion" \ No newline at end of file diff --git a/utils/util.go b/utils/util.go index 884a3af..6806c5d 100644 --- a/utils/util.go +++ b/utils/util.go @@ -6,8 +6,9 @@ import ( "sigs.k8s.io/yaml" ) -func LoadFromYaml(path string, cfg interface{}) error { - b, err := os.ReadFile(path) +// LoadFromYaml reads a YAML file from the given path and unmarshals it into the provided interface. +func LoadFromYaml(filePath string, cfg interface{}) error { + b, err := os.ReadFile(filePath) if err != nil { return err }