Skip to content

Commit 389b85f

Browse files
authored
fix: enable rsync mkpath to be backwards compatible (#1757)
* fix: check rsync backwards compat * Update util.ts * fix: format code
1 parent 12622a2 commit 389b85f

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/git.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {generateWorktree} from './worktree'
1212
import {
1313
extractErrorMessage,
1414
isNullOrUndefined,
15-
suppressSensitiveInformation
15+
suppressSensitiveInformation,
16+
getRsyncVersion
1617
} from './util'
1718

1819
/**
@@ -110,6 +111,8 @@ export async function deploy(action: ActionInterface): Promise<Status> {
110111
const temporaryDeploymentBranch = `github-pages-deploy-action/${Math.random()
111112
.toString(36)
112113
.substr(2, 9)}`
114+
const rsyncVersion = getRsyncVersion()
115+
const isMkpathSupported = rsyncVersion >= '3.2.3'
113116

114117
info('Starting to commit changes…')
115118

@@ -166,7 +169,7 @@ export async function deploy(action: ActionInterface): Promise<Status> {
166169
Allows the user to specify the root if '.' is provided.
167170
rsync is used to prevent file duplication. */
168171
await execute(
169-
`rsync -q -av --checksum --progress ${action.targetFolder ? '--mkpath' : ''} ${action.folderPath}/. ${
172+
`rsync -q -av --checksum --progress ${isMkpathSupported && action.targetFolder ? '--mkpath' : ''} ${action.folderPath}/. ${
170173
action.targetFolder
171174
? `${temporaryDeploymentDirectory}/${action.targetFolder}`
172175
: temporaryDeploymentDirectory

src/util.ts

+18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {isDebug, warning} from '@actions/core'
2+
import {execSync} from 'child_process'
23
import {existsSync} from 'fs'
34
import path from 'path'
45
import {
@@ -140,3 +141,20 @@ export const extractErrorMessage = (error: unknown): string =>
140141
*/
141142
export const stripProtocolFromUrl = (url: string): string =>
142143
url.replace(/^(?:https?:\/\/)?(?:www\.)?/i, '').split('/')[0]
144+
145+
/**
146+
* Gets the rsync version.
147+
*/
148+
export function getRsyncVersion(): string {
149+
try {
150+
const versionOutput = execSync('rsync --version').toString()
151+
const versionMatch = versionOutput.match(
152+
/rsync\s+version\s+(\d+\.\d+\.\d+)/
153+
)
154+
return versionMatch ? versionMatch[1] : ''
155+
} catch (error) {
156+
console.error(error)
157+
158+
return ''
159+
}
160+
}

0 commit comments

Comments
 (0)