mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-14 09:55:12 +00:00
chore(ci): improving CI reliability when caching (#11501)
This fixes a case where potentially some static files get not properly treated as inputs in the hash for nx cache calculation. Also it fixes a problem where the assets.mdx get sorted randomly each generation. Factors in some overlap from https://github.com/zitadel/zitadel/pull/11447 --------- Co-authored-by: Copilot <[email protected]>
This commit is contained in:
co-authored by
Copilot
parent
0999e44821
commit
04c58c5b3f
@@ -4,6 +4,7 @@ import (
|
||||
"flag"
|
||||
"io"
|
||||
"os"
|
||||
"sort"
|
||||
"text/template"
|
||||
|
||||
"github.com/zitadel/logging"
|
||||
@@ -97,6 +98,48 @@ type Service struct {
|
||||
Methods map[string]Method
|
||||
}
|
||||
|
||||
type SortedService struct {
|
||||
Prefix string
|
||||
Methods []SortedMethod
|
||||
}
|
||||
|
||||
type SortedMethod struct {
|
||||
Name string
|
||||
Method
|
||||
}
|
||||
|
||||
func (s Services) toSorted() []SortedService {
|
||||
keys := make([]string, 0, len(s))
|
||||
for k := range s {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
sorted := make([]SortedService, len(keys))
|
||||
for i, k := range keys {
|
||||
sorted[i] = SortedService{
|
||||
Prefix: s[k].Prefix,
|
||||
Methods: s[k].toSortedMethods(),
|
||||
}
|
||||
}
|
||||
return sorted
|
||||
}
|
||||
|
||||
func (s Service) toSortedMethods() []SortedMethod {
|
||||
keys := make([]string, 0, len(s.Methods))
|
||||
for k := range s.Methods {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
sorted := make([]SortedMethod, len(keys))
|
||||
for i, k := range keys {
|
||||
sorted[i] = SortedMethod{
|
||||
Name: k,
|
||||
Method: s.Methods[k],
|
||||
}
|
||||
}
|
||||
return sorted
|
||||
}
|
||||
|
||||
func GenerateAssetHandler(configFilePath, handlerPrefix string, authz, router, docs io.Writer) {
|
||||
conf := new(struct {
|
||||
Services Services
|
||||
@@ -113,12 +156,12 @@ func GenerateAssetHandler(configFilePath, handlerPrefix string, authz, router, d
|
||||
GoPkgName string
|
||||
Name string
|
||||
Prefix string
|
||||
Services Services
|
||||
Services []SortedService
|
||||
}{
|
||||
GoPkgName: "assets",
|
||||
Name: "AssetsService",
|
||||
Prefix: handlerPrefix,
|
||||
Services: conf.Services,
|
||||
Services: conf.Services.toSorted(),
|
||||
}
|
||||
err = tmplAuthz.Execute(authz, data)
|
||||
logging.Log("ASSETS-BHngj").OnError(err).Fatal("cannot generate authz")
|
||||
@@ -180,11 +223,11 @@ type {{.Name}} interface {
|
||||
Storage() static.Storage
|
||||
|
||||
{{ range $service := .Services}}
|
||||
{{ range $methodName, $method := .Methods}}
|
||||
{{ range $method := .Methods}}
|
||||
{{ range $handler := .Handlers}}
|
||||
{{$handler.Name}}{{$methodName}}() {{if $handler.MethodReturn}}{{$handler.MethodReturn}}{{end}}
|
||||
{{$handler.Name}}{{$method.Name}}() {{if $handler.MethodReturn}}{{$handler.MethodReturn}}{{end}}
|
||||
{{ if $method.HasDarkMode }}
|
||||
{{$handler.Name}}{{$methodName}}Dark() {{if $handler.MethodReturn}}{{$handler.MethodReturn}}{{end}}
|
||||
{{$handler.Name}}{{$method.Name}}Dark() {{if $handler.MethodReturn}}{{$handler.MethodReturn}}{{end}}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
@@ -196,11 +239,11 @@ func RegisterRoutes(router *mux.Router, s {{.Name}}) {
|
||||
router.Use(s.AuthInterceptor().Handler)
|
||||
|
||||
{{ range $service := .Services}}
|
||||
{{ range $methodName, $method := .Methods}}
|
||||
{{ range $method := .Methods}}
|
||||
{{ range $handler := .Handlers}}
|
||||
router.Path("{{$service.Prefix}}{{$method.Path}}{{$handler.PathSuffix}}").Methods("{{$handler.Method}}").HandlerFunc({{if $handler.HandlerType}}{{$handler.HandlerType}}(s, {{end}}s.{{$handler.Name}}{{$methodName}}(){{if $handler.HandlerType}}){{end}})
|
||||
router.Path("{{$service.Prefix}}{{$method.Path}}{{$handler.PathSuffix}}").Methods("{{$handler.Method}}").HandlerFunc({{if $handler.HandlerType}}{{$handler.HandlerType}}(s, {{end}}s.{{$handler.Name}}{{$method.Name}}(){{if $handler.HandlerType}}){{end}})
|
||||
{{ if $method.HasDarkMode }}
|
||||
router.Path("{{$service.Prefix}}{{$method.Path}}/dark{{$handler.PathSuffix}}").Methods("{{$handler.Method}}").HandlerFunc({{if $handler.HandlerType}}{{$handler.HandlerType}}(s, {{end}}s.{{$handler.Name}}{{$methodName}}Dark(){{if $handler.HandlerType}}){{end}})
|
||||
router.Path("{{$service.Prefix}}{{$method.Path}}/dark{{$handler.PathSuffix}}").Methods("{{$handler.Method}}").HandlerFunc({{if $handler.HandlerType}}{{$handler.HandlerType}}(s, {{end}}s.{{$handler.Name}}{{$method.Name}}Dark(){{if $handler.HandlerType}}){{end}})
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
@@ -212,21 +255,26 @@ const docsTmpl = `---
|
||||
title: zitadel/assets
|
||||
---
|
||||
|
||||
{/*
|
||||
Code generated by assets generator. DO NOT EDIT.
|
||||
This file is checked in to support building docs without a Go environment.
|
||||
*/}
|
||||
|
||||
## {{.Name}}
|
||||
|
||||
{{ range $service := .Services}}
|
||||
{{ range $methodName, $method := .Methods}}
|
||||
{{ range $method := .Methods}}
|
||||
{{ range $handler := .Handlers}}
|
||||
|
||||
### {{$handler.Name}}{{$methodName}}()
|
||||
### {{$handler.Name}}{{$method.Name}}()
|
||||
|
||||
> {{$handler.Name}}{{$methodName}}()
|
||||
> {{$handler.Name}}{{$method.Name}}()
|
||||
|
||||
{{$handler.Method}}: {{$service.Prefix}}{{$method.Path}}{{$handler.PathSuffix}}
|
||||
{{ if $method.HasDarkMode }}
|
||||
### {{$handler.Name}}{{$methodName}}()
|
||||
### {{$handler.Name}}{{$method.Name}}Dark()
|
||||
|
||||
> {{$handler.Name}}{{$methodName}}Dark()
|
||||
> {{$handler.Name}}{{$method.Name}}Dark()
|
||||
|
||||
{{$handler.Method}}: {{$service.Prefix}}{{$method.Path}}/dark{{$handler.PathSuffix}}
|
||||
{{ end }}
|
||||
|
||||
Reference in New Issue
Block a user