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

fix windows ci #934

Merged
merged 5 commits into from
Dec 31, 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
5 changes: 0 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ jobs:
with:
go-version: "1.23.1"

- name: patch net/http/fs.go
run: |
patch -p0 --forward `go env GOROOT`/src/net/http/fs.go < ./script/patch/fs.patch || true
patch -p0 --forward `go env GOMODCACHE`/github.com/gin-gonic/gin@v1.10.0/context.go < ./script/patch/gin-context.patch || true

- name: generate swagger docs
run: |
go install github.com/swaggo/swag/cmd/swag@latest
Expand Down
15 changes: 5 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,31 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu, windows, macos]

runs-on: ${{ matrix.os }}-latest
env:
GO111MODULE: on
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: "1.23.1"

- name: patch net/http/fs.go
run: |
patch -p0 --forward `go env GOROOT`/src/net/http/fs.go < ./script/patch/fs.patch || true
patch -p0 --forward `go env GOMODCACHE`/github.com/gin-gonic/gin@v1.10.0/context.go < ./script/patch/gin-context.patch || true

- name: generate swagger docs
run: |
go install github.com/swaggo/swag/cmd/swag@latest
touch ./cmd/dashboard/user-dist/a
touch ./cmd/dashboard/admin-dist/a
swag init --pd -d . -g ./cmd/dashboard/main.go -o ./cmd/dashboard/docs --parseGoList=false

- name: Unit test
run: |
go test -v ./...

- name: Build test
run: go build -v ./cmd/dashboard

- name: Run Gosec Security Scanner
if: runner.os == 'Linux'
uses: securego/gosec@master
Expand Down
27 changes: 24 additions & 3 deletions cmd/dashboard/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,31 @@ func getUid(c *gin.Context) uint64 {
return user.ID
}

type ginCustomWriter struct {
gin.ResponseWriter

customCode int
}

func newCustomWriter(c *gin.Context, code int) *ginCustomWriter {
return &ginCustomWriter{
ResponseWriter: c.Writer,
customCode: code,
}
}

func (w *ginCustomWriter) WriteHeader(code int) {
w.ResponseWriter.WriteHeader(w.customCode)
}

func fileWithCustomStatusCode(c *gin.Context, filepath string, customCode int) {
http.ServeFile(newCustomWriter(c, customCode), c.Request, path.Clean(filepath))

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.
}

func fallbackToFrontend(frontendDist fs.FS) func(*gin.Context) {
checkLocalFileOrFs := func(c *gin.Context, fs fs.FS, path string, customStatusCode int) bool {
if _, err := os.Stat(path); err == nil {
c.FileWithCustomStatusCode(path, customStatusCode)
fileWithCustomStatusCode(c, path, customStatusCode)
return true
}
f, err := fs.Open(path)
Expand All @@ -303,7 +324,7 @@ func fallbackToFrontend(frontendDist fs.FS) func(*gin.Context) {
if fileStat.IsDir() {
return false
}
http.ServeContentCustomStatusCode(c.Writer, c.Request, path, fileStat.ModTime(), f.(io.ReadSeeker), customStatusCode)
http.ServeContent(newCustomWriter(c, customStatusCode), c.Request, path, fileStat.ModTime(), f.(io.ReadSeeker))
return true
}
return func(c *gin.Context) {
Expand All @@ -323,7 +344,7 @@ func fallbackToFrontend(frontendDist fs.FS) func(*gin.Context) {
}
return
}
localFilePath := path.Join(singleton.Conf.UserTemplate, c.Request.URL.Path)
localFilePath := path.Join(singleton.Conf.UserTemplate, path.Clean(c.Request.URL.Path))
if checkLocalFileOrFs(c, frontendDist, localFilePath, http.StatusOK) {
return
}
Expand Down
102 changes: 0 additions & 102 deletions script/patch/fs.patch

This file was deleted.

11 changes: 0 additions & 11 deletions script/patch/gin-context.patch

This file was deleted.

Loading