11 Commits

Author SHA1 Message Date
jimehbot[bot]
27554f2a04 chore(main): release 2.4.1 (#23)
Co-authored-by: jimehbot[bot] <132453784+jimehbot[bot]@users.noreply.github.com>
2025-03-16 02:07:32 +00:00
cc42b4f2bc fix(ci/build): add missing permission to release job 2025-03-16 02:05:01 +00:00
jimehbot[bot]
15768d9a64 chore(main): release 2.4.0 (#22)
Co-authored-by: jimehbot[bot] <132453784+jimehbot[bot]@users.noreply.github.com>
2025-03-16 01:24:06 +00:00
d10ef9f603 chore(deps): specify exact version in go.mod 2025-03-16 01:18:01 +00:00
2f658ecfcb ci(chart): try again to make release-please update Chart.yaml correctly 2025-03-16 01:11:04 +00:00
317782e77e ci(chart): fixed typo in release-please config 2025-03-16 01:09:18 +00:00
2dd53f398a ci(chart): attempt to fix release-please chart version update 2025-03-16 01:04:45 +00:00
88733428f5 chore(chart): simplify Chart.yaml file for the sake of release-please 2025-03-16 00:53:37 +00:00
50c538e3b7 feat: use Go 1.24 and a net/http ServeMux for routing (#19) 2025-03-16 00:50:12 +00:00
90728a4807 ci(deps): update workflow actions and config (#18) 2025-03-16 00:43:20 +00:00
de40d5459f ci(release): split chart release into separate job
Currently the chart release seems to not work, but that's an issue for
another day.
2023-04-28 12:16:01 +01:00
10 changed files with 123 additions and 103 deletions

3
.github/.release-please-manifest.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
".": "2.4.1"
}

View File

@@ -6,9 +6,19 @@
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"draft": false,
"always-update": true,
"prerelease": false,
"extra-files": [
"chart/Chart.yaml"
{
"type": "yaml",
"path": "chart/Chart.yaml",
"jsonpath": "appVersion"
},
{
"type": "yaml",
"path": "chart/Chart.yaml",
"jsonpath": "version"
}
]
}
},

View File

@@ -4,13 +4,12 @@ on: [push]
jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version-file: "go.mod"
- name: Install dependencies
run: go mod download
- name: Build binary
@@ -24,45 +23,43 @@ jobs:
helm-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: azure/setup-helm@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v4
- uses: azure/setup-helm@v4
- name: Lint chart
run: helm lint chart
- name: Template chart
run: helm template chart
release-please:
name: Release Please
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
if: startsWith(github.ref, 'refs/heads/')
permissions:
contents: write
pull-requests: write
outputs:
release_created: ${{ steps.release-please.outputs.release_created }}
tag_name: ${{ steps.release-please.outputs.tag_name }} # e.g. v1.0.0
version: ${{ steps.release-please.outputs.version }} # e.g. 1.0.0
all: ${{ toJSON(steps.release-please.outputs) }}
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }} # e.g. v1.0.0
version: ${{ steps.release.outputs.version }} # e.g. 1.0.0
steps:
- uses: google-github-actions/release-please-action@v3
id: release-please
- uses: jimeh/release-please-manifest-action@v2
id: release
with:
command: manifest
target-branch-pattern: '^(main|master|release-[0-9]+(\.[0-9]+)?\.x)$'
app-id: ${{ secrets.RELEASE_BOT_APP_ID }}
private-key: ${{ secrets.RELEASE_BOT_PRIVATE_KEY }}
release:
runs-on: ubuntu-latest
needs: [build, helm-lint, release-please]
if: needs.release-please.outputs.release_created
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --force --tags
- name: Configure Git
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Install Helm
uses: azure/setup-helm@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
@@ -72,24 +69,40 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version-file: "go.mod"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --rm-dist
version: '~> v2'
args: release --clean
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Package chart
run: helm package ./chart -d .cr-release-packages
release-chart:
runs-on: ubuntu-latest
needs: [release, release-please]
if: needs.release-please.outputs.release_created
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --force --tags
- name: Configure Git
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Install Helm
uses: azure/setup-helm@v4
- name: Run chart-releaser
uses: helm/chart-releaser-action@v1
with:
charts_dir: chart
config: .cr.yaml
skip_packaging: true
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

View File

@@ -1,3 +1,4 @@
version: 2
before:
hooks:
- go mod tidy
@@ -27,23 +28,21 @@ universal_binaries:
- replace: false
archives:
- format: tar.gz
- formats: ["tar.gz"]
name_template: |-
{{ .ProjectName }}-{{ .Version }}_{{ .Os }}_{{ if eq .Arch "all" }}universal{{ else }}{{ .Arch }}{{ end }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}
{{ .ProjectName }}-{{ .Version }}_{{ if eq .Os "darwin" }}macos{{ else }}{{ .Os }}{{ end }}_{{ if eq .Arch "all" }}universal{{ else }}{{ .Arch }}{{ end }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}
wrap_in_directory: true
format_overrides:
- goos: windows
format: zip
replacements:
darwin: macos
formats: ["zip"]
checksum:
name_template: "checksums.txt"
snapshot:
name_template: "{{ .Tag }}-next"
version_template: "{{ .Tag }}-next"
changelog:
skip: true
disable: true
dockers:
- image_templates:

