Skip to content

Commit b611c17

Browse files
oktalzmjuraga
authored andcommitted
BUG/MINOR: allow generating server from local version of client-native
1 parent 2deff72 commit b611c17

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ This document is a short guide for contributing to this project.
99
Data Plane API is generated using [go-swagger](https://github.com/go-swagger/go-swagger) from the swagger spec found [here](https://github.com/haproxytech/client-native/blob/master/specification/build/haproxy_spec.yaml) using the following command.
1010

1111
```
12-
make swagger
12+
make generate
1313
```
1414
or if you prefer to run it directly (not in docker)
1515
```
16-
make swagger-native
16+
make generate-native
1717
```
1818

19+
`make generate-native` must also be used if you are using local client-native on disk (you have `replace github.com/haproxytech/client-native/v2 => ../client-native` in go.mod file)
20+
1921
This command generates some of the files in this project, which are marked with // Code generated by go-swagger; DO NOT EDIT.
2022
comments at the top of the files. These are not to be edited, as they are overwritten when specification is changed and the above-mentioned command is run. If you want to change those files, please change the specification where necessary and then generate them again.
2123

generate/swagger/script.sh

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ DST_DIR=$(mktemp -d)
77
echo " ---> generate folder: $DST_DIR"
88
# see if we have a replace directive
99
CN_VERSION=$(go mod edit -json | jq -c -r '.Replace | .[] | select(.Old.Path | contains("github.com/haproxytech/client-native/v2")) | .New.Version' 2>/dev/null | awk -F"-" '{print $NF}') || ""
10+
REMOTE_VERSION=$(go mod edit -json | jq -c -r '.Replace | .[] | select(.Old.Path | contains("github.com/haproxytech/client-native/v2")) | .New.Version' 2>/dev/null | awk -F"/" '{print $1}') || ""
11+
if [ "$REMOTE_VERSION" = "null" ]; then
12+
# we have a local version of CN
13+
CN_VERSION=$(go mod edit -json | jq -c -r '.Replace | .[] | select(.Old.Path | contains("github.com/haproxytech/client-native/v2")) | .New.Path' 2>/dev/null) || ""
14+
fi
1015
# if hash is to short take all of it (example v1.0.0-dev1)
1116
[ "${#CN_VERSION}" -gt 0 ] && [ "${#CN_VERSION}" -lt 4 ] && CN_VERSION=$(go mod edit -json | jq -c -r '.Replace | .[] | select(.Old.Path | contains("github.com/haproxytech/client-native/v2")) | .New.Version')
12-
# check if version is ther, if not, use one from require
17+
# check if version is there, if not, use one from require
1318
[ -z "$CN_VERSION" ] && CN_VERSION=$(go mod edit -json | jq -c -r '.Require | .[] | select(.Path | contains("github.com/haproxytech/client-native/v2")) | .Version' 2>/dev/null | awk -F"-" '{print $NF}')
1419
echo " ---> version of client native used: $CN_VERSION"
1520

@@ -26,13 +31,23 @@ else
2631
URL_PATH=raw.githubusercontent.com
2732
fi
2833

29-
echo " ---> URL path: $URL_PATH"
30-
echo " ---> repository path: $REPO_PATH"
31-
SPEC_URL=https://$URL_PATH/$REPO_PATH/$EXTRA_PATH$CN_VERSION/specification
32-
echo " ---> fetching specification: $SPEC_URL/build/haproxy_spec.yaml"
33-
wget -q -O $SPEC_DIR/haproxy_spec.yaml $SPEC_URL/build/haproxy_spec.yaml
34-
echo " ---> fetching copyright: $SPEC_URL/copyright.txt"
35-
wget -q -O $SPEC_DIR/copyright.txt $SPEC_URL/copyright.txt
34+
if [ "$REMOTE_VERSION" = "null" ]; then
35+
SPEC_URL=$(readlink -f $CN_VERSION/specification)
36+
echo " ---> using local version of specification: $SPEC_URL"
37+
echo " ---> copy specification to: $SPEC_DIR/haproxy_spec.yaml"
38+
cp $SPEC_URL/build/haproxy_spec.yaml $SPEC_DIR/haproxy_spec.yaml
39+
echo " ---> copy copyright to : $SPEC_DIR/copyright.txt"
40+
cp $SPEC_URL/copyright.txt $SPEC_DIR/copyright.txt
41+
else
42+
echo " ---> URL path: $URL_PATH"
43+
echo " ---> repository path: $REPO_PATH"
44+
SPEC_URL=https://$URL_PATH/$REPO_PATH/$EXTRA_PATH$CN_VERSION/specification
45+
46+
echo " ---> fetching specification: $SPEC_URL/build/haproxy_spec.yaml"
47+
wget -q -O $SPEC_DIR/haproxy_spec.yaml $SPEC_URL/build/haproxy_spec.yaml
48+
echo " ---> fetching copyright: $SPEC_URL/copyright.txt"
49+
wget -q -O $SPEC_DIR/copyright.txt $SPEC_URL/copyright.txt
50+
fi
3651

3752
echo "module github.com/haproxytech" > $DST_DIR/go.mod
3853
mkdir -p $DST_DIR/dataplaneapi/operations

0 commit comments

Comments
 (0)