mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
Deployment Issues (#583)
* Update git.ts * Tests * Update git.ts * Formatting * Update src/git.ts Co-authored-by: Axel Hecht <axel@pike.org> * TestFlag * Logging * Update git.ts Co-authored-by: Axel Hecht <axel@pike.org>
This commit is contained in:
parent
64eb7112e4
commit
a099e5db8b
@ -40,6 +40,24 @@ describe('git', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('init', () => {
|
describe('init', () => {
|
||||||
|
it('should execute commands', async () => {
|
||||||
|
Object.assign(action, {
|
||||||
|
silent: false,
|
||||||
|
repositoryPath: 'JamesIves/github-pages-deploy-action',
|
||||||
|
token: '123',
|
||||||
|
branch: 'branch',
|
||||||
|
folder: '.',
|
||||||
|
pusher: {
|
||||||
|
name: 'asd',
|
||||||
|
email: 'as@cat'
|
||||||
|
},
|
||||||
|
isTest: TestFlag.HAS_CHANGED_FILES
|
||||||
|
})
|
||||||
|
|
||||||
|
await init(action)
|
||||||
|
expect(execute).toBeCalledTimes(4)
|
||||||
|
})
|
||||||
|
|
||||||
it('should catch when a function throws an error', async () => {
|
it('should catch when a function throws an error', async () => {
|
||||||
;(execute as jest.Mock).mockImplementationOnce(() => {
|
;(execute as jest.Mock).mockImplementationOnce(() => {
|
||||||
throw new Error('Mocked throw')
|
throw new Error('Mocked throw')
|
||||||
@ -66,6 +84,24 @@ describe('git', () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should correctly continue when it cannot remove origin', async () => {
|
||||||
|
Object.assign(action, {
|
||||||
|
silent: false,
|
||||||
|
repositoryPath: 'JamesIves/github-pages-deploy-action',
|
||||||
|
token: '123',
|
||||||
|
branch: 'branch',
|
||||||
|
folder: '.',
|
||||||
|
pusher: {
|
||||||
|
name: 'asd',
|
||||||
|
email: 'as@cat'
|
||||||
|
},
|
||||||
|
isTest: TestFlag.UNABLE_TO_REMOVE_ORIGIN
|
||||||
|
})
|
||||||
|
|
||||||
|
await init(action)
|
||||||
|
expect(execute).toBeCalledTimes(4)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('deploy', () => {
|
describe('deploy', () => {
|
||||||
@ -75,6 +111,7 @@ describe('git', () => {
|
|||||||
folder: 'assets',
|
folder: 'assets',
|
||||||
branch: 'branch',
|
branch: 'branch',
|
||||||
token: '123',
|
token: '123',
|
||||||
|
repositoryName: 'JamesIves/montezuma',
|
||||||
pusher: {
|
pusher: {
|
||||||
name: 'asd',
|
name: 'asd',
|
||||||
email: 'as@cat'
|
email: 'as@cat'
|
||||||
|
@ -49,7 +49,7 @@ describe('main', () => {
|
|||||||
debug: true
|
debug: true
|
||||||
})
|
})
|
||||||
await run(action)
|
await run(action)
|
||||||
expect(execute).toBeCalledTimes(10)
|
expect(execute).toBeCalledTimes(12)
|
||||||
expect(rmRF).toBeCalledTimes(1)
|
expect(rmRF).toBeCalledTimes(1)
|
||||||
expect(exportVariable).toBeCalledTimes(1)
|
expect(exportVariable).toBeCalledTimes(1)
|
||||||
})
|
})
|
||||||
@ -68,7 +68,7 @@ describe('main', () => {
|
|||||||
isTest: TestFlag.HAS_CHANGED_FILES
|
isTest: TestFlag.HAS_CHANGED_FILES
|
||||||
})
|
})
|
||||||
await run(action)
|
await run(action)
|
||||||
expect(execute).toBeCalledTimes(13)
|
expect(execute).toBeCalledTimes(15)
|
||||||
expect(rmRF).toBeCalledTimes(1)
|
expect(rmRF).toBeCalledTimes(1)
|
||||||
expect(exportVariable).toBeCalledTimes(1)
|
expect(exportVariable).toBeCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
@ -8,7 +8,8 @@ const {pusher, repository} = github.context.payload
|
|||||||
export enum TestFlag {
|
export enum TestFlag {
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
HAS_CHANGED_FILES = 1 << 1, // Assume changes to commit
|
HAS_CHANGED_FILES = 1 << 1, // Assume changes to commit
|
||||||
HAS_REMOTE_BRANCH = 1 << 2 // Assume remote repository has existing commits
|
HAS_REMOTE_BRANCH = 1 << 2, // Assume remote repository has existing commits
|
||||||
|
UNABLE_TO_REMOVE_ORIGIN = 1 << 3 // Assume we can't remove origin
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For more information please refer to the README: https://github.com/JamesIves/github-pages-deploy-action */
|
/* For more information please refer to the README: https://github.com/JamesIves/github-pages-deploy-action */
|
||||||
|
23
src/git.ts
23
src/git.ts
@ -23,6 +23,22 @@ export async function init(action: ActionInterface): Promise<void | Error> {
|
|||||||
action.silent
|
action.silent
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
|
await execute(`git remote rm origin`, action.workspace, action.silent)
|
||||||
|
|
||||||
|
if (action.isTest === TestFlag.UNABLE_TO_REMOVE_ORIGIN) {
|
||||||
|
throw new Error()
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
info('Attempted to remove origin but failed, continuing…')
|
||||||
|
}
|
||||||
|
|
||||||
|
await execute(
|
||||||
|
`git remote add origin ${action.repositoryPath}`,
|
||||||
|
action.workspace,
|
||||||
|
action.silent
|
||||||
|
)
|
||||||
|
|
||||||
info('Git configured… 🔧')
|
info('Git configured… 🔧')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -48,7 +64,9 @@ export async function deploy(action: ActionInterface): Promise<Status> {
|
|||||||
const commitMessage = !isNullOrUndefined(action.commitMessage)
|
const commitMessage = !isNullOrUndefined(action.commitMessage)
|
||||||
? (action.commitMessage as string)
|
? (action.commitMessage as string)
|
||||||
: `Deploying to ${action.branch}${
|
: `Deploying to ${action.branch}${
|
||||||
process.env.GITHUB_SHA ? ` from @ ${process.env.GITHUB_SHA}` : ''
|
process.env.GITHUB_SHA
|
||||||
|
? ` from @ ${process.env.GITHUB_REPOSITORY}@${process.env.GITHUB_SHA}`
|
||||||
|
: ''
|
||||||
} 🚀`
|
} 🚀`
|
||||||
|
|
||||||
// Checks to see if the remote exists prior to deploying.
|
// Checks to see if the remote exists prior to deploying.
|
||||||
@ -113,12 +131,13 @@ export async function deploy(action: ActionInterface): Promise<Status> {
|
|||||||
branchExists && action.singleCommit
|
branchExists && action.singleCommit
|
||||||
? `git diff origin/${action.branch}`
|
? `git diff origin/${action.branch}`
|
||||||
: `git status --porcelain`
|
: `git status --porcelain`
|
||||||
|
info(`Checking if there are files to commit…`)
|
||||||
const hasFilesToCommit =
|
const hasFilesToCommit =
|
||||||
action.isTest & TestFlag.HAS_CHANGED_FILES ||
|
action.isTest & TestFlag.HAS_CHANGED_FILES ||
|
||||||
(await execute(
|
(await execute(
|
||||||
checkGitStatus,
|
checkGitStatus,
|
||||||
`${action.workspace}/${temporaryDeploymentDirectory}`,
|
`${action.workspace}/${temporaryDeploymentDirectory}`,
|
||||||
action.silent
|
true // This output is always silenced due to the large output it creates.
|
||||||
))
|
))
|
||||||
|
|
||||||
if (!hasFilesToCommit) {
|
if (!hasFilesToCommit) {
|
||||||
|
Loading…
Reference in New Issue
Block a user