name: 'Prepare Remote NFS Directories' description: | Creates specified directories on a remote NFS-mounted server via SSH. Optionally prefixes directories with a provided short SHA to isolate deployments. Skips execution if no directories are specified. inputs: ssh_host: description: 'SSH host of the remote server' required: true ssh_user: description: 'SSH username for the remote server' required: true ssh_key: description: 'SSH private key for authentication' required: true directories: description: | Newline-separated list of local directories to create remotely and copy contents from. Example: config public/images public/icons required: false default: '' remote_base_path: description: 'Base path on remote server (e.g., /mnt/docker-mounts)' required: false default: '/mnt/docker-mounts' dir_prefix: description: 'Optional prefix for remote directories (e.g., git short SHA)' required: false default: '' outputs: created_paths: description: 'Newline-separated list of remote directories created' value: ${{ steps.prepare.outputs.created_paths }} runs: using: 'composite' steps: - id: prepare shell: bash run: | set -euo pipefail if [ -z "${{ inputs.directories }}" ]; then echo "DEBUG: No directories specified. Skipping directory creation." echo "created_paths=" >> $GITHUB_OUTPUT exit 0 fi SSH_KEY_FILE=$(mktemp) echo "${{ inputs.ssh_key }}" > "$SSH_KEY_FILE" chmod 600 "$SSH_KEY_FILE" echo "DEBUG: Temporary SSH key created at $SSH_KEY_FILE" CREATED_PATHS="" PREFIX="${{ inputs.dir_prefix }}" REMOTE_BASE="${{ inputs.remote_base_path }}" while IFS= read -r LOCAL_DIR || [ -n "$LOCAL_DIR" ]; do if [ -d "$LOCAL_DIR" ]; then REMOTE_DIR="$REMOTE_BASE" if [ -n "$PREFIX" ]; then REMOTE_DIR="$REMOTE_DIR/$PREFIX" fi REMOTE_DIR="$REMOTE_DIR/$LOCAL_DIR" echo "DEBUG: Creating remote directory $REMOTE_DIR" ssh -o StrictHostKeyChecking=no -i "$SSH_KEY_FILE" \ "${{ inputs.ssh_user }}@${{ inputs.ssh_host }}" \ mkdir -p "$REMOTE_DIR" && chmod -R 755 "$REMOTE_DIR" echo "DEBUG: Copying contents from local '$LOCAL_DIR' to remote '$REMOTE_DIR'" scp -o StrictHostKeyChecking=no -i "$SSH_KEY_FILE" -r "$LOCAL_DIR/"* \ ${{ inputs.ssh_user }}@${{ inputs.ssh_host }}:"$REMOTE_DIR/" || echo "DEBUG: No files to copy in '$LOCAL_DIR'" CREATED_PATHS+="$REMOTE_DIR"$'\n' else echo "DEBUG: Local directory '$LOCAL_DIR' does not exist. Skipping." fi done <<< "${{ inputs.directories }}" echo "DEBUG: Cleaning up temporary SSH key file" rm -f "$SSH_KEY_FILE" echo "created_paths<> $GITHUB_OUTPUT echo "$CREATED_PATHS" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT