mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
Allow Subsequent Deployments (#690)
* Removing artifacts * Update git.ts * Update git.ts * Fixng up unit tests * Update main.test.ts * Update integration.yml * Update integration.yml
This commit is contained in:
parent
540f86cbdb
commit
0afb880e95
23
.github/workflows/integration.yml
vendored
23
.github/workflows/integration.yml
vendored
@ -171,7 +171,7 @@ jobs:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
branches: gh-pages
|
||||
|
||||
# Deploys using a custom env.
|
||||
# Deploys using a custom env. (Includes subsequent commit)
|
||||
integration-env:
|
||||
needs: integration-ssh-third-party-client
|
||||
runs-on: ubuntu-latest
|
||||
@ -194,6 +194,15 @@ jobs:
|
||||
target-folder: cat/montezuma4
|
||||
silent: true
|
||||
|
||||
- name: Build and Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v4
|
||||
with:
|
||||
ssh-key: ${{ secrets.DEPLOY_KEY }}
|
||||
branch: gh-pages
|
||||
folder: integration
|
||||
target-folder: cat/subsequent
|
||||
silent: true
|
||||
|
||||
- name: Cleanup Generated Branch
|
||||
uses: dawidd6/action-delete-branch@v2.0.1
|
||||
with:
|
||||
@ -227,7 +236,7 @@ jobs:
|
||||
clean: true
|
||||
silent: true
|
||||
|
||||
# Deploys to a branch that doesn't exist with SINGLE_COMMIT.
|
||||
# Deploys to a branch that doesn't exist with SINGLE_COMMIT. (Includes subsequent commit)
|
||||
integration-branch-creation:
|
||||
needs: integration-clean
|
||||
runs-on: ubuntu-latest
|
||||
@ -246,6 +255,16 @@ jobs:
|
||||
single-commit: true
|
||||
silent: true
|
||||
|
||||
- name: Build and Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v4
|
||||
with:
|
||||
token: ${{ secrets.ACCESS_TOKEN }}
|
||||
branch: integration-test-delete-prod
|
||||
folder: integration
|
||||
single-commit: true
|
||||
target-folder: jives
|
||||
silent: true
|
||||
|
||||
- name: Cleanup Generated Branch
|
||||
uses: dawidd6/action-delete-branch@v2.0.1
|
||||
with:
|
||||
|
@ -168,7 +168,7 @@ describe('git', () => {
|
||||
const response = await deploy(action)
|
||||
|
||||
// Includes the call to generateWorktree
|
||||
expect(execute).toBeCalledTimes(11)
|
||||
expect(execute).toBeCalledTimes(13)
|
||||
expect(rmRF).toBeCalledTimes(1)
|
||||
expect(response).toBe(Status.SUCCESS)
|
||||
})
|
||||
@ -191,7 +191,7 @@ describe('git', () => {
|
||||
const response = await deploy(action)
|
||||
|
||||
// Includes the call to generateWorktree
|
||||
expect(execute).toBeCalledTimes(10)
|
||||
expect(execute).toBeCalledTimes(12)
|
||||
expect(rmRF).toBeCalledTimes(1)
|
||||
expect(response).toBe(Status.SUCCESS)
|
||||
})
|
||||
@ -296,7 +296,7 @@ describe('git', () => {
|
||||
const response = await deploy(action)
|
||||
|
||||
// Includes the call to generateWorktree
|
||||
expect(execute).toBeCalledTimes(11)
|
||||
expect(execute).toBeCalledTimes(13)
|
||||
expect(rmRF).toBeCalledTimes(1)
|
||||
expect(fs.existsSync).toBeCalledTimes(2)
|
||||
expect(response).toBe(Status.SUCCESS)
|
||||
@ -328,7 +328,7 @@ describe('git', () => {
|
||||
await deploy(action)
|
||||
|
||||
// Includes the call to generateWorktree
|
||||
expect(execute).toBeCalledTimes(8)
|
||||
expect(execute).toBeCalledTimes(10)
|
||||
expect(rmRF).toBeCalledTimes(1)
|
||||
})
|
||||
})
|
||||
@ -353,7 +353,7 @@ describe('git', () => {
|
||||
await deploy(action)
|
||||
|
||||
// Includes the call to generateWorktree
|
||||
expect(execute).toBeCalledTimes(8)
|
||||
expect(execute).toBeCalledTimes(10)
|
||||
expect(rmRF).toBeCalledTimes(1)
|
||||
})
|
||||
|
||||
@ -373,7 +373,7 @@ describe('git', () => {
|
||||
|
||||
await deploy(action)
|
||||
|
||||
expect(execute).toBeCalledTimes(8)
|
||||
expect(execute).toBeCalledTimes(10)
|
||||
expect(rmRF).toBeCalledTimes(1)
|
||||
expect(mkdirP).toBeCalledTimes(1)
|
||||
})
|
||||
@ -393,7 +393,7 @@ describe('git', () => {
|
||||
})
|
||||
|
||||
const response = await deploy(action)
|
||||
expect(execute).toBeCalledTimes(8)
|
||||
expect(execute).toBeCalledTimes(10)
|
||||
expect(rmRF).toBeCalledTimes(1)
|
||||
expect(response).toBe(Status.SKIPPED)
|
||||
})
|
||||
|
@ -49,7 +49,7 @@ describe('main', () => {
|
||||
debug: true
|
||||
})
|
||||
await run(action)
|
||||
expect(execute).toBeCalledTimes(13)
|
||||
expect(execute).toBeCalledTimes(15)
|
||||
expect(rmRF).toBeCalledTimes(1)
|
||||
expect(exportVariable).toBeCalledTimes(1)
|
||||
})
|
||||
@ -69,7 +69,7 @@ describe('main', () => {
|
||||
isTest: TestFlag.HAS_CHANGED_FILES
|
||||
})
|
||||
await run(action)
|
||||
expect(execute).toBeCalledTimes(16)
|
||||
expect(execute).toBeCalledTimes(18)
|
||||
expect(rmRF).toBeCalledTimes(1)
|
||||
expect(exportVariable).toBeCalledTimes(1)
|
||||
})
|
||||
|
25
src/git.ts
25
src/git.ts
@ -151,7 +151,9 @@ export async function deploy(action: ActionInterface): Promise<Status> {
|
||||
branchExists && action.singleCommit
|
||||
? `git diff origin/${action.branch}`
|
||||
: `git status --porcelain`
|
||||
|
||||
info(`Checking if there are files to commit…`)
|
||||
|
||||
const hasFilesToCommit =
|
||||
action.isTest & TestFlag.HAS_CHANGED_FILES ||
|
||||
(await execute(
|
||||
@ -160,7 +162,11 @@ export async function deploy(action: ActionInterface): Promise<Status> {
|
||||
true // This output is always silenced due to the large output it creates.
|
||||
))
|
||||
|
||||
if (!hasFilesToCommit) {
|
||||
if (
|
||||
(!action.singleCommit && !hasFilesToCommit) ||
|
||||
// Ignores the case where single commit is true with a target folder to prevent incorrect early exiting.
|
||||
(action.singleCommit && !action.targetFolder && !hasFilesToCommit)
|
||||
) {
|
||||
return Status.SKIPPED
|
||||
}
|
||||
|
||||
@ -201,11 +207,28 @@ export async function deploy(action: ActionInterface): Promise<Status> {
|
||||
} finally {
|
||||
// Cleans up temporary files/folders and restores the git state.
|
||||
info('Running post deployment cleanup jobs… 🗑️')
|
||||
|
||||
if (!action.singleCommit) {
|
||||
info(`Resetting branch and removing artifacts…`)
|
||||
await execute(
|
||||
`git checkout -B ${temporaryDeploymentBranch}`,
|
||||
`${action.workspace}/${temporaryDeploymentDirectory}`,
|
||||
action.silent
|
||||
)
|
||||
|
||||
await execute(
|
||||
`git branch -D ${action.branch} --force`,
|
||||
action.workspace,
|
||||
action.silent
|
||||
)
|
||||
}
|
||||
|
||||
await execute(
|
||||
`git worktree remove ${temporaryDeploymentDirectory} --force`,
|
||||
action.workspace,
|
||||
action.silent
|
||||
)
|
||||
|
||||
await rmRF(temporaryDeploymentDirectory)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user