Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
134 lines (120 loc) · 5.29 KB
/
Copy pathTaskfile.yml
File metadata and controls
134 lines (120 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
version: '3'
vars:
# Computed by Task's template engine, so no `date` binary is needed (works on Windows too).
BUILD_DATE: '{{now | date "2006-01-02T15:04:05Z07:00"}}'
# Not named VERSION: that one is the user-supplied input of the `tag` task.
BUILD_VERSION:
sh: git describe --tags --always --dirty 2>/dev/null || echo dev
GO: go
BINARY_DIR: bin
BUILD_INFO_LDFLAGS: -ldflags "-w -X main.date={{.BUILD_DATE}} -X main.version={{.BUILD_VERSION}}"
GOLANG_CI: docker run --rm -v "{{.TASKFILE_DIR}}:/app" -w /app golangci/golangci-lint:v2.15.0 golangci-lint
OUTPUT_DIR: "pkg/openapi"
# Codegen output is written here first and swapped into OUTPUT_DIR only on success.
GENERATED_DIR: "build/openapi"
# Canonical spec: JSON from https://beta.epmrpp.reportportal.io/api/api-docs (ReportPortal 26.1, service-api 6.0.0)
SPEC_PATH: "reportportal-api-docs.json"
MODIFIED_SPEC_PATH: "openapi-modified.json"
OPENAPI_GENERATOR_IMAGE: "openapitools/openapi-generator-cli:v7.25.0"
JQ_IMAGE: "ghcr.io/jqlang/jq:1.8.1"
# The file tasks below use plain mkdir/rm/cp/mv/test. On Windows run Task from WSL/Git Bash, or set
# TASK_CORE_UTILS=1 to use the coreutils built into Task.
tasks:
test:
desc: Run Go tests with coverage
cmds:
- "{{.GO}} test -cover ./..."
e2e:
desc: "Run end-to-end tests against a real ReportPortal (credentials from ./.gorp or GORP_CONFIG, not part of CI)"
cmds:
- "{{.GO}} test -tags e2e -count=1 -v ./e2e/... {{.CLI_ARGS}}"
vet:
desc: Run go vet
cmds:
- "{{.GO}} vet ./..."
lint:
desc: Run golangci-lint
cmds:
- "{{.GOLANG_CI}} run ./..."
fmt:
desc: Format code with golangci-lint
cmds:
- "{{.GO}} fmt ./..."
- "{{.GOLANG_CI}} fmt ./..."
build:
desc: Build the Go binary
cmds:
- "{{.GO}} build {{.BUILD_INFO_LDFLAGS}} -o {{.BINARY_DIR}}/gorp ./"
tag:
desc: Create and push a git tag
cmds:
- git tag -a v{{.VERSION}} -m "creating tag {{.VERSION}}"
- git push origin "refs/tags/v{{.VERSION}}"
requires:
vars: [ VERSION ]
release:
desc: Run goreleaser to create a release
cmds:
- goreleaser release --clean
clean:
desc: "Remove binary and build output (the generated OpenAPI client in {{.OUTPUT_DIR}} is kept, use generate-openapi-client)"
cmds:
- rm -rf "{{.BINARY_DIR}}" build dist
# Generate OpenAPI client code from the ReportPortal's OpenAPI schema
# Note that not all additional properties are properly documented in the OpenAPI generator documentation
# For instance, the `withCustomMiddlewareFunction` property is not documented, but can be found here:
# https://github.com/OpenAPITools/openapi-generator/blob/v7.25.0/modules/openapi-generator/src/main/resources/go/configuration.mustache#L106C4-L106C32
generate-openapi-client:
desc: "Generate Go client from {{.SPEC_PATH}} (preprocessed into {{.MODIFIED_SPEC_PATH}})"
cmds:
# Always derive the input from the committed spec: the preprocessed file is git-ignored.
- task: preprocess:schema
- rm -rf "{{.GENERATED_DIR}}"
- mkdir -p "{{.GENERATED_DIR}}"
- >-
docker run --rm -v "{{.TASKFILE_DIR}}/{{.GENERATED_DIR}}:/generated"
-v "{{.TASKFILE_DIR}}/{{.MODIFIED_SPEC_PATH}}:/local/openapi.json" {{.OPENAPI_GENERATOR_IMAGE}} generate
-i /local/openapi.json -g go -o /generated --package-name openapi
--additional-properties=withGoCodegenComment=true,enumClassPrefix=true,onlyGenerateClient=true,withGoMod=false,withCustomMiddlewareFunction=true,useOneOfDiscriminatorLookup=true
--git-repo-id gorp/v5/pkg/openapi --git-user-id reportportal
--global-property modelDocs=false,apiDocs=false,apiTests=false
- cp scripts/openapi-compat/compat.go.tmpl "{{.GENERATED_DIR}}/compat.go"
# Swap only after generation succeeded, so a failed run doesn't delete the committed client.
- rm -rf "{{.OUTPUT_DIR}}"
- mv "{{.GENERATED_DIR}}" "{{.OUTPUT_DIR}}"
# Default ReportPortal's OpenAPI schema needs to be preprocessed
# due to incorrect map/dictionary type handling in the Golang OpenAPI generator
# For the Java code containing type Map<String, Object> the following OpenAPI schema is generated:
# {
# "type": "object",
# "additionalProperties": {
# "type": "object"
# }
# }
# Which results in a Go type of map[string]map[string]interface{} that
# is not compatible with the ReportPortal's API responses, for instance:
# "metadata" : {
# "qualityGate" : {
# "id" : 415,
# "status" : "FAILED"
# },
# "rp.cluster.lastRun" : "1749732585366"
# },
# The following JQ command converts mentioned types to:
# {
# "type": "object",
# "additionalProperties": true
# }
# This allows the Go OpenAPI generator to create a map[string]interface{} type which accepts any JSON object
preprocess:schema:
desc: Apply the JQ filter that fixes Map<String,Object> types (and more) for Go codegen
sources:
- "{{.SPEC_PATH}}"
- scripts/openapi-preprocess.jq
generates:
- "{{.MODIFIED_SPEC_PATH}}"
cmds:
- test -s "{{.SPEC_PATH}}"
- >-
docker run --rm -i -v "{{.TASKFILE_DIR}}/scripts:/scripts:ro" {{.JQ_IMAGE}}
-f /scripts/openapi-preprocess.jq < "{{.SPEC_PATH}}" > "{{.MODIFIED_SPEC_PATH}}"