Skip to content

Commit

Permalink
Throw together a portable version
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Crane <marcus@utf9k.net>
  • Loading branch information
marcus-crane committed Aug 5, 2023
1 parent acd1b7f commit f76e339
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 16 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/release-windows-portable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Release October

on:
release:
types: [published]

jobs:
release:
name: Release October (Windows Portable)
runs-on: windows-latest
strategy:
matrix:
platform:
- windows/amd64
steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Normalise platform tag
id: normalise_platform
shell: bash
run: |
tag=windows-portable_amd64
echo "::set-output name=tag::$tag"
- name: Normalise version tag
id: normalise_version
shell: bash
run: |
version=$(echo ${{ github.event.release.tag_name }} | sed -e 's/v//g')
echo "::set-output name=version::$version"
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19

- name: Install makensis
uses: crazy-max/ghaction-chocolatey@v2
with:
args: install nsis

- name: Install wails
shell: bash
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest

- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: '16'

- name: Build frontend assets
shell: bash
run: |
npm install -g npm
node version.js ${{ github.event.release.tag_name }}
cd frontend && npm install
- name: Build Windows NSIS installer
shell: bash
run: CGO_ENABLED=1 wails build -platform ${{ matrix.platform }} -ldflags "-X main.version=${{ github.event.release.tag_name }} -X main.portablebuild=true"

- name: Codesign Windows Portable
run: |
echo "Creating certificate file"
New-Item -ItemType directory -Path certificate
Set-Content -Path certificate\certificate.txt -Value '${{ secrets.WIN_SIGNING_CERT }}'
certutil -decode certificate\certificate.txt certificate\certificate.pfx
echo "Signing October installer"
& 'C:/Program Files (x86)/Windows Kits/10/bin/10.0.17763.0/x86/signtool.exe' sign /fd sha256 /tr http://ts.ssl.com /f certificate\certificate.pfx /p '${{ secrets.WIN_SIGNING_CERT_PASSWORD }}' october.exe
working-directory: ./build/bin

- name: Compress binary
run: Compress-Archive october.exe october-${{ steps.normalise_platform.outputs.tag }}.zip
working-directory: ./build/bin

- name: Get latest release from API
id: get_upload_url
shell: bash
run: |
curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/marcus-crane/october/releases" > /tmp/releases.json
url=$(jq -r '.[0].upload_url' /tmp/releases.json)
echo "::set-output name=url::$url"
- name: Upload artifact
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ARTIFACT_NAME: october_${{ steps.normalise_version.outputs.version }}_${{ steps.normalise_platform.outputs.tag }}
with:
upload_url: ${{ steps.get_upload_url.outputs.url }}
asset_path: ./build/bin/october-${{ steps.normalise_platform.outputs.tag }}.zip
asset_name: ${{ env.ARTIFACT_NAME }}.zip
asset_content_type: application/zip
11 changes: 7 additions & 4 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import (

// App struct
type App struct {
ctx context.Context
ctx context.Context
portable bool
}

// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
func NewApp(portable bool) *App {
return &App{
portable: portable,
}
}

// startup is called when the app starts. The context is saved
Expand All @@ -25,7 +28,7 @@ func (a *App) startup(ctx context.Context) {

func (a *App) domReady(ctx context.Context) {
a.ctx = ctx
backend.StartLogger()
backend.StartLogger(a.portable)
logrus.WithContext(ctx).Info("Logger should be initialised now")
logrus.WithContext(ctx).Info("Backend is about to start up")
}
Expand Down
30 changes: 30 additions & 0 deletions backend/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package backend

import (
"os"
"path"

"github.com/adrg/xdg"
)

func LocateConfigFile(configFilename string, portable bool) (string, error) {
if portable {
cwd, err := os.Getwd()
if err != nil {
return "", err
}
return path.Join(cwd, configFilename), nil
}
return xdg.ConfigFile(configFilename)
}

func LocateDataFile(configFilename string, portable bool) (string, error) {
if portable {
cwd, err := os.Getwd()
if err != nil {
return "", err
}
return path.Join(cwd, configFilename), nil
}
return xdg.DataFile(configFilename)
}
9 changes: 5 additions & 4 deletions backend/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"runtime"
"strings"

"github.com/adrg/xdg"
"github.com/sirupsen/logrus"

"github.com/pgaskin/koboutils/v2/kobo"
Expand All @@ -30,10 +29,11 @@ type Backend struct {
Content *Content
Bookmark *Bookmark
version string
portable bool
}

func StartBackend(ctx *context.Context, version string) *Backend {
settings, err := LoadSettings()
func StartBackend(ctx *context.Context, version string, portable bool) *Backend {
settings, err := LoadSettings(portable)
if err != nil {
logrus.WithContext(*ctx).WithError(err).Error("Failed to load settings")
}
Expand All @@ -47,6 +47,7 @@ func StartBackend(ctx *context.Context, version string) *Backend {
Content: &Content{},
Bookmark: &Bookmark{},
version: version,
portable: portable,
}
}

Expand Down Expand Up @@ -81,7 +82,7 @@ func (b *Backend) NavigateExplorerToLogLocation() {
if runtime.GOOS == "linux" {
explorerCommand = "xdg-open"
}
logLocation, err := xdg.DataFile("october/logs")
logLocation, err := LocateDataFile("october/logs", b.portable)
if err != nil {
logrus.WithError(err).Error("Failed to determine XDG data location for opening log location in explorer")
}
Expand Down
5 changes: 2 additions & 3 deletions backend/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import (
"os"
"time"

"github.com/adrg/xdg"
"github.com/sirupsen/logrus"
)

var logFileHandle *os.File

var logFile = fmt.Sprintf("october/logs/%s.json", time.Now().Format("20060102150405"))

func StartLogger() {
logPath, err := xdg.DataFile(logFile)
func StartLogger(portable bool) {
logPath, err := LocateDataFile(logFile, portable)
if err != nil {
panic("Failed to create location to store logfiles")
}
Expand Down
5 changes: 2 additions & 3 deletions backend/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"path/filepath"

"github.com/adrg/xdg"
"github.com/pkg/errors"
)

Expand All @@ -17,8 +16,8 @@ type Settings struct {
UploadStorePromptShown bool `json:"upload_store_prompt_shown"`
}

func LoadSettings() (*Settings, error) {
settingsPath, err := xdg.ConfigFile(configFilename)
func LoadSettings(portable bool) (*Settings, error) {
settingsPath, err := LocateConfigFile(configFilename, portable)
if err != nil {
return nil, errors.Wrap(err, "Failed to create settings directory. Do you have proper permissions?")
}
Expand Down
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"embed"
"fmt"
"strconv"

"github.com/marcus-crane/october/backend"
"github.com/wailsapp/wails/v2"
Expand All @@ -22,11 +23,18 @@ var icon []byte

var version = "DEV"

// Builds with this set to true cause files to be created
// in the same directory as the running executable
var portablebuild = "false"

func main() {
isPortable := false
isPortable, _ = strconv.ParseBool(portablebuild)

// Create an instance of the app structure
app := NewApp()
app := NewApp(isPortable)

backend := backend.StartBackend(&app.ctx, version)
backend := backend.StartBackend(&app.ctx, version, isPortable)

// Create application with options
err := wails.Run(&options.App{
Expand Down

0 comments on commit f76e339

Please sign in to comment.