From d4c2eacdba4ab3228c07cc557703728b856891fc Mon Sep 17 00:00:00 2001 From: Zxilly Date: Fri, 10 May 2024 02:31:10 +0800 Subject: [PATCH] feat: add a net based fallback for go install --- .github/workflows/build-ui.yml | 12 ++++++++++++ .goreleaser.yaml | 2 ++ internal/webui/embed.go | 2 ++ internal/webui/net.go | 32 ++++++++++++++++++++++++++++++++ version.go | 9 +++++++++ 5 files changed, 57 insertions(+) create mode 100644 internal/webui/net.go diff --git a/.github/workflows/build-ui.yml b/.github/workflows/build-ui.yml index b401427c13..a0f20d7014 100644 --- a/.github/workflows/build-ui.yml +++ b/.github/workflows/build-ui.yml @@ -50,6 +50,18 @@ jobs: env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + - name: Release + if: ${{ !inputs.external_call }} + uses: ncipollo/release-action@v1 + with: + artifactErrorsFailBuild: true + allowUpdates: true + artifactContentType: 'text/html' + artifacts: 'ui/dist/index.html' + tag: ui-v1 + commit: master + prerelease: true + - name: Upload artifact if: ${{ inputs.external_call }} uses: actions/upload-artifact@v4 diff --git a/.goreleaser.yaml b/.goreleaser.yaml index e6151736c0..2654cb6fb7 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -23,6 +23,8 @@ builds: - amd64 - arm64 flags: -trimpath + tags: + - embed archives: - format: tar.gz diff --git a/internal/webui/embed.go b/internal/webui/embed.go index 803deccdfa..dfd7f2db72 100644 --- a/internal/webui/embed.go +++ b/internal/webui/embed.go @@ -1,3 +1,5 @@ +//go:build embed + package webui import ( diff --git a/internal/webui/net.go b/internal/webui/net.go new file mode 100644 index 0000000000..e9376771e5 --- /dev/null +++ b/internal/webui/net.go @@ -0,0 +1,32 @@ +//go:build !embed + +package webui + +import ( + "fmt" + gsv "github.com/Zxilly/go-size-analyzer" + "github.com/Zxilly/go-size-analyzer/internal/utils" + "io" + "log/slog" + "net/http" +) + +var BaseUrl = fmt.Sprintf("https://github.com/Zxilly/go-size-analyzer/releases/download/ui-v%d/index.html", gsv.GetStaticVersion()) + +func GetTemplate() string { + slog.Info("Downloading template") + resp, err := http.Get(BaseUrl) + if err != nil { + utils.FatalError(err) + } + defer func(Body io.ReadCloser) { + _ = Body.Close() + }(resp.Body) + + body, err := io.ReadAll(resp.Body) + if err != nil { + utils.FatalError(err) + } + + return string(body) +} diff --git a/version.go b/version.go index 34300ae8b7..c60de9181c 100644 --- a/version.go +++ b/version.go @@ -14,6 +14,15 @@ const ( unknownProperty = "N/A" ) +const ( + // when update this, also update the version string in workflow + staticVersion = 1 +) + +func GetStaticVersion() int { + return staticVersion +} + var ( name = unknownProperty version = unknownVersion