Skip to content

Commit b5d87eb

Browse files
Merge pull request microsoft#200 from daschuer/ssh_cleanup
ssh cleanup code
2 parents 51782b1 + 4eb8e5d commit b5d87eb

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

.github/deploy.sh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
#
33
# Deploy artifacts (e.g. dmg, deb files) built by CI to downloads.mixxx.org.
44

5-
set -eu -o pipefail
5+
set -Eeuo pipefail
66

77
[ -z "${SSH_HOST}" ] && echo "Please set the SSH_HOST env var." >&2 && exit 1
88
[ -z "${SSH_KEY}" ] && echo "Please set the SSH_KEY env var." >&2 && exit 1
@@ -15,15 +15,19 @@ set -eu -o pipefail
1515
SSH="ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
1616
GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
1717
DEST_PATH="${DESTDIR}/${GIT_BRANCH}/${OS}"
18-
TMP_PATH="${DESTDIR}/.tmp/${UPLOAD_ID}"
18+
TMP_PATH="../../.tmp/${UPLOAD_ID}"
1919

20-
echo "Deploying to $TMP_PATH, then to $DEST_PATH."
20+
echo "Deploying to ${TMP_PATH}, then to ${DEST_PATH}."
2121

22-
# Start SSH agent
23-
ssh-agent -a ${SSH_AUTH_SOCK} > /dev/null
22+
eval "$(ssh-agent -s)" >/dev/null
23+
24+
cleanup() {
25+
eval "$(ssh-agent -k)" >/dev/null
26+
}
27+
trap cleanup EXIT
2428

2529
# Add private key to SSH agent
26-
ssh-add - <<< "${SSH_KEY}"
30+
ssh-add - <<< "${SSH_KEY}" >/dev/null
2731

2832
# realpath does not exist on macOS
2933
command -v realpath >/dev/null 2>&1 || realpath() {
@@ -50,13 +54,9 @@ do
5054
popd
5155

5256
FILEEXT="${FILENAME##*.}"
57+
58+
# Ensure directories exist
59+
${SSH} "${SSH_USER}@${SSH_HOST}" "mkdir -p '${DEST_PATH}' '${DEST_PATH}/${TMP_PATH}'"
5360

54-
rsync -e "${SSH}" --rsync-path="mkdir -p ${TMP_PATH} && rsync" -r --delete-after "${FILEPATH}" "${FILEPATH_HASH}" "${SSH_USER}@${SSH_HOST}:${TMP_PATH}"
55-
56-
# Move from the temporary path to the final destination.
57-
${SSH} "${SSH_USER}@${SSH_HOST}" << EOF
58-
trap 'rm -rf "${TMP_PATH}"' EXIT
59-
mkdir -p "${DEST_PATH}" &&
60-
mv "${TMP_PATH}/${FILENAME}" "${TMP_PATH}/${FILENAME_HASH}" "${DEST_PATH}"
61-
EOF
61+
rsync -e "${SSH}" --partial --partial-dir="${TMP_PATH}" --delay-updates -r "${FILEPATH}" "${FILEPATH_HASH}" "${SSH_USER}@${SSH_HOST}:${DEST_PATH}"
6262
done

.github/workflows/build.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,23 +209,15 @@ jobs:
209209
# Use retry loop to work around intermittent transfer issue
210210
uses: nick-fields/retry@9417ab499314dfe692edb043ded2ff9b3f5f0a68 # v3
211211
with:
212-
shell: bash
213212
max_attempts: 10
214213
timeout_minutes: 20
215214
retry_wait_seconds: 5
216215
command: |
217216
cd ${{ matrix.vcpkg_path }}
218217
.github/deploy.sh ${{ env.DEPS_BASE_NAME }}-${{ env.MIXXX_VERSION }}-${{ matrix.deps_name }}-${{ steps.vars.outputs.sha_short }}.zip
219-
on_retry_command: |
220-
if [[ "$RUNNER_OS" == "Windows" ]]; then
221-
powershell -Command "Get-Process ssh-agent -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue"
222-
else
223-
killall ssh-agent || true
224-
fi
225218
env:
226219
DESTDIR: public_html/downloads/dependencies
227220
OS: ${{ runner.os }}
228-
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
229221
SSH_HOST: downloads-hostgator.mixxx.org
230222
SSH_KEY: ${{ secrets.DOWNLOADS_HOSTGATOR_DOT_MIXXX_DOT_ORG_KEY }}
231223
SSH_PASSWORD: ${{ secrets.DOWNLOADS_HOSTGATOR_DOT_MIXXX_DOT_ORG_KEY_PASSWORD }}

0 commit comments

Comments
 (0)