diff --git a/src/git.ts b/src/git.ts index c7c2b4c79..248db032a 100644 --- a/src/git.ts +++ b/src/git.ts @@ -12,7 +12,8 @@ import {generateWorktree} from './worktree' import { extractErrorMessage, isNullOrUndefined, - suppressSensitiveInformation + suppressSensitiveInformation, + getRsyncVersion } from './util' /** @@ -110,6 +111,8 @@ export async function deploy(action: ActionInterface): Promise { const temporaryDeploymentBranch = `github-pages-deploy-action/${Math.random() .toString(36) .substr(2, 9)}` + const rsyncVersion = getRsyncVersion() + const isMkpathSupported = rsyncVersion >= '3.2.3' info('Starting to commit changes…') @@ -166,7 +169,7 @@ export async function deploy(action: ActionInterface): Promise { Allows the user to specify the root if '.' is provided. rsync is used to prevent file duplication. */ await execute( - `rsync -q -av --checksum --progress ${action.targetFolder ? '--mkpath' : ''} ${action.folderPath}/. ${ + `rsync -q -av --checksum --progress ${isMkpathSupported && action.targetFolder ? '--mkpath' : ''} ${action.folderPath}/. ${ action.targetFolder ? `${temporaryDeploymentDirectory}/${action.targetFolder}` : temporaryDeploymentDirectory diff --git a/src/util.ts b/src/util.ts index 7ed60760a..f1a45150b 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,4 +1,5 @@ import {isDebug, warning} from '@actions/core' +import {execSync} from 'child_process' import {existsSync} from 'fs' import path from 'path' import { @@ -140,3 +141,20 @@ export const extractErrorMessage = (error: unknown): string => */ export const stripProtocolFromUrl = (url: string): string => url.replace(/^(?:https?:\/\/)?(?:www\.)?/i, '').split('/')[0] + +/** + * Gets the rsync version. + */ +export function getRsyncVersion(): string { + try { + const versionOutput = execSync('rsync --version').toString() + const versionMatch = versionOutput.match( + /rsync\s+version\s+(\d+\.\d+\.\d+)/ + ) + return versionMatch ? versionMatch[1] : '' + } catch (error) { + console.error(error) + + return '' + } +}