Skip to content

Commit 135efbb

Browse files
committed
fix: github actions
1 parent 9272e21 commit 135efbb

File tree

8 files changed

+95
-24
lines changed

8 files changed

+95
-24
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ on:
77
workflow_dispatch: {}
88
push:
99
branches:
10-
- master
10+
- main
1111
tags:
1212
- v[0-9]+.[0-9]+.[0-9]+*
1313
pull_request:
1414
branches:
15-
- master
15+
- main
1616

1717
jobs:
1818
lint:
@@ -24,7 +24,7 @@ jobs:
2424
- name: Set up PHP
2525
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.31.0
2626
with:
27-
php-version: '8.3'
27+
php-version: '8.4'
2828
extensions: intl
2929
coverage: none
3030

@@ -43,7 +43,7 @@ jobs:
4343
- name: Set up PHP
4444
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.31.0
4545
with:
46-
php-version: '8.3'
46+
php-version: '8.4'
4747
coverage: none
4848
tools: composer:v2
4949

@@ -62,7 +62,7 @@ jobs:
6262
strategy:
6363
fail-fast: false
6464
matrix:
65-
php: ['7.4', '8.2']
65+
php: ['8.2', '8.3', '8.4', '8.5']
6666
steps:
6767
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
6868

@@ -82,7 +82,7 @@ jobs:
8282
release-please:
8383
name: Prepare release
8484
runs-on: ubuntu-latest
85-
if: github.ref == 'refs/heads/master'
85+
if: github.ref == 'refs/heads/main'
8686
permissions:
8787
contents: write
8888
pull-requests: write

.github/workflows/codegen.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ name: Codegen CI
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77
paths:
88
- "codegen/**"
99
- ".github/workflows/codegen.yaml"
1010
pull_request:
1111
branches:
12-
- master
12+
- main
1313
paths:
1414
- "codegen/**"
1515
- ".github/workflows/codegen.yaml"

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
help: ## Show help
55
@grep -Eh '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
66

7-
export PHPDOCUMENTOR_VERSION := v3.0.0
8-
97
.PHONY: vendor
108
vendor: composer.json ## Install dependencies
119
composer install
@@ -20,7 +18,7 @@ fmtcheck: vendor ## Check code formatting
2018

2119
.PHONY: docs
2220
docs: vendor ## Generate API reference using phpDocumentor
23-
docker run --rm -v "$(pwd):/data" "phpdoc/phpdoc:3"
21+
docker run --rm -v "$(CURDIR):/data" "phpdoc/phpdoc:3"
2422

2523
.PHONY: test
2624
test: vendor ## Run PHPUnit test suite

codegen/.golangci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: "2"
2+
linters:
3+
default: standard
4+
issues:
5+
max-same-issues: 0
6+
max-issues-per-linter: 0
7+
uniq-by-line: true
8+
formatters:
9+
enable:
10+
- gofmt
11+
- goimports
12+
settings:
13+
gci:
14+
sections:
15+
- standard
16+
- default
17+
- prefix(github.com/sumup/sumup-py/codegen)
18+
- dot
19+
gofmt:
20+
simplify: true
21+
goimports:
22+
local-prefixes:
23+
- github.com/sumup/sumup-py/codegen
24+
exclusions:
25+
generated: lax

codegen/Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Make this makefile self-documented with target `help`
2+
.PHONY: help
3+
.DEFAULT_GOAL := help
4+
help: ## Show help
5+
@grep -Eh '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
6+
7+
.PHONY: fmt
8+
fmt: ## Format go files
9+
golangci-lint fmt -v
10+
11+
.PHONY: lint
12+
lint: ## Lint go files
13+
golangci-lint run -v
14+
15+
.PHONY: test
16+
test: ## Run tests
17+
go test -v -failfast -race -timeout 10m ./...
18+
19+
.PHONY: download
20+
download:
21+
@echo Download go.mod dependencies
22+
@go mod download
23+
24+
.PHONE: vulncheck
25+
vulncheck: ## Check for Vulnerabilities (make sure you have the tools install: `make install-tools`)
26+
govulncheck ./...
27+
28+
.PHONY: install
29+
install: ## Install latest version of py-sdk-gen
30+
go install ./cmd/py-sdk-gen/...
31+
32+
.PHONY: generate
33+
generate: ## Generate all test files
34+
@set -e
35+
find ./tests -type f -name 'go.mod' -execdir sh -c 'go generate ./...' \;
36+
37+
.PHONY: update-examples
38+
update-examples: ## Update all examples
39+
@set -e
40+
find ./examples -type f -name 'Makefile' -execdir sh -c 'make' \;

