Skip to content

Commit 90f0064

Browse files
committed
Add zip_docs
rsync-antora-reference now creates a zip file that includes all the documentation at the location of `${httpdocs-path}/${github-repository-name}-docs.zip`. The value of `${github-repository-name}` is the name portion of the GitHub repository in the form of `${owner}/${name}`. Closes gh-33
1 parent 73b78a9 commit 90f0064

File tree

6 files changed

+188
-2
lines changed

6 files changed

+188
-2
lines changed

Diff for: README.adoc

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Example usage:
3939
A GitHub action that syncs Antora reference documentation using rsync with support for syncing a single version.
4040
It deploys to the docs server using the GitHub repository in the path.
4141

42+
It also creates a zip file that includes all the documentation at the location of `${httpdocs-path}/${github-repository-name}-docs.zip`.
43+
The value of `${github-repository-name}` is the name portion of the GitHub repository in the form of `${owner}/${name}`.
4244

4345
[source,yml]
4446
----

Diff for: rsync-antora-reference/src/action.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ __action() {
110110
set -f
111111

112112
local ssh_host_path="/opt/www/domains/spring.io/docs/htdocs/$github_repository_name/reference/"
113+
local pwd="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
113114
setup_ssh.sh --ssh-private-key-path "$ssh_private_key_path" --ssh-private-key "$docs_ssh_key" --ssh-known-host "$docs_ssh_host_key"
114115
if [ ! -z "$httpdocs_path" ]; then
115116
ssh_host_path="/opt/www/domains/spring.io/docs/htdocs${httpdocs_path}/"
116-
local pwd="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
117117
ssh -i "$ssh_private_key_path" "$ssh_host" 'bash -s' < "$pwd/check_github_repository_owner.sh" -- --github-repository "\"$github_repository\"" --ssh-docs-path "\"$ssh_host_path\""
118118
fi
119119
rsync_docs.sh --ssh-host "$ssh_host" --ssh-host-path "$ssh_host_path" --local-path "$site_path" --ssh-private-key-path "$ssh_private_key_path" $rsync_flag_options
120+
ssh -i "$ssh_private_key_path" "$ssh_host" 'bash -s' < "$pwd/zip_docs.sh" -- --zip-name "\"$github_repository_name-docs.zip\"" --ssh-docs-path "\"$ssh_host_path\""
120121
)
121122
exit_code=$?
122123

Diff for: rsync-antora-reference/src/zip_docs.sh

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
3+
__zip_docs_usage() {
4+
echo "usage: zip_docs.sh [OPTION]...
5+
6+
--zip-name=NAME the name of the zip file to be created
7+
--ssh-docs-path=PATH the full path that the docs that should be included in the zip file (e.g. https://docs.spring.io/spring-security/reference/ is \${HTTP_DOCS}/spring-security/reference)
8+
"
9+
}
10+
11+
__zip_docs_usage_error() {
12+
echo "Error: $1" >&2
13+
__zip_docs_usage
14+
exit 1
15+
}
16+
17+
__zip_docs() {
18+
local zip_name ssh_docs_path valid_args
19+
valid_args=$(getopt --options '' --long ,zip-name:,ssh-docs-path: -- "$@")
20+
if [[ $? -ne 0 ]]; then
21+
__zip_docs_usage
22+
exit 1;
23+
fi
24+
25+
eval set -- "$valid_args"
26+
27+
while [ : ]; do
28+
case "$1" in
29+
--zip-name)
30+
zip_name="$2"
31+
shift 2
32+
;;
33+
--ssh-docs-path)
34+
ssh_docs_path="$2"
35+
shift 2
36+
;;
37+
--) shift;
38+
break
39+
;;
40+
*)
41+
__zip_docs_usage_error "Invalid argument $1 $2"
42+
;;
43+
esac
44+
done
45+
46+
if ! [[ "$zip_name" =~ .+\.zip ]]; then
47+
__zip_docs_usage_error " '--zip-name' must end with .zip but got '$zip_name'"
48+
fi
49+
if ! [[ "$ssh_docs_path" =~ ^/.+ ]]; then
50+
__zip_docs_usage_error " '--ssh-docs-path' must start with / but got '$ssh_docs_path'"
51+
fi
52+
53+
if [ -d "$ssh_docs_path" ]; then
54+
# The path exists
55+
cd "$ssh_docs_path"
56+
echo "Zipping content in '$ssh_docs_path' to '$zip_name'"
57+
zip -r "$zip_name" . *
58+
cd -
59+
else
60+
# The path does not exist so fail
61+
echo "Error: Directory --ssh-docs-path '$ssh_docs_path' cannot be zipped because it does not exist"
62+
exit 1
63+
fi
64+
65+
}
66+
67+
__zip_docs "$@"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Ensure the directory is in git

