Skip to content

Commit

Permalink
Replace html/template with a-h/templ (#25)
Browse files Browse the repository at this point in the history
* Replace html/template with a-h/templ

* Added extensions recommendations

* Added generate tag

* Added README.md note on Templ

* Added .editorconfig

* Added license header to .editorconfig

* Added missing LF at EOF

* Added more missing EOL at EOF

* Hide templ generated files

* Updated templ

* Added templ to Makefile

* Updated version in README.md

* Added workflow

* Install correct version

* Generate with correct version

* Updated README.md
  • Loading branch information
applejag authored Mar 27, 2024
1 parent 3f89c0e commit 8a01468
Show file tree
Hide file tree
Showing 47 changed files with 2,623 additions and 673 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: 2022 Risk.Ident GmbH <[email protected]>
#
# SPDX-License-Identifier: CC0-1.0

root = true

[*]
indent_size = 2
indent_style = space
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf

[{*.{go,templ},go.mod,go.sum,Makefile}]
indent_style = tab
indent_size = 4
28 changes: 28 additions & 0 deletions .github/workflows/go-templ.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-FileCopyrightText: 2024 Risk.Ident GmbH <[email protected]>
#
# SPDX-License-Identifier: CC0-1.0

name: templ

on:
push:
branches:
- main
pull_request:

jobs:
templ:
runs-on: ubuntu-latest
name: Run templ generate
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Run templ generate
run: make generate

- name: Fail on git diff
run: git diff --exit-code
2 changes: 1 addition & 1 deletion .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

name: govulncheck

on:
on:
push:
branches:
- main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reuse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

name: REUSE Compliance Check

on:
on:
push:
branches:
- main
Expand Down
8 changes: 8 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Jelease
Upstream-Contact: Risk.Ident GmbH <[email protected]>
Source: https://github.com/RiskIdent/jelease

Files: templates/*_templ.go
Copyright: 2022 Risk.Ident GmbH
License: GPL-3.0-or-later
12 changes: 12 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-FileCopyrightText: 2022 Risk.Ident GmbH <[email protected]>
//
// SPDX-License-Identifier: CC0-1.0
{
"recommendations": [
"editorconfig.editorconfig",
"streetsidesoftware.code-spell-checker",
"golang.go",
"a-h.templ",
"redhat.vscode-yaml"
]
}
30 changes: 30 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: 2022 Risk.Ident GmbH <[email protected]>
//
// SPDX-License-Identifier: CC0-1.0
{
"cSpell.words": [
"gonic",
"jelease",
"newreleases",
"Templ",
"templating",
"tmpl",
"zerolog"
],
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/*_templ.go": true
},
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.patterns": {
"*": "${capture}.license",
"package.json": "package-lock.json, yarn.lock, pnpm-lock.yaml",
"Chart.yaml": "Chart.lock, .helmignore",
},
"explorer.fileNesting.expand": false
}
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
# SPDX-License-Identifier: CC0-1.0

.PHONY: all
all: jelease.schema.json
all: jelease.schema.json generate

jelease.schema.json: pkg/config/*.go cmd/config_schema.go
go run . config schema --output jelease.schema.json

.PHONY: generate
generate:
go run github.com/a-h/templ/cmd/templ@$(shell go list -m -f '{{ .Version }}' github.com/a-h/templ) generate

.PHONY: test
test:
go test ./...
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ config file:
curl localhost:8080/webhook -d @examples/newreleasesio-webhook.json
```

## Development

Prerequisites:

- Go 1.21 (or later): <https://go.dev/doc/install>

The HTML pages are templated using Templ. This is a manual step that
needs to be done after each code change to any `.templ` files.

```bash
go generate
```

The generate command effectively runs `go run ...`, so you don't
need `templ` CLI installed.

## Building the application and docker image

```bash
Expand Down
4 changes: 1 addition & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (

var (
cfg config.Config
htmlTemplates fs.FS
htmlStaticFiles fs.FS

appVersion string // may be set via `go build` flags
Expand All @@ -58,8 +57,7 @@ var rootCmd = &cobra.Command{
},
}

func Execute(defaultConfig config.Config, templatesFS fs.FS, staticFilesFS fs.FS) {
htmlTemplates = templatesFS
func Execute(defaultConfig config.Config, staticFilesFS fs.FS) {
htmlStaticFiles = staticFilesFS
cfg = defaultConfig

Expand Down
6 changes: 3 additions & 3 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func init() {
}

func run() error {
if htmlTemplates == nil {
return fmt.Errorf("no HTML templates loaded")
if htmlStaticFiles == nil {
return fmt.Errorf("no static files loaded")
}

jiraClient, err := jira.New(&cfg.Jira)
Expand All @@ -73,7 +73,7 @@ func run() error {
return err
}

s := server.New(&cfg, jiraClient, patcher, htmlTemplates, htmlStaticFiles)
s := server.New(&cfg, jiraClient, patcher, htmlStaticFiles)
return s.Serve()
}

Expand Down
21 changes: 13 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ module github.com/RiskIdent/jelease
go 1.21.5

require (
github.com/a-h/templ v0.2.648
github.com/andygrunwald/go-jira v1.16.0
github.com/bradleyfalzon/ghinstallation/v2 v2.7.0
github.com/fatih/color v1.15.0
github.com/gin-contrib/multitemplate v0.0.0-20230212012517-45920c92c271
github.com/fatih/color v1.16.0
github.com/gin-gonic/gin v1.9.1
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/google/go-github/v48 v48.2.0
Expand All @@ -28,14 +28,17 @@ require (

require (
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c // indirect
github.com/a-h/parse v0.0.0-20240121214402-3caf7543159a // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/cli/browser v1.2.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
Expand All @@ -53,7 +56,7 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
Expand All @@ -69,12 +72,14 @@ require (
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.5.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)
Loading

0 comments on commit 8a01468

Please sign in to comment.