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 #3

Merged
merged 1 commit into from
Sep 27, 2024
Merged
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
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
26 changes: 26 additions & 0 deletions .github/workflows/typos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Spell Check Action
on: [pull_request]

jobs:
run:
name: Spell Check with Typos
runs-on: self-hosted
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4

- 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: 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"