Skip to content

Commit d6336ab

Browse files
authored
Merge pull request #78 from ByteInternet/package-hypernode-manpage
Package hypernode manpage
2 parents 02ce49c + e20baec commit d6336ab

File tree

10 files changed

+244
-0
lines changed

10 files changed

+244
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,48 @@ Then deploy to your local Hypernode Docker:
6666
docker run --rm -it --env SSH_PRIVATE_KEY="$(cat ~/.ssh/yourdeploykey | base64)" -v ${PWD}:/build quay.io/hypernode/deploy:latest hypernode-deploy build -vvv # First build the artifact
6767
docker run --rm -it --env SSH_PRIVATE_KEY="$(cat ~/.ssh/yourdeploykey | base64)" -v ${PWD}:/build quay.io/hypernode/deploy:latest hypernode-deploy deploy docker -vvv # Then perform the deploy
6868
```
69+
70+
## Building the manpage deb
71+
72+
The docs are also packaged as a debian package named `hndocsnext` so that on a Hypernode you can run `man hypernode` (or `hypernode-manual`) and page through a `manpage` version of the Hypernode docs. To build that debian package on a Debian machine you can run these commands:
73+
```
74+
# First create the cow environment
75+
export ARCH=amd64
76+
export DIST=buster
77+
apt-get install debhelper cowbuilder git-buildpackage
78+
cowbuilder --create --distribution buster --architecture amd64 --basepath /var/cache/pbuilder/base-$DIST-amd64.cow --mirror http://ftp.debian.org/debian/ --components=main
79+
80+
# We need to make sure our build process can use networking in order to pip install the requirements
81+
echo "USENETWORK=yes" > ~/.pbuilderrc
82+
83+
# Then clone the repository and build the .deb
84+
git clone https://github.com/ByteInternet/hypernode-docs-next
85+
cd hypernode-docs-next
86+
gbp buildpackage --git-pbuilder --git-dist=$DIST --git-arch=$ARCH --git-ignore-branch -us -uc -sa --git-ignore-new
87+
```
88+
89+
Then after building the Deb you could install it with dpkg. For example:
90+
```
91+
dpkg -i ../hndocsnext_20230121.173551_all.deb
92+
```
93+
94+
And test it out with:
95+
```
96+
man hypernode
97+
```
98+
99+
To inspect the contents of the deb archive you can run:
100+
```
101+
# dpkg -L hndocsnext
102+
/.
103+
/usr
104+
/usr/local
105+
/usr/local/man
106+
/usr/local/man/man3
107+
/usr/local/man/man3/hypernode.3
108+
/usr/share
109+
/usr/share/doc
110+
/usr/share/doc/hndocsnext
111+
/usr/share/doc/hndocsnext/README.md
112+
/usr/share/doc/hndocsnext/changelog.gz
113+
```

debian/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
hndocsnext (20230121.173551) UNRELEASED; urgency=medium
2+
3+
[ Rick van de Loo ]
4+
* Initial packaging
5+
6+
-- Rick van de Loo <vdloo@desktop> Sat, 21 Jan 2023 17:35:51 +0200

debian/compat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9

debian/control

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Source: hndocsnext
2+
Priority: optional
3+
Maintainer: Hypernode Tech Team <support@hypernode.com>
4+
Build-Depends: debhelper (>= 9), python3, python3-venv, python3-dev
5+
Standards-Version: 3.9.4
6+
Homepage: https://github.com/ByteInternet/hypernode-docs-next
7+
Vcs-Git: git@github.com:ByteInternet/hypernode-docs-next.git
8+
9+
Package: hndocsnext
10+
Section: doc
11+
Architecture: all
12+
Depends: ${misc:Depends}
13+
Description: Hypernode docs in manpage form. Run 'man hypernode'.

debian/docs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
README.md

debian/hndocsnext.install

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://www.debian.org/doc/manuals/maint-guide/dother.en.html#install
2+
3+
docs/_build/man/hypernode.3 /usr/local/man/man3/

debian/hndocsnext.postinst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
set -e
3+
mandb

debian/rules

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/make -f
2+
# -*- makefile -*-
3+
4+
# Uncomment this to turn on verbose mode.
5+
#export DH_VERBOSE=1
6+
.PHONY: build
7+
8+
build:
9+
python3 -m venv venv
10+
venv/bin/pip install -r requirements/development.txt
11+
bash -c 'source venv/bin/activate; bin/build_manpage'
12+
mv docs/_build/man/docs.1 docs/_build/man/hypernode.3
13+
14+
override_dh_usrlocal:
15+
16+
%:
17+
dh $@

debian/source/format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.0 (native)

mark-release.sh

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
#!/usr/bin/env bash
2+
3+
read -r -d '' USAGE << EOUSAGE
4+
Mark a release for project, ensure commits in master are in debian changelog.
5+
If there are changes to release, update version and debian changelog,
6+
also can tag and push the release.
7+
If all commits are in changelog, won't change anything.
8+
The last line of output indicates if a release is marked or not.
9+
usage: $0 [options]
10+
options:
11+
-a automated mode (commit, tag, push)
12+
-c commit the changes for marking the release
13+
-h show this help and exit
14+
-p git push HEAD and tags
15+
-t tag the commit
16+
-v verbose output
17+
environment:
18+
AUTHOR commit author (name <email>) format
19+
DEBFULLNAME changelog writer name
20+
DEBEMAIL changelog writer email
21+
MESSAGE commit message
22+
EOUSAGE
23+
24+
# ==== opts ====
25+
COMMIT=false
26+
PUSH=false
27+
TAG=false
28+
VERBOSE=false
29+
30+
while getopts 'achptv' flag; do
31+
case "$flag" in
32+
a)
33+
COMMIT=true
34+
TAG=true
35+
PUSH=true
36+
;;
37+
c)
38+
COMMIT=true
39+
;;
40+
h)
41+
echo "$USAGE"
42+
exit
43+
;;
44+
p)
45+
PUSH=true
46+
;;
47+
t)
48+
TAG=true
49+
;;
50+
v)
51+
VERBOSE=true
52+
;;
53+
esac
54+
done
55+
56+
57+
set -o errexit
58+
59+
ROOT_DIR=$(realpath $(dirname $0))
60+
CHANGELOG="$ROOT_DIR/debian/changelog"
61+
VERSION=$(date "+%Y%m%d.%H%M%S")
62+
LOG_USER="${SUDO_USER:-$USER}"
63+
64+
# === options from env ====
65+
66+
# committer info
67+
AUTHOR="${AUTHOR:-}"
68+
MESSAGE="${MESSAGE}"
69+
if [[ -z "$MESSAGE" ]]; then
70+
MESSAGE="[automated] Marking Release $VERSION"
71+
fi
72+
73+
# changelog writer info
74+
export DEBFULLNAME="${DEBFULLNAME:-Hypernode team}"
75+
export DEBEMAIL="${DEBMAIL:-hypernode@byte.nl}"
76+
77+
78+
log() {
79+
logger --tag 'hypernode-docs-next-mark-release' "[$$ @$LOG_USER] $1"
80+
if $VERBOSE; then
81+
echo "$1"
82+
fi
83+
}
84+
85+
# deb_changelog_updated: returns 0 if there are changes to be released or 1 otherwise
86+
deb_changelog_updated() {
87+
log "checking if debian changelog needs update"
88+
# use gbp dch itself to see if there are any changes detected.
89+
# this way the logic of detecting changes is more consistent with
90+
# the rest of the system.
91+
gbp dch --debian-tag="%(version)s" --debian-branch=master
92+
# find changelog diff to see if there new commits in changelog.
93+
# commits are usually added like this to the changelog:
94+
# [ author ]
95+
# * commit message
96+
# first look for commit messages, if nothing found, then see if there is an empty author section,
97+
# as a fallback.
98+
local changed=$(git diff --text --ignore-all-space --unified=0 --no-color $CHANGELOG | grep --line-regexp --perl-regexp '\+\s{2,}\* .+')
99+
if [[ -z "$changed" ]]; then
100+
changed=$(git diff --text --ignore-all-space --unified=0 --no-color $CHANGELOG | grep --line-regexp --perl-regexp '\+\\s{2,}\[.+\].*')
101+
fi
102+
log "reverting possible changes in debian changelog during update detection"
103+
git checkout -- $CHANGELOG
104+
if [[ -n "$changed" ]]; then
105+
return 0
106+
fi
107+
return 1
108+
}
109+
110+
mark_release() {
111+
log "marking release $VERSION ..."
112+
113+
log "generating debian changelog"
114+
gbp dch --debian-tag="%(version)s" --new-version=$VERSION --debian-branch=master
115+
git add $CHANGELOG
116+
}
117+
118+
commit() {
119+
log "comitting the release changes"
120+
if [[ -z "$AUTHOR" ]]; then
121+
git commit --no-edit --message="$MESSAGE"
122+
else
123+
git commit --no-edit --message="$MESSAGE" --author "$AUTHOR"
124+
fi
125+
}
126+
127+
128+
if ! deb_changelog_updated; then
129+
log "detected no change, skipping marking release!"
130+
echo 'no change'
131+
exit
132+
fi
133+
134+
mark_release
135+
136+
if $COMMIT; then
137+
commit
138+
if $TAG; then
139+
log "creating git tag '$VERSION' ..."
140+
git tag $VERSION
141+
fi
142+
143+
if $PUSH; then
144+
log "pushing changes to origin ..."
145+
git push origin HEAD
146+
if $TAG; then
147+
git push origin $VERSION
148+
fi
149+
fi
150+
else
151+
log "not committing, skipping tagging and pushing!"
152+
fi
153+
154+
echo "marked release $VERSION"

0 commit comments

Comments
 (0)