Skip to content

Commit 128468c

Browse files
committed
Makefile: add 'doc' target, include docs in install
Add a 'doc' target and 'make-docs.sh' script to build the Asciidoc documents in 'docs/man' into installable manpages. Include these documents (and associated symlinks) in installations from source and from platform-specific packages. Additionally, update 'release.yml' to install 'asciidoctor' so that the documentation can successfully be built in that workflow. Signed-off-by: Victoria Dye <[email protected]>
1 parent 5d3a8c9 commit 128468c

File tree

6 files changed

+112
-3
lines changed

6 files changed

+112
-3
lines changed

.github/workflows/release.yml

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ jobs:
4747
uses: actions/setup-go@v3
4848
with:
4949
go-version: '1.19.0'
50+
- uses: ruby/setup-ruby@v1
51+
with:
52+
ruby-version: '3.2.1'
53+
- run: gem install asciidoctor
5054
- name: Clone repository
5155
uses: actions/checkout@v3
5256
- name: Build the release artifact

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/git-bundle-web-server
33
/bin/
44
/_dist/
5+
/_docs/

Makefile

+13-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ INSTALL_ROOT := /
1212
# Helpful paths
1313
BINDIR := $(CURDIR)/bin
1414
DISTDIR := $(CURDIR)/_dist
15+
DOCDIR := $(CURDIR)/_docs
1516

1617
# Platform information
1718
GOOS := $(shell go env GOOS)
@@ -28,12 +29,18 @@ build:
2829
@mkdir -p $(BINDIR)
2930
GOOS="$(GOOS)" GOARCH="$(GOARCH)" go build -o $(BINDIR) ./...
3031

32+
.PHONY: doc
33+
doc:
34+
@scripts/make-docs.sh --docs="$(CURDIR)/docs/man" \
35+
--output="$(DOCDIR)"
36+
3137
# Installation targets
3238
.PHONY: install
33-
install: build
39+
install: build doc
3440
@echo
3541
@echo "======== Installing to $(INSTALL_ROOT) ========"
3642
@scripts/install.sh --bindir="$(BINDIR)" \
43+
--docdir="$(DOCDIR)" \
3744
--uninstaller="$(CURDIR)/scripts/uninstall.sh" \
3845
--allow-root \
3946
--include-symlinks \
@@ -63,10 +70,11 @@ DEBDIR := $(DISTDIR)/deb
6370
DEB_FILENAME := $(DISTDIR)/$(NAME)_$(VERSION)-$(PACKAGE_REVISION)_$(PACKAGE_ARCH).deb
6471

6572
# Targets
66-
$(DEBDIR)/root: check-arch build
73+
$(DEBDIR)/root: check-arch build doc
6774
@echo
6875
@echo "======== Formatting package contents ========"
6976
@scripts/install.sh --bindir="$(BINDIR)" \
77+
--docdir="$(DOCDIR)" \
7078
--include-symlinks \
7179
--install-root="$(DEBDIR)/root"
7280

@@ -94,10 +102,11 @@ PKGDIR := $(DISTDIR)/pkg
94102
PKG_FILENAME := $(DISTDIR)/$(NAME)_$(VERSION)-$(PACKAGE_REVISION)_$(PACKAGE_ARCH).pkg
95103

96104
# Targets
97-
$(PKGDIR)/payload: check-arch build
105+
$(PKGDIR)/payload: check-arch build doc
98106
@echo
99107
@echo "======== Formatting package contents ========"
100108
@scripts/install.sh --bindir="$(BINDIR)" \
109+
--docdir="$(DOCDIR)" \
101110
--uninstaller="$(CURDIR)/scripts/uninstall.sh" \
102111
--install-root="$(PKGDIR)/payload"
103112

@@ -125,3 +134,4 @@ clean:
125134
go clean ./...
126135
$(RM) -r $(BINDIR)
127136
$(RM) -r $(DISTDIR)
137+
$(RM) -r $(DOCDIR)

build/package/pkg/scripts/postinstall

+15
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,19 @@ do
1818
ln -s "$RELATIVE_LINK_TO_BIN/$p" "$LINK_TO/$p"
1919
done
2020

