Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable rsync mkpath to be backwards compatible #1757

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {generateWorktree} from './worktree'
import {
extractErrorMessage,
isNullOrUndefined,
suppressSensitiveInformation
suppressSensitiveInformation,
getRsyncVersion
} from './util'

/**
Expand Down Expand Up @@ -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…')

Expand Down Expand Up @@ -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
Expand Down
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 {
Expand Down Expand Up @@ -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 ''
}
}
Loading