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

Defaults Preserve-LFS #503

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ In addition to the deployment options you must also configure the following.
| `CLEAN` | If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option is turned on by default, and can be toggled off by setting it to `false`. | `with` | **No** |
| `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** |

Expand Down
60 changes: 6 additions & 54 deletions __tests__/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,6 @@ describe('git', () => {
})

describe('init', () => {
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)
})

it('should catch when a function throws an error', async () => {
;(execute as jest.Mock).mockImplementationOnce(() => {
throw new Error('Mocked throw')
Expand All @@ -63,7 +44,6 @@ describe('git', () => {
accessToken: '123',
branch: 'branch',
folder: '.',
preserve: true,
isTest: true,
pusher: {
name: 'asd',
Expand Down Expand Up @@ -192,31 +172,6 @@ describe('git', () => {
folder: 'assets',
branch: 'branch',
gitHubToken: '123',
lfs: true,
pusher: {
name: 'asd',
email: 'as@cat'
}
})

const response = await deploy(action)

// Includes the call to generateBranch
expect(execute).toBeCalledTimes(13)
expect(rmRF).toBeCalledTimes(1)
expect(response).toBe(Status.SUCCESS)
})

it('should execute stash apply commands if preserve is true', async () => {
Object.assign(action, {
silent: false,
folder: 'assets',
folderPath: 'assets',
branch: 'branch',
gitHubToken: '123',
lfs: true,
preserve: true,
isTest: true,
pusher: {
name: 'asd',
email: 'as@cat'
Expand Down Expand Up @@ -245,8 +200,6 @@ describe('git', () => {
folderPath: 'assets',
branch: 'branch',
gitHubToken: '123',
lfs: true,
preserve: true,
isTest: true,
pusher: {
name: 'asd',
Expand Down Expand Up @@ -280,7 +233,7 @@ describe('git', () => {
await deploy(action)

// Includes the call to generateBranch
expect(execute).toBeCalledTimes(18)
expect(execute).toBeCalledTimes(20)
expect(rmRF).toBeCalledTimes(1)
})

Expand All @@ -304,7 +257,7 @@ describe('git', () => {
const response = await deploy(action)

// Includes the call to generateBranch
expect(execute).toBeCalledTimes(12)
expect(execute).toBeCalledTimes(14)
expect(rmRF).toBeCalledTimes(1)
expect(response).toBe(Status.SUCCESS)
})
Expand All @@ -329,7 +282,7 @@ describe('git', () => {
await deploy(action)

// Includes the call to generateBranch
expect(execute).toBeCalledTimes(12)
expect(execute).toBeCalledTimes(14)
expect(rmRF).toBeCalledTimes(1)
})

Expand All @@ -351,7 +304,7 @@ describe('git', () => {
await deploy(action)

// Includes the call to generateBranch
expect(execute).toBeCalledTimes(12)
expect(execute).toBeCalledTimes(14)
expect(rmRF).toBeCalledTimes(1)
})

Expand All @@ -371,7 +324,7 @@ describe('git', () => {

await deploy(action)

expect(execute).toBeCalledTimes(12)
expect(execute).toBeCalledTimes(14)
expect(rmRF).toBeCalledTimes(1)
expect(mkdirP).toBeCalledTimes(1)
})
Expand All @@ -390,7 +343,7 @@ describe('git', () => {
})

const response = await deploy(action)
expect(execute).toBeCalledTimes(13)
expect(execute).toBeCalledTimes(15)
expect(rmRF).toBeCalledTimes(1)
expect(response).toBe(Status.SKIPPED)
})
Expand All @@ -405,7 +358,6 @@ describe('git', () => {
folder: 'assets',
branch: 'branch',
gitHubToken: '123',
lfs: true,
pusher: {
name: 'asd',
email: 'as@cat'
Expand Down
4 changes: 2 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('main', () => {
debug: true
})
await run(action)
expect(execute).toBeCalledTimes(19)
expect(execute).toBeCalledTimes(22)
expect(rmRF).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
})
Expand All @@ -64,7 +64,7 @@ describe('main', () => {
}
})
await run(action)
expect(execute).toBeCalledTimes(18)
expect(execute).toBeCalledTimes(21)
expect(rmRF).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
})
Expand Down
8 changes: 0 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,11 @@ inputs:
SINGLE_COMMIT:
description: "This option can be used if you'd prefer to have a single commit on the deployment branch instead of maintaining the full history."
required: false

LFS:
description: "Migrates files from Git LFS so they can be comitted to the deployment branch."
required: false

SILENT:
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'
10 changes: 0 additions & 10 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ export interface ActionInterface {
gitHubToken?: string | null
/** Determines if the action is running in test mode or not. */
isTest?: boolean | null
/** Removes files from LFS if toggled to allow normal deployment. */
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. */
Expand Down Expand Up @@ -89,9 +85,6 @@ export const action: ActionInterface = {
isTest: process.env.UNIT_TEST
? process.env.UNIT_TEST.toLowerCase() === 'true'
: false,
lfs: !isNullOrUndefined(getInput('LFS'))
? getInput('LFS').toLowerCase() === 'true'
: false,
email: !isNullOrUndefined(getInput('GIT_CONFIG_EMAIL'))
? getInput('GIT_CONFIG_EMAIL')
: pusher && pusher.email
Expand All @@ -107,9 +100,6 @@ 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
Expand Down
35 changes: 15 additions & 20 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ export async function init(action: ActionInterface): Promise<void | Error> {
action.silent
)

if (action.preserve) {
info(`Stashing workspace changes… ⬆️`)
await execute(`git stash`, action.workspace, action.silent)
}
info(`Stashing any workspace changes… ⬆️`)
await execute(`git stash`, action.workspace, action.silent)

await execute(
`git fetch --no-recurse-submodules`,
Expand Down Expand Up @@ -158,24 +156,21 @@ export async function deploy(action: ActionInterface): Promise<Status> {
action.silent
)

if (action.lfs) {
// Migrates data from LFS so it can be comitted the "normal" way.
info(`Migrating from Git LFS… ⚓`)
await execute(
`git lfs migrate export --include="*" --yes`,
action.workspace,
action.silent
)
}
info(`Migrating from Git LFS… ⚓`)
await execute(
`git lfs migrate export --include="*" --yes`,
action.workspace,
action.silent
)

if (action.preserve) {
info(`Applying stashed workspace changes… ⬆️`)
info(`Applying stashed workspace changes… ⬆️`)

try {
await execute(`git stash apply`, action.workspace, action.silent)
} catch {
info('Unable to apply from stash, continuing…')
}
try {
await execute(`git stash apply`, action.workspace, action.silent)
} catch {
info(
'Unable to apply from stash. This could simply be because there are no stashed changes. Continuing…'
)
}

await execute(
Expand Down