21+
for mandir in "$APP_ROOT"/share/man/man*/
22+
do
23+
mdir=$(basename "$mandir")
24+
LINK_TO="$INSTALL_DESTINATION/usr/local/share/man/$mdir"
25+
RELATIVE_LINK_TO_MAN="../../../git-bundle-server/share/man/$mdir"
26+
mkdir -p "$LINK_TO"
27+
28+
for manpage in "$mandir"/*
29+
do
30+
mpage=$(basename "$manpage")
31+
rm -f "$LINK_TO/$mpage"
32+
ln -s "$RELATIVE_LINK_TO_MAN/$mpage" "$LINK_TO/$mpage"
33+
done
34+
done
35+
2136
exit 0

scripts/install.sh

+31
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ case "$i" in
2525
BINDIR="${i#*=}"
2626
shift # past argument=value
2727
;;
28+
--docdir=*)
29+
DOCDIR="${i#*=}"
30+
shift # past argument=value
31+
;;
2832
--uninstaller=*)
2933
UNINSTALLER="${i#*=}"
3034
shift # past argument=value
@@ -51,6 +55,9 @@ done
5155
if [ -z "$BINDIR" ]; then
5256
die "--bindir was not set"
5357
fi
58+
if [ -z "$DOCDIR" ]; then
59+
die "--docdir was not set"
60+
fi
5461
if [ -z "$INSTALL_ROOT" ]; then
5562
die "--install-root was not set"
5663
fi
@@ -71,6 +78,14 @@ retry_root mkdir -p "$APP_ROOT"
7178
echo "Copying binaries..."
7279
retry_root cp -R "$BINDIR/." "$APP_ROOT/bin"
7380

81+
echo "Copying manpages..."
82+
for N in $(find "$DOCDIR" -type f | sed -e 's/.*\.//' | sort -u)
83+
do
84+
retry_root mkdir -p "$APP_ROOT/share/man/man$N"
85+
retry_root cp -R "$DOCDIR/"*."$N" "$APP_ROOT/share/man/man$N"
86+
87+
done
88+
7489
# Copy uninstaller script
7590
if [ -n "$UNINSTALLER" ]; then
7691
echo "Copying uninstall script..."
@@ -90,4 +105,20 @@ if [ -n "$INCLUDE_SYMLINKS" ]; then
90105
retry_root rm -f "$LINK_TO/$p"
91106
retry_root ln -s "$RELATIVE_LINK_TO_BIN/$p" "$LINK_TO/$p"
92107
done
108+
109+
echo "Creating manpage symlinks..."
110+
for mandir in "$APP_ROOT"/share/man/man*/
111+
do
112+
mdir=$(basename "$mandir")
113+
LINK_TO="$INSTALL_ROOT/usr/local/share/man/$mdir"
114+
RELATIVE_LINK_TO_MAN="../../../git-bundle-server/share/man/$mdir"
115+
retry_root mkdir -p "$LINK_TO"
116+
117+
for manpage in "$mandir"/*
118+
do
119+
mpage=$(basename "$manpage")
120+
retry_root rm -f "$LINK_TO/$mpage"
121+
retry_root ln -s "$RELATIVE_LINK_TO_MAN/$mpage" "$LINK_TO/$mpage"
122+
done
123+
done
93124
fi

scripts/make-docs.sh

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
die () {
3+
echo "$*" >&2
4+
exit 1
5+
}
6+
7+
THISDIR="$( cd "$(dirname "$0")" ; pwd -P )"
8+
9+
# Parse script arguments
10+
for i in "$@"
11+
do
12+
case "$i" in
13+
--docs=*)
14+
MAN_DIR="${i#*=}"
15+
shift # past argument=value
16+
;;
17+
--output=*)
18+
OUT_DIR="${i#*=}"
19+
shift # past argument=value
20+
;;
21+
*)
22+
die "unknown option '$i'"
23+
;;
24+
esac
25+
done
26+
27+
# Perform pre-execution checks
28+
if [ -z "$MAN_DIR" ]; then
29+
die "--docs was not set"
30+
fi
31+
32+
if [ -z "$OUT_DIR" ]; then
33+
die "--output was not set"
34+
fi
35+
36+
set -e
37+
38+
if ! command -v asciidoctor >/dev/null 2>&1
39+
then
40+
die "cannot generate man pages: asciidoctor not installed. \
41+
See https://docs.asciidoctor.org/asciidoctor/latest/install for \
42+
installation instructions."
43+
fi
44+
45+
# Generate the man pages
46+
mkdir -p "$OUT_DIR"
47+
48+
asciidoctor -b manpage -I "$THISDIR" -r asciidoctor-extensions.rb -D "$OUT_DIR" "$MAN_DIR/*.adoc"

0 commit comments

Comments
 (0)