Diff for: rsync-antora-reference/test/test-action.bats

+33-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ usage: action.sh [OPTION]...
6666
@test "docs-ssh-key with space" {
6767
stub setup_ssh.sh "$(capture_program_args "setup_ssh")"
6868
stub rsync_docs.sh "$(capture_program_args "rsync_docs")"
69+
stub ssh "$(capture_program "ssh")"
6970
stub cleanup_ssh.sh "$(capture_program_args "cleanup_ssh")"
7071

7172
run action.sh --docs-username USER --docs-host HOST --docs-ssh-key 'SSH KEY' --docs-ssh-host-key HOST_KEY --site-path SITE_PATH --github-repository spring-projects/spring-security
@@ -74,10 +75,13 @@ usage: action.sh [OPTION]...
7475
assert_output "" # No warnings due to spaces
7576
assert_program_args "setup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --ssh-private-key SSH KEY --ssh-known-host HOST_KEY"
7677
assert_program_args "rsync_docs" "--ssh-host USER@HOST --ssh-host-path /opt/www/domains/spring.io/docs/htdocs/spring-security/reference/ --local-path SITE_PATH --ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
78+
assert_program_args "ssh" "-i $HOME/.ssh/spring-projects/spring-security USER@HOST bash -s -- --zip-name \"spring-security-docs.zip\" --ssh-docs-path \"/opt/www/domains/spring.io/docs/htdocs/spring-security/reference/\""
79+
assert_regex "$(get_program_stdin 'ssh')" 'zip_docs'
7780
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
7881

7982
unstub --allow-missing setup_ssh.sh
8083
unstub rsync_docs.sh
84+
unstub ssh
8185
unstub cleanup_ssh.sh
8286
}
8387

@@ -91,6 +95,7 @@ usage: action.sh [OPTION]...
9195
@test "docs-ssh-host-key with space" {
9296
stub setup_ssh.sh "$(capture_program_args "setup_ssh")"
9397
stub rsync_docs.sh "$(capture_program_args "rsync_docs")"
98+
stub ssh "$(capture_program "ssh")"
9499
stub cleanup_ssh.sh "$(capture_program_args "cleanup_ssh")"
95100

96101
run action.sh --docs-username USER --docs-host HOST --docs-ssh-key 'SSH_KEY' --docs-ssh-host-key 'HOST KEY' --site-path SITE_PATH --github-repository spring-projects/spring-security
@@ -99,10 +104,13 @@ usage: action.sh [OPTION]...
99104
assert_output "" # No warnings due to spaces
100105
assert_program_args "setup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --ssh-private-key SSH_KEY --ssh-known-host HOST KEY"
101106
assert_program_args "rsync_docs" "--ssh-host USER@HOST --ssh-host-path /opt/www/domains/spring.io/docs/htdocs/spring-security/reference/ --local-path SITE_PATH --ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
107+
assert_program_args "ssh" "-i $HOME/.ssh/spring-projects/spring-security USER@HOST bash -s -- --zip-name \"spring-security-docs.zip\" --ssh-docs-path \"/opt/www/domains/spring.io/docs/htdocs/spring-security/reference/\""
108+
assert_regex "$(get_program_stdin 'ssh')" 'zip_docs'
102109
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
103110

104111
unstub --allow-missing setup_ssh.sh
105112
unstub rsync_docs.sh
113+
unstub ssh
106114
unstub cleanup_ssh.sh
107115
}
108116

