Skip to content

Commit 115fc26

Browse files
committed
Merge branch 'main' into migrate-cc-to-qlty
# Conflicts: # .secrets.baseline
2 parents 2622f32 + 6986b4b commit 115fc26

6 files changed

Lines changed: 68 additions & 17 deletions

File tree

.github/workflows/update-client.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,18 @@ jobs:
9999
go run main.go -i ../all-service-definition/all-def-flat.yaml -o ../extensions/extension_link_followers.gen.go -t templates/linkfollowers.go.tmpl -g links -c ../client
100100
- name: Copy extensions to client
101101
run: |
102-
if [ -d ./extensions/ ] ; then cp -r extensions/. ${{ env.go_module }}/ ; fi
102+
if [ -d ./extensions/ ]; then
103+
cp -r extensions/. ${{ env.go_module }}/
104+
echo "EXTENSIONS_EXISTS=true" >> $GITHUB_ENV
105+
fi
103106
ls -l ${{ env.go_module }}/*
107+
- name: Upload extensions
108+
if: ${{ env.EXTENSIONS_EXISTS == 'true' }}
109+
uses: actions/upload-artifact@v4
110+
with:
111+
name: extensions
112+
path: extensions/
113+
retention-days: 1
104114
- name: License files
105115
run: |
106116
cd-license-files

.secrets.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,5 @@
149149
}
150150
]
151151
},
152-
"generated_at": "2025-06-13T15:49:02Z"
152+
"generated_at": "2025-06-19T13:33:59Z"
153153
}

changes/20250617120442.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:sparkles: Add support to disable generating extensions for HAL link data

changes/20250619143339.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:green_heart: Upload generated go extension files during CI flow

generator/cmd/root.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"os"
7-
"path/filepath"
87

98
"github.com/spf13/cobra"
109
"github.com/spf13/viper"
@@ -16,12 +15,13 @@ import (
1615
)
1716

1817
const (
19-
app = "generate_code"
20-
inputArg = "input"
21-
outputArg = "output"
22-
templateArg = "template"
23-
GenerateType = "generate"
24-
clientPath = "client_path"
18+
app = "generate_code"
19+
inputArg = "input"
20+
outputArg = "output"
21+
templateArg = "template"
22+
GenerateType = "generate"
23+
clientPath = "client-path"
24+
disableLinksArg = "disable-links"
2525
)
2626

2727
var (
@@ -49,12 +49,14 @@ func init() {
4949
rootCmd.Flags().StringP(templateArg, "t", "", "path to the template file if defaults need overriding")
5050
rootCmd.Flags().StringP(GenerateType, "g", "", "what to generate")
5151
rootCmd.Flags().StringP(clientPath, "c", "", "path to the client go package generated by OpenAPI Generator")
52+
rootCmd.Flags().StringP(disableLinksArg, "d", "", "disable the generation of HAL link data")
5253

5354
_ = configUtils.BindFlagToEnv(viperSession, app, "GENERATE_CODE_INPUT", rootCmd.Flags().Lookup(inputArg))
5455
_ = configUtils.BindFlagToEnv(viperSession, app, "GENERATE_CODE_OUTPUT", rootCmd.Flags().Lookup(outputArg))
5556
_ = configUtils.BindFlagToEnv(viperSession, app, "GENERATE_CODE_TEMPLATE", rootCmd.Flags().Lookup(templateArg))
5657
_ = configUtils.BindFlagToEnv(viperSession, app, "GENERATE_CODE_GENERATE_TYPE", rootCmd.Flags().Lookup(GenerateType))
5758
_ = configUtils.BindFlagToEnv(viperSession, app, "GENERATE_CODE_CLIENT_PATH", rootCmd.Flags().Lookup(clientPath))
59+
_ = configUtils.BindFlagToEnv(viperSession, app, "GENERATE_CODE_DISABLE_LINKS", rootCmd.Flags().Lookup(disableLinksArg))
5860
}
5961

6062
func RunCLI(ctx context.Context) (err error) {
@@ -81,7 +83,12 @@ func RunCLI(ctx context.Context) (err error) {
8183
return
8284
}
8385

84-
err = codegen.CopyStaticFiles(ctx, d.PackageName, filepath.Dir(d.DestinationPath))
86+
staticFileConfig, err := codegen.GenerateStaticFileConfigStruct(extensionConfig)
87+
if err != nil {
88+
return
89+
}
90+
91+
err = codegen.CopyStaticFiles(ctx, staticFileConfig)
8592
if err != nil {
8693
return
8794
}

generator/codegen/common.go

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"go/format"
1010
"path/filepath"
11+
"slices"
1112
"strings"
1213
"text/template"
1314

@@ -44,6 +45,7 @@ type Data struct {
4445
DestinationPath string
4546
ClientPackagePath string
4647
PackageName string
48+
DisableLinks bool
4749
}
4850

4951
var ValidGenerationTargets = map[string]func(*Data) error{
@@ -58,6 +60,13 @@ type ExtensionsConfig struct {
5860
Template string `mapstructure:"template"`
5961
GenerateType string `mapstructure:"generate_type"`
6062
ClientPackagePath string `mapstructure:"client_path"`
63+
DisableLinks bool `mapstructure:"disable_links"`
64+
}
65+
66+
type StaticFileConfig struct {
67+
ClientName string
68+
Destination string
69+
Exclusions []string
6170
}
6271

6372
func DefaultExtensionsConfig() *ExtensionsConfig {
@@ -118,6 +127,24 @@ func GenerateDataStruct(cfg ExtensionsConfig) (d *Data, err error) {
118127
}, nil
119128
}
120129

130+
func GenerateStaticFileConfigStruct(cfg ExtensionsConfig) (d *StaticFileConfig, err error) {
131+
clientName, err := getPackageNameFromPath(cfg.ClientPackagePath)
132+
if err != nil {
133+
return
134+
}
135+
136+
var exclusions []string
137+
if cfg.DisableLinks {
138+
exclusions = append(exclusions, "static/extension_model_hal_link_data.go.static")
139+
}
140+
141+
return &StaticFileConfig{
142+
ClientName: clientName,
143+
Destination: filepath.Dir(cfg.Output),
144+
Exclusions: exclusions,
145+
}, nil
146+
}
147+
121148
func GenerateTemplateFile(ctx context.Context, d *Data) (err error) {
122149
t, err := template.
123150
New(filepath.Base(d.TemplatePath)).
@@ -227,23 +254,28 @@ func isExtensionFlagSet(props openapi3.ExtensionProps, flagKey string) (isSet bo
227254
return
228255
}
229256

230-
func CopyStaticFiles(ctx context.Context, clientName string, destination string) (err error) {
257+
func CopyStaticFiles(ctx context.Context, staticFileConfig *StaticFileConfig) (err error) {
231258
efs, fsErr := filesystem.NewEmbedFileSystem(&static)
232259
if fsErr != nil {
233-
return commonerrors.Newf(commonerrors.ErrUnexpected, "failed to create a filesystem for directory `%s`: %s", destination, fsErr.Error())
260+
return commonerrors.Newf(commonerrors.ErrUnexpected, "failed to create a filesystem for directory `%s`: %s", staticFileConfig.Destination, fsErr.Error())
234261
}
235262

236263
files, lsErr := efs.FindAll(".", "go.static")
237264
if lsErr != nil {
238-
return commonerrors.Newf(commonerrors.ErrUnexpected, "no files with the '.go.static' extension were found in the directory `%s`", destination)
265+
return commonerrors.Newf(commonerrors.ErrUnexpected, "no files with the '.go.static' extension were found in the directory `%s`", staticFileConfig.Destination)
239266
}
240267

241-
mkdirErr := filesystem.MkDir(destination)
268+
mkdirErr := filesystem.MkDir(staticFileConfig.Destination)
242269
if mkdirErr != nil {
243-
return commonerrors.Newf(commonerrors.ErrUnexpected, "could not create directory `%s`: %s", destination, mkdirErr.Error())
270+
return commonerrors.Newf(commonerrors.ErrUnexpected, "could not create directory `%s`: %s", staticFileConfig.Destination, mkdirErr.Error())
244271
}
245272

246273
for _, f := range files {
274+
// Skip the file if it's contained in exclusions
275+
if slices.Contains(staticFileConfig.Exclusions, f) {
276+
continue
277+
}
278+
247279
t, tmplErr := template.
248280
New(filesystem.FilePathBase(efs, f)).
249281
ParseFS(static, f)
@@ -255,8 +287,8 @@ func CopyStaticFiles(ctx context.Context, clientName string, destination string)
255287
resultFileName = strings.TrimSuffix(resultFileName, ".static")
256288

257289
d := Data{
258-
DestinationPath: filepath.Join(destination, resultFileName),
259-
PackageName: clientName,
290+
DestinationPath: filepath.Join(staticFileConfig.Destination, resultFileName),
291+
PackageName: staticFileConfig.ClientName,
260292
}
261293
err = generateSourceCode(ctx, &d, t)
262294
if err != nil {

0 commit comments

Comments
 (0)