Skip to content

Commit

Permalink
feat: add a net based fallback for go install
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxilly committed May 9, 2024
1 parent 912800d commit d4c2eac
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build-ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ builds:
- amd64
- arm64
flags: -trimpath
tags:
- embed

archives:
- format: tar.gz
Expand Down
2 changes: 2 additions & 0 deletions internal/webui/embed.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build embed

package webui

import (
Expand Down
32 changes: 32 additions & 0 deletions internal/webui/net.go
Original file line number Diff line number Diff line change
@@ -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)
}
9 changes: 9 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d4c2eac

Please sign in to comment.