Skip to content

Commit

Permalink
Move CLI tool inside October itself
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Crane <[email protected]>
  • Loading branch information
marcus-crane committed Jan 17, 2024
1 parent 51b7e10 commit a571a44
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 76 deletions.
100 changes: 25 additions & 75 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,6 @@ jobs:
version="1.0.0"
fi
echo "version=$version" >> $GITHUB_OUTPUT
- name: Determine whether to perform codesigning
id: signing
shell: bash
run: |
echo "${{ github.event.pull_request.title }}"
enabled="false"
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
enabled="true"
fi
if [[ "${{ github.event.pull_request.title }}" == \[SIGN\]* ]]; then
enabled="true"
fi
echo "enabled=$enabled" >> $GITHUB_OUTPUT
# Set up development dependencies

Expand Down Expand Up @@ -101,7 +87,7 @@ jobs:

- name: Import code signing certificate from Github Secrets
uses: Apple-Actions/import-codesign-certs@v1
if: runner.os == 'macOS' && steps.signing.outputs.enabled == 'true'
if: runner.os == 'macOS'
with:
p12-file-base64: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_BASE64 }}
p12-password: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_PASSWORD }}
Expand All @@ -113,15 +99,7 @@ jobs:
uses: crazy-max/ghaction-chocolatey@v3
with:
args: install nsis

- name: Set up Windows certificates
if: runner.os == 'Windows' && matrix.build.tag == 'windows_amd64' && steps.signing.outputs.enabled == 'true'
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

# Build -- frontend

- name: Build frontend assets
Expand All @@ -130,44 +108,10 @@ jobs:
npm install -g npm
node version.js "v${{ steps.normalise_version.outputs.version }}"
cd frontend && npm install
# Build -- cli variants

## We skip Windows Portable for now because files have no consistent home and that's more weirdness than I want to deal with at the moment
## We skip Darwin Universal because there is no build target for Go (that I am aware of!)
- name: Build october-cli
if: ${{ matrix.build.tag != 'windows-portable_amd64' && matrix.build.tag != 'darwin_universal' }}
shell: bash
run: GOOS=$(echo ${{ matrix.build.platform }} | cut -d '/' -f 1) GOARCH=$(echo ${{ matrix.build.platform }} | cut -d '/' -f 2) go build -ldflags="-X main.version=v${{ steps.normalise_version.outputs.version }}"
working-directory: ./cmd/october-cli

# Codesign (CLI)
- name: Codesign Windows CLI
if: runner.os == 'Windows' && matrix.build.tag == 'windows_amd64' && steps.signing.outputs.enabled == 'true'
run: |
& '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 }}' .\cmd\october-cli\october-cli.exe
- name: Sign october-cli
if: ${{ runner.os == 'macOS' && matrix.build.tag != 'darwin_universal' && steps.signing.outputs.enabled == 'true' }}
shell: bash
run: |
codesign -s "Developer ID Application: Marcus Crane" -f -v --timestamp --options runtime ./october-cli
working-directory: ./cmd/october-cli

# TODO: Move Windows CLI inside folder for nsis bundling
- name: Move october-cli.exe inside Windows asset folder
if: runner.os == 'Windows' && matrix.build.tag == 'windows_amd64'
shell: bash
run: mv cmd/october-cli/october-cli.exe build/windows/

- name: Use NSI installer config that packages Windows CLI
if: runner.os == 'Windows' && matrix.build.tag == 'windows_amd64'
shell: bash
run: mv build/windows/installer/projectcli.nsi build/windows/installer/project.nsi

# Build -- app variants

## Linux + macOS
## Linux
- name: Build wails app for Linux / macOS
if: runner.os == 'Linux' || runner.os == 'macOS'
shell: bash
Expand All @@ -184,15 +128,11 @@ jobs:
shell: bash
run: wails build -platform ${{ matrix.build.platform }} -nsis -ldflags "-X main.version=v${{ steps.normalise_version.outputs.version }} -X main.portablebuild=true"

# Codesigning apps (only performed when releases are cut)

- name: Move october-cli inside October.app
if: ${{ runner.os == 'macOS' && matrix.build.tag != 'darwin_universal' }}
shell: bash
run: mv cmd/october-cli/october-cli build/bin/October.app/Contents/MacOS
# Codesigning (only performed when releases are cut)

## macOS
- name: Notarise macOS app + create dmg
if: runner.os == 'macOS' && steps.signing.outputs.enabled == 'true'
if: runner.os == 'macOS' && startsWith(github.ref, 'refs/tags/')
shell: bash
run: gon -log-level=info gon.config.json
env:
Expand All @@ -201,16 +141,27 @@ jobs:
AC_PROVIDER: "6RNEAKRYDT"

## Windows

