Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub workflows zherphy #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down
13 changes: 3 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
30 changes: 30 additions & 0 deletions .github/workflows/moderation_tag_check.yml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 15 additions & 15 deletions .github/workflows/typos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- name: Writes changes in the local checkout
uses: crate-ci/typos@master
with:
write_changes: true
41 changes: 41 additions & 0 deletions scripts/moderation_tag_check.sh
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions typos.toml
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 3 additions & 2 deletions utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading