From 6f497d2ed6f84ec96b2813a0f16a48ea0627e3a9 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Wed, 9 Aug 2023 13:08:05 +0200 Subject: [PATCH 1/2] Rename docker release file --- .github/workflows/{release.yml => docker.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{release.yml => docker.yml} (100%) diff --git a/.github/workflows/release.yml b/.github/workflows/docker.yml similarity index 100% rename from .github/workflows/release.yml rename to .github/workflows/docker.yml From 177761327a79dfd5858f6df71683a96fd067bc9a Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Wed, 9 Aug 2023 13:31:42 +0200 Subject: [PATCH 2/2] Added goreleaser to generate binaries on tag --- .github/workflows/release.yml | 28 +++++++++++++++++++ .goreleaser.yml | 51 +++++++++++++++++++++++++++++++++++ main.go | 17 +++++------- 3 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..73687a8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,28 @@ +name: goreleaser + +on: + push: + tags: + - "*" + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - run: git fetch --force --tags + - uses: actions/setup-go@v4 + with: + go-version: stable + - uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..bfcca79 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,51 @@ +--- +before: + hooks: + - go mod tidy -compat=1.20 + - go mod vendor + +release: + prerelease: auto + +builds: + - id: wolweb + mod_timestamp: "{{ .CommitTimestamp }}" + env: + - CGO_ENABLED=0 + targets: + - darwin_amd64 + - darwin_arm64 + - freebsd_amd64 + - linux_386 + - linux_amd64 + - linux_arm64 + - linux_arm_5 + - linux_arm_6 + - linux_arm_7 + flags: + - -mod=readonly + ldflags: + - -s -w -X main.Version={{.Version}} + +archives: + - id: golang-cross + name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}' + format: binary + +source: + enabled: true + name_template: "{{ .ProjectName }}_{{ .Version }}" + format: tar.gz + files: + - "vendor/" + +checksum: + name_template: "checksums.txt" +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/main.go b/main.go index 8409845..1fe36e0 100644 --- a/main.go +++ b/main.go @@ -15,21 +15,23 @@ import ( "github.com/ilyakaznacheev/cleanenv" ) +var Version = "dev" + // Global variables -var appConfig AppConfig -var appData AppData +var ( + appConfig AppConfig + appData AppData +) func main() { - + log.Printf("Starting WakeOnLan Webserver version %s", Version) setWorkingDir() loadConfig() loadData() setupWebServer() - } func setWorkingDir() { - thisApp, err := os.Executable() if err != nil { log.Fatalf("Error determining the directory. \"%s\"", err) @@ -37,21 +39,17 @@ func setWorkingDir() { appPath := filepath.Dir(thisApp) os.Chdir(appPath) log.Printf("Set working directory: %s", appPath) - } func loadConfig() { - err := cleanenv.ReadConfig("config.json", &appConfig) if err != nil { log.Fatalf("Error loading config.json file. \"%s\"", err) } log.Printf("Application configuratrion loaded from config.json") - } func setupWebServer() { - // Init HTTP Router - mux router := mux.NewRouter() @@ -95,7 +93,6 @@ func setupWebServer() { } log.Fatal(srv.ListenAndServe()) - } func CacheControlWrapper(h http.Handler) http.Handler {