View File

@@ -1,3 +0,0 @@
{
".": "2.3.0"
}

View File

@@ -1,5 +1,19 @@
# Changelog
## [2.4.1](https://github.com/jimeh/casecmp/compare/v2.4.0...v2.4.1) (2025-03-16)
### Bug Fixes
* **ci/build:** add missing permission to release job ([cc42b4f](https://github.com/jimeh/casecmp/commit/cc42b4f2bc8112b249bcf1a596989618ee80ca0d))
## [2.4.0](https://github.com/jimeh/casecmp/compare/v2.3.0...v2.4.0) (2025-03-16)
### Features
* use Go 1.24 and a net/http ServeMux for routing ([#19](https://github.com/jimeh/casecmp/issues/19)) ([50c538e](https://github.com/jimeh/casecmp/commit/50c538e3b78d841bf09653a1571a8019a2126be0))
## [2.3.0](https://github.com/jimeh/casecmp/compare/v2.2.0...v2.3.0) (2023-04-26)

View File

@@ -1,6 +1,6 @@
NAME = casecmp
BINARY = bin/${NAME}
VERSION ?= $(shell cat VERSION)
VERSION ?= $(shell git describe --tags)
SOURCES = $(shell find . -name '*.go' -o -name 'Makefile')
$(BINARY): $(SOURCES)

View File

@@ -1,24 +1,6 @@
apiVersion: v2
name: casecmp
description: A Helm chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
description: A Helm chart for casecmp
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 2.3.0 # x-release-please-version
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: 2.3.0 # x-release-please-version
version: 2.4.1
appVersion: 2.4.1

2
go.mod
View File

@@ -1,3 +1,3 @@
module github.com/jimeh/casecmp
go 1.20
go 1.24.1

76
main.go
View File

@@ -56,6 +56,11 @@ curl -X POST -H "Content-Type: application/json" -d '{"a":"Foo Bar","b":"FOO BAR
`))
func indexHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" || r.URL.RawQuery != "" {
casecmpHandler(w, r)
return
}
scheme := "http"
if r.TLS != nil || *forceHTTPSFlag {
scheme = "https"
@@ -89,20 +94,44 @@ type JSONData struct {
B string `json:"b"`
}
func casecmpHandler(w http.ResponseWriter, r *http.Request) error {
func casecmpHandler(w http.ResponseWriter, r *http.Request) {
equal, err := casecmp(r)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = fmt.Fprint(w, err.Error())
return
}
resp := "0"
if equal {
resp = "1"
}
accept := r.Header.Get("Accept")
if strings.Contains(accept, "application/json") {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
_, _ = fmt.Fprintf(w, `{"result":%s}`, resp)
return
}
_, _ = fmt.Fprint(w, resp)
}
func casecmp(r *http.Request) (bool, error) {
var a, b string
contentType := r.Header.Get("Content-Type")
if strings.Contains(contentType, "application/json") {
body, err := io.ReadAll(r.Body)
if err != nil {
return err
return false, err
}
d := JSONData{}
err = json.Unmarshal(body, &d)
if err != nil {
return err
return false, fmt.Errorf("invalid JSON request: %w", err)
}
a = d.A
@@ -112,39 +141,7 @@ func casecmpHandler(w http.ResponseWriter, r *http.Request) error {
b = r.FormValue("b")
}
resp := "0"
if strings.EqualFold(string(a), string(b)) {
resp = "1"
}
accept := r.Header.Get("Accept")
if strings.Contains(accept, "application/json") {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
_, err := fmt.Fprintf(w, `{"result":%s}`, resp)
return err
}
_, err := fmt.Fprint(w, resp)
return err
}
func handler(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/":
if r.Method != "GET" || r.URL.RawQuery != "" {
err := casecmpHandler(w, r)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = fmt.Fprint(w, err.Error())
}
return
}
indexHandler(w, r)
case "/about":
aboutHandler(w, r)
default:
http.NotFound(w, r)
}
return strings.EqualFold(string(a), string(b)), nil
}
func printVersion() {
@@ -184,6 +181,11 @@ func startServer() error {
*forceHTTPSFlag = true
}
mux := http.NewServeMux()
mux.HandleFunc("/{$}", indexHandler)
mux.HandleFunc("/about", aboutHandler)
mux.HandleFunc("/about/{$}", aboutHandler)
address := fmt.Sprintf("%s:%d", *bindFlag, *portFlag)
fmt.Printf("Listening on %s\n", address)
@@ -191,7 +193,7 @@ func startServer() error {
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
IdleTimeout: 30 * time.Second,
Handler: http.HandlerFunc(handler),
Handler: mux,
Addr: address,
}