-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ci/golangci): fix golangcl-lint git push and apply format code on…
… Push (#4077)
- Loading branch information
Showing
9 changed files
with
149 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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." | ||
# 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 |
This file contains 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 | ||
|
||
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 }} |
This file contains 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 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 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 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 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 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 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