Skip to content

Commit e21b85e

Browse files
authored
add doc2go (#13)
* build script: CLI arg `--generate-code-documentation` * README: document doc2go
1 parent fceed9f commit e21b85e

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ RUN apt update && apt install -y zip \
3131
| tar --strip-components=1 -C /usr/local/bin -xzf - --wildcards 'golangci-lint-*-linux-amd64/golangci-lint' \
3232
&& rm -rf /go/pkg \
3333
&& mkdir /tmp/protoc && cd /tmp/protoc \
34+
&& curl --fail --location https://github.com/abhinav/doc2go/releases/download/v0.8.1/doc2go-linux-amd64.tar.gz | tar -C /usr/local/bin/ -xzf - doc2go \
3435
&& ln -s /usr/bin/build-go-project.sh /build-common.sh \
3536
&& git config --global --add safe.directory /workspace \
3637
&& true

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Features
3737
- [Protobuf](https://developers.google.com/protocol-buffers) compiler included
3838
- [Deployer](https://github.com/function61/deployer) integration
3939
* For packaging `deployerspec.zip` files
40+
- [doc2go](https://github.com/abhinav/doc2go/) for generating documentation (use case: private documentation). See [why godoc isn't enough](https://github.com/golang/go/issues/2381).
4041

4142
Standardized build process:
4243

build-go-project.sh

+18-1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ standardBuildProcess() {
174174

175175
buildstep packageLambdaFunction
176176

177+
buildstep generateCodeDocs
178+
177179
if [ ! -z ${GOFMT_TARGETS+x} ]; then
178180
echo "ERROR: GOFMT_TARGETS is deprecated"
179181
exit 1
@@ -197,6 +199,16 @@ function packageLambdaFunction {
197199
)
198200
}
199201

202+
# uses doc2go to (auto)generate documentation for Go code.
203+
# https://abhinav.github.io/doc2go/
204+
# use case: private projects for which https://pkg.go.dev/ docs aren't accessible.
205+
function generateCodeDocs {
206+
local docsTempDir="/tmp/docsite"
207+
rm -rf "$docsTempDir"
208+
doc2go -out "$docsTempDir" ./...
209+
tar -C "$docsTempDir" . -czf rel/code-documentation.tar.gz
210+
}
211+
200212
# not being sourced?
201213
#
202214
# when we don't go into the if, we're in backwards compatiblity mode. this script used to be sourced,
@@ -207,9 +219,10 @@ function packageLambdaFunction {
207219
# so the new style is to just invoke this script with args.
208220
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
209221
SKIP_PACKAGELAMBDAFUNCTION=y
222+
SKIP_GENERATECODEDOCS=y
210223

211224
# we don't use short options but "-o" needs to be set, otherwise it mysteriously just doesn't work...
212-
options=$(getopt -l "directory:,binary-basename:,aws-lambda-zip" -o "" -a -- "$@")
225+
options=$(getopt -l "directory:,binary-basename:,aws-lambda-zip,generate-code-documentation" -o "" -a -- "$@")
213226

214227
eval set -- "$options"
215228

@@ -227,6 +240,9 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
227240
--aws-lambda-zip)
228241
unset SKIP_PACKAGELAMBDAFUNCTION
229242
;;
243+
--generate-code-documentation)
244+
unset SKIP_GENERATECODEDOCS
245+
;;
230246
--)
231247
shift
232248
break;;
@@ -247,6 +263,7 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
247263
SKIP_CODEGENERATION=y
248264
SKIP_STATICANALYSIS=y
249265
SKIP_TESTS=y
266+
SKIP_GENERATECODEDOCS=y
250267
fi
251268

252269
standardBuildProcess

0 commit comments

Comments
 (0)