name: 'Prepare Remote NFS Directories' description: | Creates specified directories on a remote NFS-mounted server via SSH. Uses stack_name and optional short SHA to isolate deployments. Skips execution if no directories are specified. inputs: stack_name: description: 'Stack name to prefix remote directories' required: true 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 echo "DEBUG: Starting directory preparation step" echo "DEBUG: Remote host: ${{ inputs.ssh_host }}" echo "DEBUG: Remote user: ${{ inputs.ssh_user }}" echo "DEBUG: Remote base path: ${{ inputs.remote_base_path }}" echo "DEBUG: Stack name: ${{ inputs.stack_name }}" echo "DEBUG: Directory prefix: '${{ inputs.dir_prefix }}'" 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="" REMOTE_BASE="${{ inputs.remote_base_path }}" STACK_NAME="${{ inputs.stack_name }}" PREFIX="${{ inputs.dir_prefix }}" # Build the root directory path if [ -n "$PREFIX" ]; then ROOT_DIR="$REMOTE_BASE/${STACK_NAME}-${PREFIX}" else ROOT_DIR="$REMOTE_BASE/${STACK_NAME}" fi echo "DEBUG: Root remote directory: '$ROOT_DIR'" while IFS= read -r LOCAL_DIR || [ -n "$LOCAL_DIR" ]; do echo "DEBUG: Processing local directory: '$LOCAL_DIR'" if [ -d "$LOCAL_DIR" ]; then REMOTE_DIR="$ROOT_DIR/$LOCAL_DIR" echo "DEBUG: Ensuring remote directory exists: '$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: Remote directory '$REMOTE_DIR' created and permissions set" echo "DEBUG: Copying contents from local '$LOCAL_DIR' to remote '$REMOTE_DIR'" if compgen -G "$LOCAL_DIR/*" > /dev/null; then scp -o StrictHostKeyChecking=no -i "$SSH_KEY_FILE" -r "$LOCAL_DIR/"* \ ${{ inputs.ssh_user }}@${{ inputs.ssh_host }}:"$REMOTE_DIR/" echo "DEBUG: Files from '$LOCAL_DIR' copied successfully to '$REMOTE_DIR'" else echo "DEBUG: No files found in '$LOCAL_DIR' to copy" fi 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 at $SSH_KEY_FILE" rm -f "$SSH_KEY_FILE" echo "DEBUG: Temporary SSH key file removed" echo "DEBUG: All directories processed. Created paths:" echo "$CREATED_PATHS" echo "created_paths<> $GITHUB_OUTPUT echo "$CREATED_PATHS" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT echo "DEBUG: Directory preparation step completed successfully"