@@ -116,74 +124,92 @@ usage: action.sh [OPTION]...
116124
@test "valid arguments" {
117125
stub setup_ssh.sh "$(capture_program_args "setup_ssh")"
118126
stub rsync_docs.sh "$(capture_program_args "rsync_docs")"
127+
stub ssh "$(capture_program "ssh")"
119128
stub cleanup_ssh.sh "$(capture_program_args "cleanup_ssh")"
120129

121130
run action.sh --docs-username USER --docs-host HOST --docs-ssh-key KEY --docs-ssh-host-key HOST_KEY --site-path SITE_PATH --github-repository spring-projects/spring-security
122131

123132
assert_success
124133
assert_program_args "setup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --ssh-private-key KEY --ssh-known-host HOST_KEY"
125134
assert_program_args "rsync_docs" "--ssh-host USER@HOST --ssh-host-path /opt/www/domains/spring.io/docs/htdocs/spring-security/reference/ --local-path SITE_PATH --ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
135+
assert_program_args "ssh" "-i $HOME/.ssh/spring-projects/spring-security USER@HOST bash -s -- --zip-name \"spring-security-docs.zip\" --ssh-docs-path \"/opt/www/domains/spring.io/docs/htdocs/spring-security/reference/\""
136+
assert_regex "$(get_program_stdin 'ssh')" 'zip_docs'
126137
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
127138

128139
unstub --allow-missing setup_ssh.sh
129140
unstub rsync_docs.sh
141+
unstub ssh
130142
unstub cleanup_ssh.sh
131143
}
132144

133145
@test "missing site-path defaults build/site" {
134146
stub setup_ssh.sh "$(capture_program_args "setup_ssh")"
135147
stub rsync_docs.sh "$(capture_program_args "rsync_docs")"
148+
stub ssh "$(capture_program "ssh")"
136149
stub cleanup_ssh.sh "$(capture_program_args "cleanup_ssh")"
137150

138151
run action.sh --docs-username USER --docs-host HOST --docs-ssh-key KEY --docs-ssh-host-key HOST_KEY --github-repository spring-projects/spring-security
139152

140153
assert_success
141154
assert_program_args "setup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --ssh-private-key KEY --ssh-known-host HOST_KEY"
142155
assert_program_args "rsync_docs" "--ssh-host USER@HOST --ssh-host-path /opt/www/domains/spring.io/docs/htdocs/spring-security/reference/ --local-path build/site --ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
156+
assert_program_args "ssh" "-i $HOME/.ssh/spring-projects/spring-security USER@HOST bash -s -- --zip-name \"spring-security-docs.zip\" --ssh-docs-path \"/opt/www/domains/spring.io/docs/htdocs/spring-security/reference/\""
157+
assert_regex "$(get_program_stdin 'ssh')" 'zip_docs'
143158
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
159+
144160
unstub --allow-missing setup_ssh.sh
145161
unstub rsync_docs.sh
162+
unstub ssh
146163
unstub cleanup_ssh.sh
147164
}
148165

149166
# had a bug using -e instead of -z
150167
@test "site-path where path exists does not default build/site" {
151168
stub setup_ssh.sh "$(capture_program_args "setup_ssh")"
152169
stub rsync_docs.sh "$(capture_program_args "rsync_docs")"
170+
stub ssh "$(capture_program "ssh")"
153171
stub cleanup_ssh.sh "$(capture_program_args "cleanup_ssh")"
154172

155173
run action.sh --docs-username USER --docs-host HOST --site-path "$BATS_TEMP_DIR" --docs-ssh-key KEY --docs-ssh-host-key HOST_KEY --github-repository spring-projects/spring-security
156174

157175
assert_success
158176
assert_program_args "setup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --ssh-private-key KEY --ssh-known-host HOST_KEY"
159177
assert_program_args "rsync_docs" "--ssh-host USER@HOST --ssh-host-path /opt/www/domains/spring.io/docs/htdocs/spring-security/reference/ --local-path $BATS_TEMP_DIR --ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
178+
assert_program_args "ssh" "-i $HOME/.ssh/spring-projects/spring-security USER@HOST bash -s -- --zip-name \"spring-security-docs.zip\" --ssh-docs-path \"/opt/www/domains/spring.io/docs/htdocs/spring-security/reference/\""
179+
assert_regex "$(get_program_stdin 'ssh')" 'zip_docs'
160180
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
161181

162182
unstub --allow-missing setup_ssh.sh
163183
unstub rsync_docs.sh
184+
unstub ssh
164185
unstub cleanup_ssh.sh
165186
}
166187

