diff --git a/.gitignore b/.gitignore index 6c4e5a1..972c77e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ tags -bin/* -!bin/.gitkeep -dist/ -Pominal +pominal cover.out diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9d6371a..9aa907b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,7 @@ --- +include: +- template: 'Workflows/MergeRequest-Pipelines.gitlab-ci.yml' + stages: - test - deploy @@ -16,7 +19,7 @@ test:unit: paths: - code-coverage.html extends: .install-make - image: golang:1.13.7-alpine + image: golang:1.14.4-alpine script: - make test_cover_report stage: test diff --git a/.golangci.yml b/.golangci.yml index 3897935..1520bfe 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -63,7 +63,7 @@ linters: issues: exclude-rules: - - path: version.go + - path: main.go linters: - gochecknoglobals - path: _test.go diff --git a/Makefile b/Makefile index 47eb7c4..bfa6691 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,46 @@ -NAME := pominal -BIN_DIR := ./bin -BIN_FILE := $(BIN_DIR)/$(NAME) +# Pominal +# Copyright (C) 2020 Daniel Anglin -.PHONY: all test_unit build clean +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. -all: test_unit build +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +include config.mk + +.PHONY: test_unit test_cover_report test_lint pominal clean test_unit: - @go test -v -coverprofile=cover.out . + go test -v -coverprofile=cover.out . test_cover_report: test_unit - @go tool cover -html=cover.out -o code-coverage.html + go tool cover -html=cover.out -o code-coverage.html test_lint: - @golangci-lint run --color always + golangci-lint run --color always -build: - @go build -a -o $(BIN_FILE) - @cp -a assets bin/assets +pominal: + go build -ldflags=$(LDFLAGS) -v -a -o pominal + +install: pominal + mkdir -p $(INSTALL_PREFIX)/bin + mkdir -p $(INSTALL_PREFIX)/share/pominal + cp -f pominal $(INSTALL_PREFIX)/bin + chmod 0755 $(INSTALL_PREFIX)/bin/pominal + cp -a assets/* $(INSTALL_PREFIX)/share/pominal + chmod -R a-rwx,u+rwX,g+rX,o+rX $(INSTALL_PREFIX)/share/pominal + +uninstall: + rm -f $(INSTALL_PREFIX)/bin/pominal + rm -fr $(INSTALL_PREFIX)/share/pominal clean: - @go clean - @rm -rf $(BIN_FILE) $(BIN_DIR)/assets + go clean diff --git a/README.md b/README.md index d9d8302..b8bef35 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,32 @@ # Pominal -Pominal is a Pomodoro application for the terminal. Pominal is written in Go. +## Summary + +Pominal is a Pomodoro application for the terminal written in Go. +Pominal is primarily written for GNU/Linux but might also run fine on Windows and OSX. + +## Installation + +Before installing Pominal make sure that you have the tools listed below installed on your system: + +- Make +- The latest version of [Go](https://golang.org) + +Run the below command to build and install Pominal. +By default Pominal is installed in /usr/local so you may have to run the command with sudo. + +```sh +$ make clean install +``` + +To change the installation path you can edit `INSTALL_PREFIX` in config.mk or set the `INSTALL_PREFIX` variable as you execute `make`: + +```sh +# example install Pominal in your home directory +$ INSTALL_PREFIX=${HOME}/.local make clean install +``` + +If you are installing Pominal on an OS other than GNU/Linux and/or an architecture other than AMD64 then update the `GOOS` and `GOARCH` variables in config.mk. ## Assets diff --git a/alert.go b/alert.go index 65dec84..8395eff 100644 --- a/alert.go +++ b/alert.go @@ -20,40 +20,20 @@ package main import ( "fmt" - "os" - "path/filepath" "github.com/0xAX/notificator" ) -const iconPath string = "assets/icon/tomato.png" +const iconPath string = "share/pominal/icons/tomato.png" // initNotifier initialises the new desktop notifier. func initNotifier() *notificator.Notificator { return notificator.New(notificator.Options{ - DefaultIcon: getNotificationIconPath(), + DefaultIcon: installPrefix + "/" + iconPath, AppName: "Pominal", }) } -// getNotificationIconPath returns the absolute path of the tomoato icon -// used for desktop notifications. -// If there is an error getting the path to the executing program -// then an empty string is returned. -func getNotificationIconPath() string { - var result string - - exe, err := os.Executable() - if err != nil { - fmt.Printf("ERROR: Unable to determine path to this executable. %s", err.Error()) - return result - } - - result = filepath.Dir(exe) + "/" + iconPath - - return result -} - // alert creates a new desktop notification. func desktopAlert(label, msg string, notifier *notificator.Notificator) { if len(msg) == 0 { diff --git a/assets/icon/tomato.png b/assets/icons/tomato.png similarity index 100% rename from assets/icon/tomato.png rename to assets/icons/tomato.png diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..89a968e --- /dev/null +++ b/config.mk @@ -0,0 +1,13 @@ +# pominal version +VERSION = 0.3.0 + +# Default installation path +INSTALL_PREFIX ?= /usr/local + +# Go environment variables +CGO_ENABLED = 0 +GOOS = linux +GOARCH = amd64 + +# Build flags +LDFLAGS = "-s -w -X main.version=$(VERSION) -X main.installPrefix=$(INSTALL_PREFIX)" diff --git a/main.go b/main.go index a09a092..3655d72 100644 --- a/main.go +++ b/main.go @@ -20,12 +20,18 @@ package main import ( "flag" + "fmt" "log" "os" "github.com/rivo/tview" ) +var ( + version string + installPrefix string +) + const ( workTimerLabel string = "Work" shortBreakTimerLabel string = "Short break" @@ -82,3 +88,7 @@ func main() { panic(err) } } + +func Version() { + fmt.Printf("Pominal version %s\n", version) +} diff --git a/version.go b/version.go deleted file mode 100644 index cdcdbd2..0000000 --- a/version.go +++ /dev/null @@ -1,32 +0,0 @@ -/* - Pominal - Copyright (C) 2020 Daniel Anglin - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -package main - -import "fmt" - -var ( - commit string - date string - goversion string - version string -) - -func Version() { - fmt.Printf("Pominal\n\nVersion: %s\nCommit: %s\nGo Version: %s\nDate: %s", version, commit, goversion, date) -}