Skip to content

Commit

Permalink
Fix empty BUILD_REFNAME
Browse files Browse the repository at this point in the history
Previously the value of --build-ref-name would be '""' if BUILD_REFNAME was
empty

Closes gh-19
  • Loading branch information
rwinch committed Mar 18, 2024
1 parent 9d51426 commit 6fe7405
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
6 changes: 5 additions & 1 deletion rsync-antora-reference/src/action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ __action_usage_error() {
__action() {
local docs_username docs_host docs_ssh_key docs_ssh_host_key site_path github_repository httpdocs_path valid_args
local rsync_flag_options=''
if [ ! -z "$BUILD_REFNAME" ]; then
rsync_flag_options="${rsync_flag_options} --build-ref-name $BUILD_REFNAME"
fi
valid_args=$(getopt --options '' --long docs-username:,docs-host:,docs-ssh-key:,docs-ssh-host-key:,dry-run,site-path:,github-repository:,httpdocs-path: -- "$@")
if [[ $? -ne 0 ]]; then
__action_usage
Expand Down Expand Up @@ -96,6 +99,7 @@ __action() {
__action_usage_error "Missing option '--github-repository'"
fi


## Extract repository_name from the owner/repository_name
local github_repository_name="$(echo ${github_repository} | cut -d '/' -f 2)"
local ssh_private_key_path="$HOME/.ssh/${github_repository:-publish-docs}"
Expand All @@ -112,7 +116,7 @@ __action() {
local pwd="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
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\""
fi
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" --build-ref-name "\"$BUILD_REFNAME\"" $rsync_flag_options
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
)
exit_code=$?

Expand Down
16 changes: 8 additions & 8 deletions rsync-antora-reference/test/test-action.bats
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ usage: action.sh [OPTION]...
assert_success
assert_output "" # No warnings due to spaces
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"
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 \"\""
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"
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"

unstub --allow-missing setup_ssh.sh
Expand All @@ -98,7 +98,7 @@ usage: action.sh [OPTION]...
assert_success
assert_output "" # No warnings due to spaces
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"
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 \"\""
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"
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"

unstub --allow-missing setup_ssh.sh
Expand All @@ -122,7 +122,7 @@ usage: action.sh [OPTION]...

assert_success
assert_program_args "setup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --ssh-private-key KEY --ssh-known-host HOST_KEY"
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 \"\""
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"
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"

unstub --allow-missing setup_ssh.sh
Expand All @@ -139,7 +139,7 @@ usage: action.sh [OPTION]...

assert_success
assert_program_args "setup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --ssh-private-key KEY --ssh-known-host HOST_KEY"
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 --build-ref-name \"\""
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"
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
}

Expand All @@ -153,7 +153,7 @@ usage: action.sh [OPTION]...

assert_success
assert_program_args "setup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --ssh-private-key KEY --ssh-known-host HOST_KEY"
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 --build-ref-name \"\""
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"
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"
}

Expand All @@ -166,7 +166,7 @@ usage: action.sh [OPTION]...

assert_success
assert_program_args "setup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --ssh-private-key KEY --ssh-known-host HOST_KEY"
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 \"\" --dry-run"
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"
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"

unstub --allow-missing setup_ssh.sh
Expand All @@ -185,7 +185,7 @@ usage: action.sh [OPTION]...

assert_success
assert_program_args "setup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --ssh-private-key KEY --ssh-known-host HOST_KEY"
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"
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"
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"

unstub --allow-missing setup_ssh.sh
Expand All @@ -205,7 +205,7 @@ usage: action.sh [OPTION]...
assert_program_args "setup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security --ssh-private-key KEY --ssh-known-host HOST_KEY"
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/\""
assert_regex "$(get_program_stdin 'ssh')" 'check_github_repository_owner'
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 --build-ref-name \"\""
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"
assert_program_args "cleanup_ssh" "--ssh-private-key-path $HOME/.ssh/spring-projects/spring-security"

unstub --allow-missing setup_ssh.sh
Expand Down

0 comments on commit 6fe7405

Please sign in to comment.