This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
101 lines (78 loc) · 3 KB
/
Makefile
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
.PHONY: all pull fetch patch generate clean codegen mod docs move-other patch-post fmt test stage
CURRENT_UID := $(shell id -u)
CURRENT_GID := $(shell id -g)
SPEC_BASE_URL:=https://api.equinix.com/metal/v1/api-docs
SPEC_ROOT_FILE:=openapi3.yaml
SPEC_FETCHED_DIR=spec/oas3.fetched
SPEC_PATCH_DIR=patches/spec.fetched.json
SPEC_PATCHED_DIR=spec/oas3.patched
SPEC_FETCHED_FILE:=spec.fetched.json
SPEC_PATCHED_FILE:=spec.patched.json
OPENAPI_IMAGE_TAG=v7.1.0
OPENAPI_IMAGE=openapitools/openapi-generator-cli:${OPENAPI_IMAGE_TAG}
GIT_ORG=equinix-labs
GIT_REPO=metal-go
PACKAGE_PREFIX=metal
PACKAGE_MAJOR=v1
PACKAGE_VERSION=$(shell cat version)
CRI=docker # nerdctl
OPENAPI_GENERATOR=${CRI} run --rm -u ${CURRENT_UID}:${CURRENT_GID} -v $(CURDIR):/local ${OPENAPI_IMAGE}
SPEC_FETCHER=${CRI} run --rm -u ${CURRENT_UID}:${CURRENT_GID} -v $(CURDIR):/workdir --entrypoint sh mikefarah/yq:4.30.8 script/download_spec.sh
GOLANGCI_LINT=golangci-lint
all: pull fetch patch generate stage
generate: clean codegen mod docs move-other patch-post fmt test
pull:
${CRI} pull ${OPENAPI_IMAGE}
fetch:
${SPEC_FETCHER} ${SPEC_BASE_URL} ${SPEC_FETCHED_DIR} ${SPEC_ROOT_FILE}
patch:
rm -rf ${SPEC_PATCHED_DIR}
cp -r ${SPEC_FETCHED_DIR} ${SPEC_PATCHED_DIR}
for diff in $(shell set -x; find ${SPEC_PATCH_DIR} -name '*.patch' | sort -n); do \
patch --no-backup-if-mismatch -N -t -p1 -i $$diff; \
done
patch-post:
# patch is idempotent, always starting with the generated files
for diff in $(shell find patches/post -name \*.patch | sort -n); do \
patch --no-backup-if-mismatch -N -t -p1 -i $$diff; \
done
clean:
rm -rf $(PACKAGE_PREFIX)
codegen:
${OPENAPI_GENERATOR} generate -g go \
--package-name ${PACKAGE_MAJOR} \
--http-user-agent "${GIT_REPO}/${PACKAGE_VERSION}" \
-p packageVersion=${PACKAGE_VERSION} \
--git-user-id ${GIT_ORG} \
--git-repo-id ${GIT_REPO}/${PACKAGE_PREFIX} \
-c /local/config/openapi-generator.json \
-o /local/${PACKAGE_PREFIX}/${PACKAGE_MAJOR} \
-i /local/${SPEC_PATCHED_DIR}/${SPEC_ROOT_FILE}
validate:
${OPENAPI_GENERATOR} validate \
--recommend \
-i /local/${SPEC_PATCHED_DIR}
mod:
rm -f go.mod go.sum ${PACKAGE_PREFIX}/${PACKAGE_MAJOR}/go.mod ${PACKAGE_PREFIX}/${PACKAGE_MAJOR}/go.sum
go mod init github.com/${GIT_ORG}/${GIT_REPO}
printf "// Deprecated: use github.com/equinix/equinix-sdk-go instead.\n%s" "$$(cat go.mod)" > go.mod
go mod tidy
test:
go test -v ./...
clean-docs:
rm -rf docs API.md
move-docs:
mv ${PACKAGE_PREFIX}/${PACKAGE_MAJOR}/README.md API.md
mv ${PACKAGE_PREFIX}/${PACKAGE_MAJOR}/docs .
docs: clean-docs move-docs
move-other:
rm -rf api .travis.yml git_push.sh
rm -f ${PACKAGE_PREFIX}/${PACKAGE_MAJOR}/.travis.yml
mv ${PACKAGE_PREFIX}/${PACKAGE_MAJOR}/api .
rm ${PACKAGE_PREFIX}/${PACKAGE_MAJOR}/git_push.sh
lint:
@$(GOLANGCI_LINT) run -v --no-config --fast=false --fix --disable-all --enable goimports $(PACKAGE_PREFIX)
fmt:
go run mvdan.cc/gofumpt@v0.3.1 -l -w $(PACKAGE_PREFIX)
stage:
test -d .git && git add --intent-to-add API.md docs ${PACKAGE_PREFIX} go.mod go.sum