mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
fix(ci/golangci): fix golangcl-lint git push and apply format code on Push (#4077)
This commit is contained in:
36
.github/workflows/before_script.sh
vendored
36
.github/workflows/before_script.sh
vendored
@ -1,6 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
find . -name "*.go" | xargs gofmt -w
|
||||
git diff --name-only --exit-code || if [ $? != 0 ]; then echo "Notice: gofmt check failed,please gofmt before pr." && exit 1; fi
|
||||
echo "gofmt check pass."
|
||||
# Install gci
|
||||
echo "Installing gci..."
|
||||
go install github.com/daixiang0/gci@latest
|
||||
|
||||
# Check if the GCI is installed successfully
|
||||
if ! command -v gci &> /dev/null
|
||||
then
|
||||
echo "gci could not be installed. Please check your Go setup."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Use GCI to format the code
|
||||
echo "Running gci to format code..."
|
||||
gci write \
|
||||
--custom-order \
|
||||
--skip-generated \
|
||||
--skip-vendor \
|
||||
-s standard \
|
||||
-s blank \
|
||||
-s default \
|
||||
-s dot \
|
||||
-s "prefix(github.com/gogf/gf/v2)" \
|
||||
-s "prefix(github.com/gogf/gf/cmd)" \
|
||||
-s "prefix(github.com/gogf/gf/contrib)" \
|
||||
-s "prefix(github.com/gogf/gf/example)" \
|
||||
./
|
||||
|
||||
# Check the code for changes
|
||||
git diff --name-only --exit-code || if [ $? != 0 ]; then echo "Notice: gci check failed, please gci before pr." && exit 1; fi
|
||||
echo "gci check pass."
|
||||
|
||||
# Add the local domain name to `/etc/hosts`
|
||||
echo "Adding local domain to /etc/hosts..."
|
||||
sudo echo "127.0.0.1 local" | sudo tee -a /etc/hosts
|
||||
61
.github/workflows/format-code-on-push.yml
vendored
Normal file
61
.github/workflows/format-code-on-push.yml
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
name: Format Code on Push
|
||||
|
||||
on:
|
||||
push
|
||||
|
||||
jobs:
|
||||
format-code:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [ 'stable' ]
|
||||
name: format-code-by-gci
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Golang ${{ matrix.go-version }}
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
- name: Install gci
|
||||
run: go install github.com/daixiang0/gci@latest
|
||||
- name: Run gci
|
||||
run: |
|
||||
gci write --custom-order \
|
||||
--skip-generated \
|
||||
--skip-vendor \
|
||||
-s standard \
|
||||
-s blank \
|
||||
-s default \
|
||||
-s dot \
|
||||
-s "prefix(github.com/gogf/gf/v2)" \
|
||||
-s "prefix(github.com/gogf/gf/cmd)" \
|
||||
-s "prefix(github.com/gogf/gf/contrib)" \
|
||||
-s "prefix(github.com/gogf/gf/example)" \
|
||||
./
|
||||
- name: Check for changes
|
||||
run: |
|
||||
if [[ -n "$(git status --porcelain)" ]]; then
|
||||
echo "HAS_CHANGES=true" >> $GITHUB_ENV
|
||||
else
|
||||
echo "HAS_CHANGES=false" >> $GITHUB_ENV
|
||||
fi
|
||||
- name: Configure Git
|
||||
run: |
|
||||
if [[ "$HAS_CHANGES" == 'true' ]]; then
|
||||
git config --global user.name "github-actions[bot]"
|
||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||
else
|
||||
echo "HAS_CHANGES= $HAS_CHANGES "
|
||||
fi
|
||||
- name: Commit and push changes
|
||||
run: |
|
||||
if [[ "$HAS_CHANGES" == 'true' ]]; then
|
||||
git add .
|
||||
git commit -m "Apply gci import order changes"
|
||||
git push origin ${{ github.event.pull_request.head.ref }}
|
||||
else
|
||||
echo "No change to commit push"
|
||||
fi
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
44
.github/workflows/golangci-lint.yml
vendored
44
.github/workflows/golangci-lint.yml
vendored
@ -4,7 +4,7 @@
|
||||
# If a copy of the MIT was not distributed with this file,
|
||||
# You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
name: GolangCI-Lint
|
||||
name: GolangCI Lint
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
@ -26,11 +26,11 @@ on:
|
||||
- feat/**
|
||||
|
||||
jobs:
|
||||
golangci:
|
||||
golang-ci:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [ 'stable' ]
|
||||
name: golangci-lint
|
||||
name: golang-ci-lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
@ -39,44 +39,12 @@ jobs:
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
- name: golangci-lint
|
||||
- name: golang-ci-lint
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
# Required: specify the golangci-lint version without the patch version to always use the latest patch.
|
||||
version: v1.62.2
|
||||
only-new-issues: true
|
||||
skip-cache: true
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
args: --timeout 3m0s
|
||||
- name: Install gci
|
||||
run: go install github.com/daixiang0/gci@latest
|
||||
- name: Run gci
|
||||
run: |
|
||||
gci write --custom-order \
|
||||
--skip-generated \
|
||||
--skip-vendor \
|
||||
-s standard \
|
||||
-s blank \
|
||||
-s default \
|
||||
-s dot \
|
||||
-s "prefix(github.com/gogf/gf/v2)" \
|
||||
-s "prefix(github.com/gogf/gf/cmd)" \
|
||||
-s "prefix(github.com/gogf/gf/contrib)" \
|
||||
-s "prefix(github.com/gogf/gf/example)" \
|
||||
./
|
||||
- name: Check for changes
|
||||
# Check if the event is a push or a pull request from a forked repository
|
||||
if: github.event_name == 'push'|| (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true)
|
||||
run: |
|
||||
if [[ -n "$(git status --porcelain)" ]]; then
|
||||
echo "HAS_CHANGES=true" >> $GITHUB_ENV
|
||||
else
|
||||
echo "HAS_CHANGES=false" >> $GITHUB_ENV
|
||||
fi
|
||||
- name: Commit and push changes
|
||||
if: env.HAS_CHANGES == 'true'
|
||||
run: |
|
||||
git config --global user.name "github-actions[bot]"
|
||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git add .
|
||||
git commit -m "Apply gci import order changes"
|
||||
git push origin HEAD:$(git rev-parse --abbrev-ref HEAD)
|
||||
args: --timeout 3m0s --config=.golangci.yml -v
|
||||
|
||||
6
.github/workflows/issue-check-inactive.yml
vendored
6
.github/workflows/issue-check-inactive.yml
vendored
@ -1,12 +1,12 @@
|
||||
# 规则描述:每天凌晨3点(GMT+8)执行一次,将最近7天没有活跃且非BUG的ISSUE设置标签:inactive
|
||||
# Rule description: Execute the ISSUE once a day at 3 a.m. (GMT+8) and set the non-bug issue that has not been active in the last 7 days to inactive
|
||||
name: Issue Check Inactive
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 19 * * *"
|
||||
|
||||
env: # 设置环境变量
|
||||
TZ: Asia/Shanghai #时区(设置时区可使页面中的`最近更新时间`使用时区时间)
|
||||
env: # Set environment variables
|
||||
TZ: Asia/Shanghai #Time zone (setting the time zone allows the 'Last Updated' on the page to use the time zone)
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
6
.github/workflows/issue-close-inactive.yml
vendored
6
.github/workflows/issue-close-inactive.yml
vendored
@ -1,12 +1,12 @@
|
||||
# 规则描述:每天凌晨 4 点 (GMT+8) 执行一次,将最近 30 天没有活跃且非 BUG 的 ISSUE 关闭
|
||||
# RULE DESCRIPTION: EXECUTED ONCE A DAY AT 4 A.M. (GMT+8) TO CLOSE NON-BUG ISSUES THAT HAVE NOT BEEN ACTIVE IN THE LAST 30 DAYS
|
||||
name: Issue Close Inactive
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 20 * * *"
|
||||
|
||||
env: # 设置环境变量
|
||||
TZ: Asia/Shanghai #时区(设置时区可使页面中的`最近更新时间`使用时区时间)
|
||||
env: # Set environment variables
|
||||
TZ: Asia/Shanghai #Time zone (setting the time zone allows the 'Last Updated' on the page to use the time zone)
|
||||
|
||||
jobs:
|
||||
close-issues:
|
||||
|
||||
6
.github/workflows/issue-labeled.yml
vendored
6
.github/workflows/issue-labeled.yml
vendored
@ -1,4 +1,4 @@
|
||||
## 规则描述:当 issue 被标记为 help wanted 时,增加评论
|
||||
## Rule description: Add comments when an issue is marked as help wanted
|
||||
|
||||
name: Issue Labeled
|
||||
|
||||
@ -6,8 +6,8 @@ on:
|
||||
issues:
|
||||
types: [labeled]
|
||||
|
||||
env: # 设置环境变量
|
||||
TZ: Asia/Shanghai # 时区(设置时区可使页面中的`最近更新时间`使用时区时间)
|
||||
env: # Set environment variables
|
||||
TZ: Asia/Shanghai # Time zone (setting the time zone allows the 'Last Updated' on the page to use the time zone)
|
||||
|
||||
jobs:
|
||||
reply-labeled:
|
||||
|
||||
6
.github/workflows/issue-remove-inactive.yml
vendored
6
.github/workflows/issue-remove-inactive.yml
vendored
@ -1,4 +1,4 @@
|
||||
# 规则描述:在 issue 没有活跃且尚未被关闭期间,若 issue 作者更新或评论该 ISSUE,则移除其 inactive 标签
|
||||
# Rule description: If an issue author updates or comments on an issue while it is not active and has not been closed, the inactive tag will be removed
|
||||
name: Issue Remove Inactive
|
||||
|
||||
on:
|
||||
@ -7,8 +7,8 @@ on:
|
||||
issue_comment:
|
||||
types: [created, edited]
|
||||
|
||||
env: # 设置环境变量
|
||||
TZ: Asia/Shanghai #时区(设置时区可使页面中的`最近更新时间`使用时区时间)
|
||||
env: # Set environment variables
|
||||
TZ: Asia/Shanghai #Time zone (setting the time zone allows the 'Last Updated' on the page to use the time zone)
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# 规则描述:将需要提供更多细节且暂未关闭的 issue,在 issue 作者评论后,移除 need more details 标签
|
||||
# Rule Description: For issues that need more details and are not yet closed, remove the "need more details" tag after the issue author comments
|
||||
name: Issue Remove Need More Details
|
||||
|
||||
on:
|
||||
@ -7,8 +7,8 @@ on:
|
||||
issue_comment:
|
||||
types: [created, edited]
|
||||
|
||||
env: # 设置环境变量
|
||||
TZ: Asia/Shanghai #时区(设置时区可使页面中的`最近更新时间`使用时区时间)
|
||||
env: # Set environment variables
|
||||
TZ: Asia/Shanghai #Time zone (setting the time zone allows the 'Last Updated' on the page to use the time zone)
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
Reference in New Issue
Block a user