-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(ci/golangci): fix golangcl-lint git push and apply format code on Push #4077
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
Merged
Merged
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
18e5fdf
modify golangci.yml
houseme cfcf2c2
fix
houseme 3cdd710
Apply gci import order changes
github-actions[bot] fe10691
up
houseme 120304e
fix
houseme eda7461
fix
houseme 3ccb760
fix
houseme a448d1e
Apply gci import order changes
github-actions[bot] 4eeba6b
test
houseme b60ae3c
fix
houseme 23c9601
fix
houseme 7909b47
Apply gci import order changes
github-actions[bot] 641b66a
fix
houseme 29d8caf
Fix/gci test 1224 (#4075)
housemecn 3750a42
Update apple-fix-to-fork.yml
houseme 0452668
Update provider.go (#4076)
housemecn 1089d29
Merge branch 'fix/gci-test' of github.com:gogf/gf into fix/modify-gol…
houseme a36054c
improve action config and create test
houseme 7a7cb8e
Apply gci import order changes [skip ci]
github-actions[bot] 5a39908
Update provider.go
houseme 3de35cc
Apply gci import order changes [skip ci]
github-actions[bot] 1493e67
improve code
houseme f9929be
remove `reviewdog/action-golangci-lint@v2` action
houseme 5e7fa47
improve comment
houseme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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." | ||
# 安装 gci | ||
echo "Installing gci..." | ||
go install github.com/daixiang0/gci@latest | ||
|
||
# 检查 gci 是否安装成功 | ||
if ! command -v gci &> /dev/null | ||
then | ||
echo "gci could not be installed. Please check your Go setup." | ||
exit 1 | ||
fi | ||
|
||
# 使用 gci 格式化代码 | ||
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)" \ | ||
./ | ||
|
||
# 检查代码是否有变化 | ||
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." | ||
|
||
# 添加本地域名到 /etc/hosts | ||
echo "Adding local domain to /etc/hosts..." | ||
sudo echo "127.0.0.1 local" | sudo tee -a /etc/hosts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Format code on Push | ||
houseme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
on: | ||
push | ||
|
||
jobs: | ||
apply-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 }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.