|
17 | 17 | source:
|
18 | 18 | type: string
|
19 | 19 | required: true
|
20 |
| - description: Remote absolute path to configuration input source |
| 20 | + description: Remote absolute path to configuration input source file or directory |
21 | 21 | target:
|
22 | 22 | type: string
|
23 | 23 | required: true
|
24 |
| - description: Remote absolute path to configuration input destination |
| 24 | + description: Remote absolute path to configuration input destination directory |
25 | 25 | overwrite-target:
|
26 | 26 | type: boolean
|
27 | 27 | required: true
|
|
69 | 69 | run: |
|
70 | 70 | errors=false
|
71 | 71 |
|
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)" |
78 | 74 | errors=true
|
79 | 75 | fi
|
80 | 76 | if [ -z "${{ inputs.target-acl-spec }}" ]; then
|
@@ -194,15 +190,14 @@ jobs:
|
194 | 190 | # and then one locally on the runner to copy the list of files from the remote.
|
195 | 191 | run: |
|
196 | 192 | ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} -i ${{ steps.ssh.outputs.private-key-path }} /bin/bash <<'EOT'
|
197 |
| -
|
198 | 193 | # 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" |
204 | 198 |
|
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" \ |
206 | 201 | ${{ ! inputs.overwrite-target && '--ignore-existing' || '--update' }} \
|
207 | 202 | ${{ inputs.source }} ${{ inputs.target }} \
|
208 | 203 | | grep --invert-match '/$' \
|
|
0 commit comments