From 5cd91b48deef13f2af0e9e32598d2046d0421905 Mon Sep 17 00:00:00 2001 From: novikov Date: Wed, 11 Sep 2024 21:30:42 +0700 Subject: [PATCH] prepare for github --- .github/workflows/goreleaser.yml | 38 ++++++++++++++++++ .gitignore | 26 +++++++++++- .goreleaser.yaml | 69 ++++++++++++++++++++++++++++++++ Dockerfile | 6 +++ Makefile | 8 +++- cmd/root.go | 16 +++++++- config_example.yaml | 34 ++++++++++++++++ go.mod | 4 +- main.go | 5 ++- pkg/models/human_input_test.go | 2 +- readme.md | 3 ++ 11 files changed, 203 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/goreleaser.yml create mode 100644 .goreleaser.yaml create mode 100644 Dockerfile create mode 100644 config_example.yaml create mode 100644 readme.md diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 0000000..79e3fed --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,38 @@ +name: goreleaser + +on: + push: + tags: + - '*' + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + env: + DOCKER_CLI_EXPERIMENTAL: "enabled" + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Docker Login + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.23.0 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index ce9b991..fdeb986 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,25 @@ -todolist +### Go template +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..b93c8e4 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,69 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +# The lines below are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 2 + +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + # you may remove this if you don't need go generate + - go generate ./... + - go test ./... + +builds: + - env: + - CGO_ENABLED=0 + goarch: + - amd64 + - arm64 + goos: + - linux + - windows + - darwin + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +dockers: + - image_templates: + - "paragor/todolist:{{ .Tag }}-amd64" + goarch: amd64 + use: buildx + build_flag_templates: + - "--builder=default" + - image_templates: + - "paragor/todolist:{{ .Tag }}-arm64" + goarch: arm64 + use: buildx + build_flag_templates: + - "--builder=default" +docker_manifests: + - name_template: "paragor/todolist:{{ .Tag }}" + image_templates: + - "paragor/todolist:{{ .Tag }}-amd64" + - "paragor/todolist:{{ .Tag }}-arm64" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a05f765 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM alpine:3.20.2 + +WORKDIR /app + +COPY todolist /usr/bin/ +ENTRYPOINT ["/usr/bin/todolist"] diff --git a/Makefile b/Makefile index 9217efc..ced79cc 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ -build: - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o todolist main.go +build_local: + goreleaser release --snapshot --clean install: CGO_ENABLED=0 go build -o /usr/local/bin/todolist main.go /usr/local/bin/todolist config-persist + +update_default_config: + rm config_example.yaml || true + TODOLIST_HOME=./ go run main.go config-persist --config=config_example.yaml diff --git a/cmd/root.go b/cmd/root.go index a27adfd..2b00799 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -10,7 +10,7 @@ import ( "strings" ) -var homeDir = path.Join(os.Getenv("HOME"), ".config/todolist") +var homeDir = path.Join(Or(os.Getenv("TODOLIST_HOME"), os.Getenv("HOME")), ".config/todolist") func init() { cobra.OnInitialize(initConfig) @@ -50,3 +50,17 @@ func initConfig() { panic(fmt.Errorf("cant unmarshal config file: %w", err).Error()) } } + +func Or[T comparable](value T, alternatives ...T) T { + var zero T + if value != zero { + return value + } + for _, alternative := range alternatives { + if alternative != zero { + return alternative + } + } + + return zero +} diff --git a/config_example.yaml b/config_example.yaml new file mode 100644 index 0000000..01f12b3 --- /dev/null +++ b/config_example.yaml @@ -0,0 +1,34 @@ +server: + diagnostic_endpoints_enabled: true + database_file: .config/todolist/database.json + listen_addr: :8080 + public_url: "" + auth_enabled: false + token_auth: + enabled: false + client_token: api_password + base_auth: + enabled: false + login: "" + password: "" + oidc_auth: + enabled: false + client_id: "" + client_secret: "" + issuer_url: https://accounts.google.com + scopes: + - openid + - email + - profile + cookie_key: kiel4teof4Eoziheigiesh7ooquiepho + whitelist_emails: [] + telegram: + enabled: false + token: "" + userId: 0 + everyday_agenda: + enabled: false + at: 0001-01-01T00:00:00Z +client: + remote_addr: http://127.0.0.1:8080 + server_token: api_password diff --git a/go.mod b/go.mod index b80e2cd..4a919d3 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,12 @@ module github.com/paragor/todo -go 1.21.3 +go 1.23.0 require ( github.com/google/uuid v1.6.0 github.com/gorilla/handlers v1.5.2 github.com/gorilla/mux v1.8.1 + github.com/jedib0t/go-pretty/v6 v6.5.9 github.com/prometheus/client_golang v1.19.1 github.com/spf13/cobra v1.8.1 github.com/zitadel/oidc/v3 v3.26.1 @@ -22,7 +23,6 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/gorilla/securecookie v1.1.2 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/jedib0t/go-pretty/v6 v6.5.9 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/muhlemmer/gu v0.3.1 // indirect github.com/prometheus/client_model v0.5.0 // indirect diff --git a/main.go b/main.go index 3780beb..5234833 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,9 @@ package main -import "github.com/paragor/todo/cmd" +import ( + "github.com/paragor/todo/cmd" + _ "time/tzdata" +) func main() { cmd.Execute() diff --git a/pkg/models/human_input_test.go b/pkg/models/human_input_test.go index c3f513d..ec94a8d 100644 --- a/pkg/models/human_input_test.go +++ b/pkg/models/human_input_test.go @@ -19,7 +19,7 @@ func TestParseHumanInput(t *testing.T) { }{ { args: args{ - input: " modify 358bb57b-7d84-47a0-a3d5-29fcd77f87b9 project:one bla due:2024-10-15T10:00:00 +hui blabla bla -bui notify: status:pending\t \n ", + input: " modify 358bb57b-7d84-47a0-a3d5-29fcd77f87b9 project:one bla due:2024-10-15T10:00:00 +hui blabla bla !bui notify: status:pending\t \n ", }, want: &HumanInputParserResult{ Action: HumanActionModify, diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..c154e98 --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +# todolist + +todo