Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Jun 8, 2022
2 parents 252b0ba + 22a051c commit 9982cdd
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 5 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/release.yml
@@ -0,0 +1,57 @@
name: goreleaser

on:
push:
# run only against tags
tags:
- '*'

permissions:
contents: write
# packages: write
# issues: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Include web UI
uses: robinraju/release-downloader@v1.3
with:
repository: filecoin-project/saturn-l2-webui
# Update tag to deploy new web UI.
tag: v0.0.6
fileName: saturn-l2-webui.tar.gz
out-file-path: resources/webui
-
name: Unpack web UI archive
run: |
cd resources/webui
tar zxvf saturn-l2-webui.tar.gz
rm saturn-l2-webui.tar.gz
-
name: Fetch all tags
run: git fetch --force --tags
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -13,3 +13,6 @@

# Dependency directories (remove the comment below to include it)
# vendor/

dist/
resources/webui
44 changes: 44 additions & 0 deletions .goreleaser.yaml
@@ -0,0 +1,44 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
main: ./main

archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
groups:
- title: Features
regexp: "^.*feat[(\\w)]*:+.*$"
order: 0
- title: 'Bug fixes'
regexp: "^.*fix[(\\w)]*:+.*$"
order: 1
- title: Others
order: 999
filters:
exclude:
- '^docs:'
- '^test:'

32 changes: 27 additions & 5 deletions main/main.go
Expand Up @@ -6,8 +6,11 @@ import (
"net/http"
"os"
"strconv"
"strings"

"github.com/gorilla/mux"

"github.com/filecoin-project/saturn-l2/resources"
)

func main() {
Expand All @@ -24,7 +27,7 @@ func main() {
}

m := mux.NewRouter()
m.Handle("/webui", http.HandlerFunc(webuiIndex))
m.PathPrefix("/webui").Handler(http.HandlerFunc(webuiHandler))
srv := &http.Server{
Handler: m,
}
Expand All @@ -48,8 +51,27 @@ func main() {
}
}

func webuiIndex(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(200)
w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprint(w, "<html><head><title>Saturn L2 Node</title></head><body>Status: running</body></html>")
func webuiHandler(w http.ResponseWriter, r *http.Request) {
rootDir := "webui"
path := strings.TrimPrefix(r.URL.Path, "/")

_, err := resources.WebUI.Open(path)
if path == rootDir || os.IsNotExist(err) {
// file does not exist, serve index.html
index, err := resources.WebUI.ReadFile(rootDir + "/index.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)
w.Write(index)
return
} else if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

// otherwise, use http.FileServer to serve the static dir
http.FileServer(http.FS(resources.WebUI)).ServeHTTP(w, r)
}
9 changes: 9 additions & 0 deletions resources/resources.go
@@ -0,0 +1,9 @@
package resources

import "embed"

// webui folder is empty during local development, embed resources.go
// so go doesn't complain about "no embeddable files"
//
//go:embed webui resources.go
var WebUI embed.FS

0 comments on commit 9982cdd

Please sign in to comment.