codegen/pkg/generator/generator.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,21 +262,23 @@ func (g *Generator) buildPHPEnum(enum enumDefinition) string {
262262
}
263263

264264
backingType := ""
265-
if enum.Type == "string" {
265+
switch enum.Type {
266+
case "string":
266267
backingType = ": string"
267-
} else if enum.Type == "int" {
268+
case "int":
268269
backingType = ": int"
269270
}
270271

271272
fmt.Fprintf(&buf, "enum %s%s\n{\n", enum.Name, backingType)
272273

273274
for _, value := range enum.Values {
274275
caseName := phpEnumCaseName(value)
275-
if enum.Type == "string" {
276+
switch enum.Type {
277+
case "string":
276278
fmt.Fprintf(&buf, " case %s = '%s';\n", caseName, value)
277-
} else if enum.Type == "int" {
279+
case "int":
278280
fmt.Fprintf(&buf, " case %s = %s;\n", caseName, value)
279-
} else {
281+
default:
280282
fmt.Fprintf(&buf, " case %s;\n", caseName)
281283
}
282284
}

codegen/pkg/generator/names.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ func phpEnumName(schemaName, propertyName string) string {
4848
propertyName = strings.TrimSpace(propertyName)
4949
propertyName = strings.ReplaceAll(propertyName, "-", "_")
5050
propertyName = strings.ReplaceAll(propertyName, ".", "_")
51-
51+
5252
baseName := strcase.ToCamel(propertyName)
5353
return schemaName + baseName
5454
}
5555

5656
func phpEnumCaseName(value string) string {
5757
value = strings.TrimSpace(value)
58-
58+
5959
// Handle numeric values or values that start with numbers
6060
if len(value) > 0 && value[0] >= '0' && value[0] <= '9' {
6161
value = "VALUE_" + value
6262
}
63-
63+
6464
// Replace common separators and special characters
6565
value = strings.ReplaceAll(value, "+", "_PLUS_")
6666
value = strings.ReplaceAll(value, "-", "_")
@@ -80,21 +80,21 @@ func phpEnumCaseName(value string) string {
8080
value = strings.ReplaceAll(value, ",", "_")
8181
value = strings.ReplaceAll(value, "'", "_")
8282
value = strings.ReplaceAll(value, "\"", "_")
83-
83+
8484
// Convert to screaming snake case
8585
value = strcase.ToScreamingSnake(value)
86-
86+
8787
// Clean up multiple underscores
8888
for strings.Contains(value, "__") {
8989
value = strings.ReplaceAll(value, "__", "_")
9090
}
91-
91+
9292
// Ensure it doesn't start with underscore (unless it's a special value)
9393
value = strings.TrimLeft(value, "_")
94-
94+
9595
if value == "" {
9696
return "EMPTY"
9797
}
98-
98+
9999
return value
100100
}

codegen/pkg/generator/sumup.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import (
1212
"github.com/iancoleman/strcase"
1313
)
1414

15+
//nolint:unused // retained for future SumUp class generation
1516
var reservedServiceNames = map[string]struct{}{
1617
"Authorization": {},
1718
"Custom": {},
1819
}
1920

21+
//nolint:unused // writeSumUpClass is kept for the legacy SumUp SDK surface
2022
func (g *Generator) writeSumUpClass() error {
2123
dir := g.cfg.Out
2224
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
@@ -225,6 +227,7 @@ class SumUp
225227
return nil
226228
}
227229

230+
//nolint:unused // helper is used when SumUp class generation is re-enabled
228231
func (g *Generator) collectServiceDefinitions() []string {
229232
if len(g.operationsByTag) == 0 {
230233
return nil
@@ -255,6 +258,7 @@ func (g *Generator) collectServiceDefinitions() []string {
255258
return services
256259
}
257260

261+
//nolint:unused // helper for the SumUp class code generation
258262
func sumUpUseStatements(serviceNames []string) []string {
259263
uses := []string{
260264
"SumUp\\Application\\ApplicationConfiguration",
@@ -282,6 +286,7 @@ func sumUpUseStatements(serviceNames []string) []string {
282286
return append(uses, serviceUses...)
283287
}
284288

289+
//nolint:unused // helper for generating the SumUp class docblocks
285290
func renderSumUpPropertyDocs(serviceNames []string) string {
286291
if len(serviceNames) == 0 {
287292
return ""
@@ -296,6 +301,7 @@ func renderSumUpPropertyDocs(serviceNames []string) string {
296301
return buf.String()
297302
}
298303

304+
//nolint:unused // helper for generating the SumUp class service map
299305
func renderSumUpServiceMap(serviceNames []string) string {
300306
if len(serviceNames) == 0 {
301307
return ""

0 commit comments

Comments
 (0)