Skip to content

Commit da0b65b

Browse files
Fix to rsync non-dir doubling filename in --output-format (#16)
* remote-copy.yml: Determine `--out-format` based on whether dir or file is being transferred * Simplify the workflow by requiring `inputs.target` to be a directory Co-authored-by: Aidan Heerdegen <[email protected]> --------- Co-authored-by: Aidan Heerdegen <[email protected]>
1 parent ef33762 commit da0b65b

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

.github/workflows/remote-copy.yml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ on:
1717
source:
1818
type: string
1919
required: true
20-
description: Remote absolute path to configuration input source
20+
description: Remote absolute path to configuration input source file or directory
2121
target:
2222
type: string
2323
required: true
24-
description: Remote absolute path to configuration input destination
24+
description: Remote absolute path to configuration input destination directory
2525
overwrite-target:
2626
type: boolean
2727
required: true
@@ -69,12 +69,8 @@ jobs:
6969
run: |
7070
errors=false
7171
72-
if [ -z "${{ inputs.source }}"]; then
73-
echo "::error::No 'source' input given, can't copy anything."
74-
errors=true
75-
fi
76-
if [ -z "${{ inputs.target }}"]; then
77-
echo "::error::No 'target' input given, can't copy to anywhere."
72+
if [[ "$(basename "${{ inputs.source }}")" == "$(basename "${{ inputs.target }}")" ]]; then
73+
echo "::error::Attempted to copy a file into a file (destination must be a directory) or copy a directory into one with the same name (common rsync error)"
7874
errors=true
7975
fi
8076
if [ -z "${{ inputs.target-acl-spec }}" ]; then
@@ -194,15 +190,14 @@ jobs:
194190
# and then one locally on the runner to copy the list of files from the remote.
195191
run: |
196192
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} -i ${{ steps.ssh.outputs.private-key-path }} /bin/bash <<'EOT'
197-
198193
# Create intermediate directories since we can't use `rsync`s `--mkpath` on some deployment targets
199-
if [ -d "${{ inputs.source }}" ]; then
200-
mkdir -p "${{ inputs.target }}"
201-
else # we can assume we are transferring a file
202-
mkdir -p $(dirname "${{ inputs.target }}")
203-
fi
194+
mkdir -p "${{ inputs.target }}"
195+
196+
# The output of the rsync command will be a list of transferred absolute paths, for further processing
197+
RSYNC_OUT_FORMAT="$(readlink -f "${{ inputs.target }}")/%n"
204198
205-
rsync --recursive --out-format="${{ inputs.target }}/%n" \
199+
# Transfer the source to the target, and pipe a space-separated list of destination file paths
200+
rsync --recursive --out-format="$RSYNC_OUT_FORMAT" \
206201
${{ ! inputs.overwrite-target && '--ignore-existing' || '--update' }} \
207202
${{ inputs.source }} ${{ inputs.target }} \
208203
| grep --invert-match '/$' \

0 commit comments

Comments
 (0)