add build version, Makefile & install instructions
This commit is contained in:
parent
422ee93b44
commit
d9cf417e72
|
@ -0,0 +1,68 @@
|
|||
# Install YetAnotherToDoList
|
||||
|
||||
## Install via `go install`
|
||||
|
||||
> ⚠️ no commit & version information provided
|
||||
|
||||
```bash
|
||||
go install somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList@latest
|
||||
```
|
||||
|
||||
...or specify the installation location by adding `GOBIN=<installation directory>`
|
||||
|
||||
## Install from git repository
|
||||
|
||||
Requirements:
|
||||
|
||||
- go 1.20
|
||||
- git
|
||||
- GNU make
|
||||
|
||||
```bash
|
||||
git clone https://somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList.git
|
||||
cd YetAnotherToDoList
|
||||
go mod tidy # optional
|
||||
make build
|
||||
```
|
||||
|
||||
To customize your build, you can run `make` with these environment Variables (on the same line):
|
||||
|
||||
```
|
||||
INSTALL_DIR=<installation directory>
|
||||
BUILD_FLAGS=<go build flags>
|
||||
RUN_FLAGS=<cli arguments for YetAnotherToDoList>
|
||||
```
|
||||
|
||||
## Install from pre-build binary
|
||||
|
||||
There are currently no pre-build binaries available
|
||||
|
||||
## Add shell completion
|
||||
|
||||
YetAnotherToDoList must be in your `PATH` for this to work.
|
||||
|
||||
### Bash
|
||||
|
||||
```bash
|
||||
source <(YetAnotherToDoList completion bash)
|
||||
```
|
||||
|
||||
For other shells or more info, see `YetAnotherToDoList help completion <bash|zsh|fish|powershell>`
|
||||
|
||||
## Uninstall
|
||||
|
||||
Run `make uninstall` or
|
||||
|
||||
```bash
|
||||
rm $HOME/.local/bin/YetAnotherToDoList # replace with your installation path
|
||||
```
|
||||
|
||||
> Don't forget to delete the `.log`, `.yaml` and `.sqlite3` files if you don't need them any more.
|
||||
|
||||
### Remove shell completion
|
||||
|
||||
#### Bash
|
||||
|
||||
```bash
|
||||
complete -r YetAnotherToDoList
|
||||
```
|
|
@ -0,0 +1,71 @@
|
|||
# YetAnotherToDoList
|
||||
# Copyright © 2023 gilex-dev gilex-dev@proton.me
|
||||
|
||||
# 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, version 3.
|
||||
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
project:=YetAnotherToDoList
|
||||
goPackage:=somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList/globals
|
||||
|
||||
INSTALL_DIR?=$$HOME/.local/bin
|
||||
BUILD_FLAGS?=
|
||||
RUN_FLAGS?=
|
||||
|
||||
commitHash=$(shell git rev-parse --short HEAD)
|
||||
ifneq ($(shell git status --porcelain),)
|
||||
# working directory not clean
|
||||
commitHash:=$(commitHash)*
|
||||
endif
|
||||
|
||||
latestTag:=$(shell git describe --abbrev=0 --tags 2> /dev/null)# suppress possible error
|
||||
|
||||
ifeq ($(shell git tag --points-at HEAD),)
|
||||
# current commit has no tag
|
||||
ifeq ($(latestTag),)
|
||||
# no previous tag exists
|
||||
latestTag=unknown
|
||||
else
|
||||
# found a tag before HEAD
|
||||
latestTag:=$(latestTag)*
|
||||
endif
|
||||
endif
|
||||
|
||||
.PHONY: all
|
||||
all: install
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
go build $(BUILD_FLAGS) -ldflags="-X '$(goPackage).Version=$(latestTag)' -X '$(goPackage).CommitHash=$(commitHash)'" -o $(project) .
|
||||
|
||||
.PHONY: run
|
||||
run:
|
||||
go run $(BUILD_FLAGS) -ldflags="-X '$(goPackage).Version=$(latestTag)' -X '$(goPackage).CommitHash=$(commitHash)'" . $(RUN_FLAGS)
|
||||
|
||||
$(project): build
|
||||
|
||||
.PHONY: install
|
||||
install: $(project)
|
||||
install $(project) $(INSTALL_DIR)
|
||||
@echo -e "\nIf you want to add shell completion, see INSTALL.md"
|
||||
|
||||
.PHONY: uninstall
|
||||
uninstall:
|
||||
@-rm $(INSTALL_DIR)/$(project)
|
||||
|
||||
.PHONY: info
|
||||
info:
|
||||
$(info project=$(project))
|
||||
$(info goPackage=$(goPackage))
|
||||
$(info latestTag=$(latestTag))
|
||||
$(info commitHash=$(commitHash))
|
||||
$(info BUILD_FLAGS=$(BUILD_FLAGS))
|
||||
$(info INSTALL_DIR=$(INSTALL_DIR))
|
||||
@echo -e "\nSee INSTALL.md for usage"
|
17
cmd/root.go
17
cmd/root.go
|
@ -26,6 +26,7 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList/globals"
|
||||
)
|
||||
|
||||
var cfgFile string
|
||||
|
@ -33,8 +34,9 @@ var logger *log.Logger
|
|||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "YetAnotherToDoList",
|
||||
Short: "A simple To Do List Web Application with Go backend, Vue.js frontend and a GraphQL API",
|
||||
Use: "YetAnotherToDoList",
|
||||
Version: fmt.Sprintf("%s %s", globals.Version, globals.CommitHash),
|
||||
Short: "Simple To Do List Web Application with Vue.js frontend and GraphQL API",
|
||||
Long: `YetAnotherToDoList 2023 by gilex-dev
|
||||
A simple To Do List Web Application with Go backend, Vue.js frontend and a GraphQL API
|
||||
`,
|
||||
|
@ -53,6 +55,17 @@ func Execute() {
|
|||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.CompletionOptions.HiddenDefaultCmd = true
|
||||
// check if first argument needs init (inspired by https://github.com/spf13/cobra/issues/823#issuecomment-617863653)
|
||||
if len(os.Args) > 1 {
|
||||
noSetupRequired := []string{"__complete", "__completeNoDesc", "completion", "help", licenseCmd.Name()}
|
||||
for _, subcommand := range noSetupRequired {
|
||||
if subcommand != os.Args[1] {
|
||||
continue
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
cobra.OnInitialize(initConfig, initLog)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
var serverCmd = &cobra.Command{
|
||||
Use: "server",
|
||||
Short: "Start the http server",
|
||||
Long: ``,
|
||||
Long: `Starts the http server for the graphql api`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if err := viper.BindPFlag("debug", cmd.Flags().Lookup("debug")); err != nil {
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
YetAnotherToDoList
|
||||
Copyright © 2023 gilex-dev gilex-dev@proton.me
|
||||
|
||||
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, version 3.
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package globals
|
||||
|
||||
var Version, CommitHash string = "unknown", "unknown"
|
|
@ -17,12 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/99designs/gqlgen/graphql/handler"
|
||||
"github.com/99designs/gqlgen/graphql/playground"
|
||||
"somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList/globals"
|
||||
"somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList/graph"
|
||||
)
|
||||
|
||||
|
@ -30,6 +32,9 @@ func StartServer(logger *log.Logger, port int) {
|
|||
srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}}))
|
||||
|
||||
http.Handle("/", playground.Handler("GraphQL playground", "/api"))
|
||||
http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "%s %s", globals.Version, globals.CommitHash)
|
||||
})
|
||||
|
||||
http.Handle("/api", srv)
|
||||
logger.Printf("connect to http://localhost:%v/ for GraphQL playground", port)
|
||||
|
|
Loading…
Reference in New Issue