167188
@test "dry-run=true" {
168189
stub setup_ssh.sh "$(capture_program_args "setup_ssh")"
169190
stub rsync_docs.sh "$(capture_program_args "rsync_docs")"
191+
stub ssh "$(capture_program "ssh")"
170192
stub cleanup_ssh.sh "$(capture_program_args "cleanup_ssh")"
171193

172194
run action.sh --docs-username USER --docs-host HOST --docs-ssh-key KEY --docs-ssh-host-key HOST_KEY --site-path SITE_PATH --github-repository spring-projects/spring-security --dry-run
173195

174196
assert_success
175197
assert_program_args "setup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --ssh-private-key KEY --ssh-known-host HOST_KEY"
176198
assert_program_args "rsync_docs" "--ssh-host USER@HOST --ssh-host-path /opt/www/domains/spring.io/docs/htdocs/spring-security/reference/ --local-path SITE_PATH --ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --dry-run"
199+
assert_program_args "ssh" "-i $HOME/.ssh/spring-projects/spring-security USER@HOST bash -s -- --zip-name \"spring-security-docs.zip\" --ssh-docs-path \"/opt/www/domains/spring.io/docs/htdocs/spring-security/reference/\""
200+
assert_regex "$(get_program_stdin 'ssh')" 'zip_docs'
177201
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
178202

179203
unstub --allow-missing setup_ssh.sh
180204
unstub rsync_docs.sh
205+
unstub ssh
181206
unstub cleanup_ssh.sh
182207
}
183208

184209
@test "BUILD_REFNAME set" {
185210
stub setup_ssh.sh "$(capture_program_args "setup_ssh")"
186211
stub rsync_docs.sh "$(capture_program_args "rsync_docs")"
212+
stub ssh "$(capture_program "ssh")"
187213
stub cleanup_ssh.sh "$(capture_program_args "cleanup_ssh")"
188214

189215
export BUILD_REFNAME=6.1.x
@@ -193,25 +219,31 @@ usage: action.sh [OPTION]...
193219
assert_success
194220
assert_program_args "setup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --ssh-private-key KEY --ssh-known-host HOST_KEY"
195221
assert_program_args "rsync_docs" "--ssh-host USER@HOST --ssh-host-path /opt/www/domains/spring.io/docs/htdocs/spring-security/reference/ --local-path SITE_PATH --ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --build-ref-name 6.1.x --dry-run"
222+
assert_program_args "ssh" "-i $HOME/.ssh/spring-projects/spring-security USER@HOST bash -s -- --zip-name \"spring-security-docs.zip\" --ssh-docs-path \"/opt/www/domains/spring.io/docs/htdocs/spring-security/reference/\""
223+
assert_regex "$(get_program_stdin 'ssh')" 'zip_docs'
196224
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
197225

198226
unstub --allow-missing setup_ssh.sh
199227
unstub rsync_docs.sh
228+
unstub ssh
200229
unstub cleanup_ssh.sh
201230
}
202231