- name: Codesign Windows NSIS Installer
if: runner.os == 'Windows' && matrix.build.tag == 'windows_amd64' && steps.signing.outputs.enabled == 'true'
if: runner.os == 'Windows' && matrix.build.tag == 'windows_amd64' && startsWith(github.ref, 'refs/tags/')
run: |
& '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 }}' .\build\bin\October-${{ matrix.build.arch }}-installer.exe
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-${{ matrix.build.arch }}-installer.exe
working-directory: ./build/bin

- name: Codesign Windows Portable
if: runner.os == 'Windows' && matrix.build.portable == 'windows-portable_amd64' && steps.signing.outputs.enabled == 'true'
if: runner.os == 'Windows' && matrix.build.portable == 'windows-portable_amd64' && startsWith(github.ref, 'refs/tags/')
run: |
& '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 }}' .\build\bin\october.exe
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

# Packaging

Expand All @@ -220,7 +171,6 @@ jobs:
shell: bash
run: |
mv build/bin/october build/linux/october_0.0.0_ARCH/usr/local/bin/
mv cmd/october-cli/october-cli build/linux/october_0.0.0_ARCH/usr/local/bin/
cd build/linux
sed -i 's/0.0.0/${{ steps.normalise_version.outputs.version }}/g' "october_0.0.0_ARCH/DEBIAN/control"
sed -i 's/ARCH/${{ matrix.build.arch }}/g' "october_0.0.0_ARCH/DEBIAN/control"
Expand Down Expand Up @@ -268,7 +218,7 @@ jobs:
with:
name: october_pr${{ github.event.pull_request.number }}_${{ github.event.pull_request.head.sha }}_${{ matrix.build.tag }}.zip
path: |
./build/bin/october-${{ matrix.build.tag }}.zip
./build/bin
- name: Get latest release from API
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -289,4 +239,4 @@ jobs:
upload_url: ${{ steps.get_upload_url.outputs.url }}
asset_path: ./build/bin/october-${{ matrix.build.tag }}.zip
asset_name: ${{ env.ARTIFACT_NAME }}.zip
asset_content_type: application/zip
asset_content_type: application/zip
78 changes: 78 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package cli

import (
"context"
"fmt"
"log"
"os"

"github.com/marcus-crane/october/backend"
"github.com/mattn/go-isatty"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)

func IsInvokedFromTerminal() bool {
if isatty.IsTerminal(os.Stdout.Fd()) {
return true
}
if isatty.IsCygwinTerminal(os.Stdout.Fd()) {
return true
}
return false
}

func Invoke(isPortable bool, version string) {
app := &cli.App{
Name: "october",
HelpName: "october",
Version: version,
Authors: []*cli.Author{
{
Name: "Marcus Crane",
Email: "[email protected]",
},
},
Usage: "sync your kobo highlights to readwise from your terminal",
Commands: []*cli.Command{
{
Name: "launch",
Usage: "skip cli tool and launch desktop ui",
},
{
Name: "sync",
Aliases: []string{"s"},
Usage: "sync kobo highlights to readwise",
Action: func(c *cli.Context) error {
ctx := context.Background()
b := backend.StartBackend(&ctx, version, isPortable)
if b.Settings.ReadwiseToken == "" {
return fmt.Errorf("no readwise token was configured. please set this up using the gui as the cli does not support this yet")
}
kobos := b.DetectKobos()
if len(kobos) == 0 {
return fmt.Errorf("no kobo was found. have you plugged one in and accepted the connection request?")
}
if len(kobos) > 1 {
return fmt.Errorf("cli only supports one connected kobo at a time")
}
err := b.SelectKobo(kobos[0].MntPath)
if err != nil {
return fmt.Errorf("an error occurred trying to connect to the kobo at %s", kobos[0].MntPath)
}
num, err := b.ForwardToReadwise()
if err != nil {
return err
}
logrus.Infof("Successfully synced %d highlights to Readwise", num)
return nil
},
},
},
}

err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ toolchain go1.21.3
require (
github.com/adrg/xdg v0.4.0
github.com/glebarez/sqlite v1.10.0
github.com/mattn/go-isatty v0.0.19
github.com/pgaskin/koboutils/v2 v2.1.2-0.20220306004009-a07e72ebae42
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0
Expand Down Expand Up @@ -35,7 +36,6 @@ require (
github.com/leaanthony/slicer v1.6.0 // indirect
github.com/leaanthony/u v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package main
import (
"embed"
"fmt"
"os"
"strconv"

"github.com/marcus-crane/october/backend"
"github.com/marcus-crane/october/cli"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/logger"
"github.com/wailsapp/wails/v2/pkg/options"
Expand All @@ -31,6 +33,13 @@ func main() {
isPortable := false
isPortable, _ = strconv.ParseBool(portablebuild)

skipCli := len(os.Args) == 2 && os.Args[1] == "launch"

if cli.IsInvokedFromTerminal() && !skipCli {
cli.Invoke(isPortable, version)
return
}

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

Expand Down

0 comments on commit a571a44

Please sign in to comment.