Skip to content

Commit 0dc4df2

Browse files
committed
Add Go code analyzer workflow
1 parent 554981d commit 0dc4df2

File tree

3 files changed

+50
-18
lines changed

3 files changed

+50
-18
lines changed

.github/workflows/release.yml

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ name: Release 3X-UI
22

33
on:
44
workflow_dispatch:
5-
release:
6-
types: [published]
75
push:
8-
branches:
9-
- main
106
tags:
117
- "v*.*.*"
128
paths:
@@ -20,9 +16,48 @@ on:
2016
- 'x-ui.service.debian'
2117
- 'x-ui.service.arch'
2218
- 'x-ui.service.rhel'
19+
pull_request:
2320

2421
jobs:
22+
analyze:
23+
name: Analyze Go code
24+
permissions:
25+
contents: read
26+
runs-on: ubuntu-latest
27+
timeout-minutes: 20
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v6
31+
32+
- name: Set up Go
33+
uses: actions/setup-go@v6
34+
with:
35+
go-version-file: go.mod
36+
cache: true
37+
38+
- name: Check formatting
39+
run: |
40+
unformatted=$(gofmt -l .)
41+
if [ -n "$unformatted" ]; then
42+
echo "These files are not gofmt-formatted:"
43+
echo "$unformatted"
44+
exit 1
45+
fi
46+
47+
- name: Run go vet
48+
run: go vet ./...
49+
50+
- name: Run staticcheck
51+
uses: dominikh/staticcheck-action@v1
52+
with:
53+
version: "latest"
54+
install-go: false
55+
56+
- name: Run tests
57+
run: go test -race -shuffle=on ./...
58+
2559
build:
60+
needs: analyze
2661
permissions:
2762
contents: write
2863
strategy:
@@ -140,12 +175,10 @@ jobs:
140175

141176
- name: Upload files to GH release
142177
uses: svenstaro/upload-release-action@v2
143-
if: |
144-
(github.event_name == 'release' && github.event.action == 'published') ||
145-
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
178+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
146179
with:
147180
repo_token: ${{ secrets.GITHUB_TOKEN }}
148-
tag: ${{ github.ref }}
181+
tag: ${{ github.ref_name }}
149182
file: x-ui-linux-${{ matrix.platform }}.tar.gz
150183
asset_name: x-ui-linux-${{ matrix.platform }}.tar.gz
151184
overwrite: true
@@ -156,6 +189,7 @@ jobs:
156189
# =================================
157190
build-windows:
158191
name: Build for Windows
192+
needs: analyze
159193
permissions:
160194
contents: write
161195
strategy:
@@ -237,12 +271,10 @@ jobs:
237271

238272
- name: Upload files to GH release
239273
uses: svenstaro/upload-release-action@v2
240-
if: |
241-
(github.event_name == 'release' && github.event.action == 'published') ||
242-
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
274+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
243275
with:
244276
repo_token: ${{ secrets.GITHUB_TOKEN }}
245-
tag: ${{ github.ref }}
277+
tag: ${{ github.ref_name }}
246278
file: x-ui-windows-amd64.zip
247279
asset_name: x-ui-windows-amd64.zip
248280
overwrite: true

web/controller/index.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package controller
22

33
import (
4+
"fmt"
45
"net/http"
56
"text/template"
67
"time"
7-
"fmt"
88

99
"github.com/mhsanaei/3x-ui/v2/logger"
1010
"github.com/mhsanaei/3x-ui/v2/web/service"
@@ -79,12 +79,12 @@ func (a *IndexController) login(c *gin.Context) {
7979

8080
if user == nil {
8181
logger.Warningf("wrong username: \"%s\", password: \"%s\", IP: \"%s\"", safeUser, safePass, getRemoteIp(c))
82-
83-
notifyPass := safePass
84-
82+
83+
notifyPass := safePass
84+
8585
if checkErr != nil && checkErr.Error() == "invalid 2fa code" {
8686
translatedError := a.tgbot.I18nBot("tgbot.messages.2faFailed")
87-
notifyPass = fmt.Sprintf("*** (%s)", translatedError)
87+
notifyPass = fmt.Sprintf("*** (%s)", translatedError)
8888
}
8989

9090
a.tgbot.UserLoginNotify(safeUser, notifyPass, getRemoteIp(c), timeStr, 0)

web/service/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (s *UserService) CheckUser(username string, password string, twoFactorCode
9595
}
9696

9797
if gotp.NewDefaultTOTP(twoFactorToken).Now() != twoFactorCode {
98-
return nil, errors.New("invalid 2fa code")
98+
return nil, errors.New("invalid 2fa code")
9999
}
100100
}
101101

0 commit comments

Comments
 (0)