203232
@test "httpdocs-path check httpdocs-path success" {
204233
stub setup_ssh.sh "$(capture_program_args "setup_ssh")"
205234
stub ssh "$(capture_program "ssh")"
206235
stub rsync_docs.sh "$(capture_program_args "rsync_docs")"
236+
stub ssh "$(capture_program "ssh")"
207237
stub cleanup_ssh.sh "$(capture_program_args "cleanup_ssh")"
208238

209239
run action.sh --docs-username USER --docs-host HOST --docs-ssh-key KEY --docs-ssh-host-key HOST_KEY --site-path SITE_PATH --github-repository spring-projects/spring-security --httpdocs-path /security/reference
210240

211241
assert_success
212242
assert_program_args "setup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --ssh-private-key KEY --ssh-known-host HOST_KEY"
213-
assert_program_args "ssh" "-i $HOME/.ssh/spring-projects/spring-security USER@HOST bash -s -- --github-repository \"spring-projects/spring-security\" --ssh-docs-path \"/opt/www/domains/spring.io/docs/htdocs/security/reference/\""
243+
assert_program_args "ssh" "-i $HOME/.ssh/spring-projects/spring-security USER@HOST bash -s -- --github-repository \"spring-projects/spring-security\" --ssh-docs-path \"/opt/www/domains/spring.io/docs/htdocs/security/reference/\"
244+
-i $HOME/.ssh/spring-projects/spring-security USER@HOST bash -s -- --zip-name \"spring-security-docs.zip\" --ssh-docs-path \"/opt/www/domains/spring.io/docs/htdocs/security/reference/\""
214245
assert_regex "$(get_program_stdin 'ssh')" 'check_github_repository_owner'
246+
assert_regex "$(get_program_stdin 'ssh')" 'zip_docs'
215247
assert_program_args "rsync_docs" "--ssh-host USER@HOST --ssh-host-path /opt/www/domains/spring.io/docs/htdocs/security/reference/ --local-path SITE_PATH --ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
216248
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
217249

Diff for: rsync-antora-reference/test/test-zip_docs.bats

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
setup () {
2+
load 'test_helper/common-setup'
3+
_common_setup
4+
}
5+
6+
# executed after each test
7+
teardown() {
8+
_common_teardown
9+
}
10+
11+
@test "no arguments" {
12+
run zip_docs.sh
13+
assert [ "$status" -eq 1 ]
14+
assert [ "${lines[0]}" = "Error: '--zip-name' must end with .zip but got ''" ]
15+
assert [ "${lines[1]}" = 'usage: zip_docs.sh [OPTION]...' ]
16+
}
17+
18+
@test "usage" {
19+
run zip_docs.sh
20+
assert [ "$status" -eq 1 ]
21+
assert [ "${output}" = "Error: '--zip-name' must end with .zip but got ''
22+
usage: zip_docs.sh [OPTION]...
23+
24+
--zip-name=NAME the name of the zip file to be created
25+
--ssh-docs-path=PATH the full path that the docs that should be included in the zip file (e.g. https://docs.spring.io/spring-security/reference/ is \${HTTP_DOCS}/spring-security/reference)" ]
26+
}
27+
28+
@test "invalid long option" {
29+
run zip_docs.sh --invalid
30+
assert [ "$status" -eq 1 ]
31+
assert [ "${lines[0]}" = "getopt: unrecognized option '--invalid'" ]
32+
assert [ "${lines[1]}" = 'usage: zip_docs.sh [OPTION]...' ]
33+
}
34+
35+
# --zip-name spring-security-docs.zip --ssh-docs-path /spring-security/reference
36+
@test "missing github-repository" {
37+
run zip_docs.sh --ssh-docs-path /spring-security/reference
38+
assert [ "$status" -eq 1 ]
39+
assert [ "${lines[0]}" = "Error: '--zip-name' must end with .zip but got ''" ]
40+
assert [ "${lines[1]}" = 'usage: zip_docs.sh [OPTION]...' ]
41+
}
42+
43+
@test "invalid zip-name ZIP" {
44+
run zip_docs.sh --zip-name ZIP --ssh-docs-path /spring-security/reference
45+
assert [ "$status" -eq 1 ]
46+
assert [ "${lines[0]}" = "Error: '--zip-name' must end with .zip but got 'ZIP'" ]
47+
assert [ "${lines[1]}" = 'usage: zip_docs.sh [OPTION]...' ]
48+
}
49+
50+
@test "missing ssh-docs-path" {
51+
run zip_docs.sh --zip-name spring-security-docs.zip
52+
assert [ "$status" -eq 1 ]
53+
assert [ "${lines[0]}" = "Error: '--ssh-docs-path' must start with / but got ''" ]
54+
assert [ "${lines[1]}" = 'usage: zip_docs.sh [OPTION]...' ]
55+
}
56+
57+
@test "invalid ssh-docs-path spring-security/reference" {
58+
run zip_docs.sh --zip-name spring-security-docs.zip --ssh-docs-path spring-security/reference
59+
assert [ "$status" -eq 1 ]
60+
assert [ "${lines[0]}" = "Error: '--ssh-docs-path' must start with / but got 'spring-security/reference'" ]
61+
assert [ "${lines[1]}" = 'usage: zip_docs.sh [OPTION]...' ]
62+
}
63+
64+
@test "missing --ssh-docs-path" {
65+
local dir="${BATS_RESOURCE_TEMP_DIR}/MISSING"
66+
run zip_docs.sh --zip-name spring-security-docs.zip --ssh-docs-path "$dir"
67+
assert_failure
68+
assert_output "Error: Directory --ssh-docs-path '$dir' cannot be zipped because it does not exist"
69+
}
70+
71+
@test "success" {
72+
stub zip "$(capture_program_args "zip")"
73+
74+
local dir="${BATS_RESOURCE_TEMP_DIR}/spring-security"
75+
run zip_docs.sh --zip-name spring-security-docs.zip --ssh-docs-path "$dir"
76+
77+
assert_success
78+
assert_output "Zipping content in '$dir' to 'spring-security-docs.zip'
79+
$(pwd)"
80+
assert_program_args "zip" "-r spring-security-docs.zip . *"
81+
82+
unstub zip
83+
}

0 commit comments

Comments
 (0)