mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
Stash / Remote Changes (#435)
* Preservation Changes * Update git.ts * Makes adjustments
This commit is contained in:
parent
b8efd660d9
commit
8912f4fdb3
@ -151,6 +151,7 @@ In addition to the deployment options you must also configure the following.
|
||||
| `CLEAN_EXCLUDE` | If you need to use `CLEAN` but you'd like to preserve certain files or folders you can use this option. This should be formatted as an array but stored as a string. For example: `'["filename.js", "folder"]'` | `with` | **No** |
|
||||
| `SINGLE_COMMIT` | This option can be toggled to `true` if you'd prefer to have a single commit on the deployment branch instead of maintaining the full history. **Using this option will also cause any existing history to be wiped from the deployment branch**. | `with` | **No** |
|
||||
| `LFS` | If toggled all files will be migrated from [Git LFS](https://git-lfs.github.com/) so they can be comitted to the deployment branch. | `with` | **No** |
|
||||
| `PRESERVE` | Preserves and restores the workspace prior to deployment. This option is useful if you're modifying files in the worktree that aren't comitted to Git. | `with` | **No** |
|
||||
| `SILENT` | Silences the action output preventing it from displaying git messages. | `with` | **No** |
|
||||
| `WORKSPACE` | This should point to where your project lives on the virtual machine. The GitHub Actions environment will set this for you. It is only necessary to set this variable if you're using the node module. | `with` | **No** |
|
||||
|
||||
|
@ -241,6 +241,26 @@ describe('git', () => {
|
||||
|
||||
expect(execute).toBeCalledTimes(6)
|
||||
})
|
||||
|
||||
it('should stash changes if preserve is true', async () => {
|
||||
Object.assign(action, {
|
||||
silent: false,
|
||||
repositoryPath: 'JamesIves/github-pages-deploy-action',
|
||||
accessToken: '123',
|
||||
branch: 'branch',
|
||||
folder: '.',
|
||||
preserve: true,
|
||||
isTest: true,
|
||||
pusher: {
|
||||
name: 'asd',
|
||||
email: 'as@cat'
|
||||
}
|
||||
})
|
||||
|
||||
await init(action)
|
||||
|
||||
expect(execute).toBeCalledTimes(7)
|
||||
})
|
||||
})
|
||||
|
||||
describe('generateBranch', () => {
|
||||
@ -364,6 +384,29 @@ describe('git', () => {
|
||||
expect(response).toBe(Status.SUCCESS)
|
||||
})
|
||||
|
||||
it('should execute stash apply commands if preserve is true', async () => {
|
||||
Object.assign(action, {
|
||||
silent: false,
|
||||
folder: 'assets',
|
||||
branch: 'branch',
|
||||
gitHubToken: '123',
|
||||
lfs: true,
|
||||
preserve: true,
|
||||
isTest: true,
|
||||
pusher: {
|
||||
name: 'asd',
|
||||
email: 'as@cat'
|
||||
}
|
||||
})
|
||||
|
||||
const response = await deploy(action)
|
||||
|
||||
// Includes the call to generateBranch
|
||||
expect(execute).toBeCalledTimes(14)
|
||||
expect(rmRF).toBeCalledTimes(1)
|
||||
expect(response).toBe(Status.SUCCESS)
|
||||
})
|
||||
|
||||
it('should not ignore CNAME or nojekyll if they exist in the deployment folder', async () => {
|
||||
Object.assign(action, {
|
||||
silent: false,
|
||||
|
@ -77,6 +77,10 @@ inputs:
|
||||
description: "Silences the action output preventing it from displaying git messages."
|
||||
required: false
|
||||
|
||||
PRESERVE:
|
||||
description: "Preserves and restores any workspace changes prior to deployment."
|
||||
required: false
|
||||
|
||||
outputs:
|
||||
DEPLOYMENT_STATUS:
|
||||
description: 'The status of the deployment that indicates if the run failed or passed. Possible outputs include: success|failed|skipped'
|
||||
|
@ -32,6 +32,8 @@ export interface ActionInterface {
|
||||
lfs?: boolean | null
|
||||
/** The git config name. */
|
||||
name?: string
|
||||
/** Determines if the workspace should be stashed/restored prior to comitting. */
|
||||
preserve?: boolean | null
|
||||
/** The repository path, for example JamesIves/github-pages-deploy-action. */
|
||||
repositoryName?: string
|
||||
/** The fully qualified repositpory path, this gets auto generated if repositoryName is provided. */
|
||||
@ -85,6 +87,9 @@ export const action: ActionInterface = {
|
||||
: process.env.GITHUB_ACTOR
|
||||
? process.env.GITHUB_ACTOR
|
||||
: 'GitHub Pages Deploy Action',
|
||||
preserve: !isNullOrUndefined(getInput('PRESERVE'))
|
||||
? getInput('PRESERVE').toLowerCase() === 'true'
|
||||
: false,
|
||||
repositoryName: !isNullOrUndefined(getInput('REPOSITORY_NAME'))
|
||||
? getInput('REPOSITORY_NAME')
|
||||
: repository && repository.full_name
|
||||
|
25
src/git.ts
25
src/git.ts
@ -29,12 +29,25 @@ export async function init(action: ActionInterface): Promise<void | Error> {
|
||||
action.silent
|
||||
)
|
||||
|
||||
try {
|
||||
await execute(`git remote rm origin`, action.workspace, action.silent)
|
||||
} finally {
|
||||
if (action.isTest) {
|
||||
info('Attempted to remove origin…')
|
||||
}
|
||||
}
|
||||
|
||||
await execute(
|
||||
`git remote add origin ${action.repositoryPath}`,
|
||||
action.workspace,
|
||||
action.silent
|
||||
)
|
||||
|
||||
if (action.preserve) {
|
||||
info(`Stashing workspace changes… ⬆️`)
|
||||
await execute(`git stash`, action.workspace, action.silent)
|
||||
}
|
||||
|
||||
await execute(
|
||||
`git fetch --no-recurse-submodules`,
|
||||
action.workspace,
|
||||
@ -165,6 +178,18 @@ export async function deploy(action: ActionInterface): Promise<Status> {
|
||||
)
|
||||
}
|
||||
|
||||
if (action.preserve) {
|
||||
info(`Applying stashed workspace changes… ⬆️`)
|
||||
|
||||
try {
|
||||
await execute(`git stash apply`, action.workspace, action.silent)
|
||||
} finally {
|
||||
if (action.isTest) {
|
||||
info('Attempted to apply stash…')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await execute(
|
||||
`git worktree add --checkout ${temporaryDeploymentDirectory} origin/${action.branch}`,
|
||||
action.workspace,
|
||||
|
Loading…
Reference in New Issue
Block a user