-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-api-docs.sh
executable file
·90 lines (73 loc) · 3.13 KB
/
gen-api-docs.sh
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
#!/bin/bash
# Copyright 2019 Google LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -ex
#Reinstall Go 1.15 since the version upon it won't work with gen-crd-api-reference-docs
rm -rf /usr/local/go
GO_VERSION=1.15.13
cd /usr/local
wget -q https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz && \
tar -xzf go${GO_VERSION}.linux-amd64.tar.gz && rm go${GO_VERSION}.linux-amd64.tar.gz
export GOPROXY=http://proxy.golang.org
echo "using go proxy as a workaround for git.agache.org being down: $GOPROXY"
cd /go/src/github.com/ahmetb/gen-crd-api-reference-docs
#Use local version of agones
go mod edit --replace=agones.dev/agones@latest=../../../agones.dev/agones/
go build
cp /go/src/agones.dev/agones/site/assets/templates/pkg.tpl ./template
FILE=${FILE:-/go/src/agones.dev/agones/site/content/en/docs/Reference/agones_crd_api_reference.html}
VERSION=${VERSION:-"0.9.0"}
# +++ Title section
TITLE="/tmp/title.html"
# Current ExpiryVersion
EXPIRY_DOC="/tmp/expiry.html"
# Previous Publish Version after release
PUBLISH_DOC="/tmp/publish.html"
# Output of the gen-crd-api-reference-docs
RESULT="/tmp/agones_crd_api_reference.html"
# Version to compare
OLD="/tmp/old_docs.html"
./gen-crd-api-reference-docs --config ../../../agones.dev/agones/site/assets/templates/crd-doc-config.json --api-dir ../../../agones.dev/agones/pkg/apis/ --out-file $RESULT
awk '/\ feature\ publishVersion/{flag=1;next}/\ \/feature/{flag=0}flag' $FILE > $OLD
# Get the title lines from +++ till empty string
awk '/\+\+\+/ {ok=1} /^$/ {ok=0} {if(ok){print $0}}' $FILE > $TITLE
printf "\n" >> $TITLE
doc_version=$(grep 'feature publishVersion=' $FILE )
echo $doc_version
publish='{{% feature publishVersion="'$VERSION'" %}}'
expiry='{{% feature expiryVersion="'$VERSION'" %}}'
#Get previous expiry version tag
sed '/\ expiryVersion="'$VERSION'"/,/%\ \/feature/!d;/%\ \/feature/q' $FILE > $EXPIRY_DOC
sed '/\ publishVersion=/,/%\ \/feature/!d;/%\ \/feature/q' $FILE > $PUBLISH_DOC
function sedeasy {
sed -i "s/$(echo $1 | sed -e 's/\([[\/.*]\|\]\)/\\&/g')/$(echo $2 | sed -e 's/[\/&]/\\&/g')/g" $3
}
# do we have changes in generated API docs compared to previous version
if ! diff <(sort $RESULT) <(sort $OLD);
then
echo "Output to a file $FILE"
if [ "$publish" != "$doc_version" ]
then
echo "Tagging old publishVersion section with expiryVersion shortcode"
sedeasy "$doc_version" "$expiry" $PUBLISH_DOC
cat $PUBLISH_DOC >> $TITLE
else
echo "expiry version left unchanged"
cat $EXPIRY_DOC >> $TITLE
fi
cat $TITLE > $FILE
echo -e '{{% feature publishVersion="'$VERSION'" %}}' >> $FILE
cat $RESULT >> $FILE
echo -e '{{% /feature %}}\n' >> $FILE
fi