Skip to content

Commit

Permalink
fix: enable rsync mkpath to be backwards compatible (#1757)
Browse files Browse the repository at this point in the history
* fix: check rsync backwards compat

* Update util.ts

* fix: format code
  • Loading branch information
JamesIves authored Dec 3, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 12622a2 commit 389b85f
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/git.ts
Original file line number Diff line number Diff line change
@@ -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<Status> {
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<Status> {
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
18 changes: 18 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -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 ''
}
}

0 comments on commit 389b85f

Please sign in to comment.