Skip to content

Commit

Permalink
use the old release mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
tlanfer committed Jul 19, 2024
1 parent 6c73e0c commit 1be391b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 143 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/pre-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@ jobs:
${{ runner.os }}-go-
- name: Build
run: cd companion && go build -ldflags -H=windowsgui -o ../companion.exe ./cmd/companion
run: cd companion && go generate ./... && go build -ldflags -H=windowsgui -o ../companion.exe ./cmd/companion


- uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
prerelease: true
title: "Development Build"
files: |
companion.exe
19 changes: 10 additions & 9 deletions .github/workflows/tagged-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
- name: Build
run: cd companion && go generate ./... && go build -ldflags -H=windowsgui -o ../companion.exe ./cmd/companion


- uses: "marvinpinto/action-automatic-releases@latest"
with:
workdir: companion
distribution: goreleaser
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
companion.exe
2 changes: 0 additions & 2 deletions companion/cmd/companion/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"companion/internal/adapter/inbound/yamlconfig"
"companion/internal/adapter/outbound/exchangerate"
"companion/internal/adapter/outbound/scanner"
"companion/internal/adapter/outbound/update"
"companion/internal/eventprocssor"
"io"
"log"
Expand All @@ -29,7 +28,6 @@ var (
)

func main() {
update.Version = version

yamlconfig.Init()

Expand Down
29 changes: 4 additions & 25 deletions companion/internal/adapter/inbound/ui/updates/handler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package updates

import (
"companion/internal/adapter/outbound/update"
"encoding/json"
"log"
"net/http"
Expand All @@ -21,23 +20,15 @@ func (h handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
switch req.Method {
case http.MethodGet:
h.get(w, req)
case http.MethodPost:
h.post(w, req)
default:
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
}
}

func (h handler) get(w http.ResponseWriter, _ *http.Request) {
latest, b, err := update.IsLatest()

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

dto := dto{
Version: h.version,
Latest: latest,
IsLatest: b,
Version: h.version,
}

w.Header().Set("Content-Type", "application/json")
Expand All @@ -46,18 +37,6 @@ func (h handler) get(w http.ResponseWriter, _ *http.Request) {
}
}

func (h handler) post(w http.ResponseWriter, _ *http.Request) {
err := update.Run()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
w.WriteHeader(http.StatusOK)
}

}

type dto struct {
Version string `json:"version"`
Latest string `json:"latest"`
IsLatest bool `json:"isLatest"`
Version string `json:"version"`
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,7 @@
<script>
import {version, runUpdate} from '../lib/version.js';
let state = $version.isLatest ? "ok" : "old";
const initUpdate = async () => {
state = "updating";
const success = await runUpdate();
if( success ) {
state = "updated";
} else {
state = "error";
}
};
import {version} from '../lib/version.js';
</script>

<div>
You are running {$version.version}.
{#if state==="ok"}
This is the latest version.
{/if}
{#if state==="old"}
Version {$version.latest} is available.
<button on:click={initUpdate}>Update now?</button>
{/if}
{#if state==="updating"}
Updating, please wait...
{/if}
{#if state==="updated"}
Updated to v{$version.latest}. Please restart the companion
{/if}
{#if state==="error"}
An error occurred. Please try again later.
{/if}
</div>

<style>
button {
background: none;
border: none;
font-family: inherit;
padding: 0;
}
button:hover {
text-decoration: underline;
}
</style>
10 changes: 1 addition & 9 deletions companion/internal/adapter/inbound/ui/www/src/lib/version.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import {readable} from "svelte/store";

export const version = readable({version: "", latest:"", isLatest: true}, async set => {
export const version = readable({version: ""}, async set => {
const res = await fetch("/api/version")
const ver = await res.json()

set(ver)
});

export const runUpdate = async ()=> {
const res = await fetch("/api/version", {
method: "POST"
})
return res.status === 200
}
56 changes: 0 additions & 56 deletions companion/internal/adapter/outbound/update/update.go

This file was deleted.

0 comments on commit 1be391b

Please sign in to comment.