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:
James Ives 2021-05-10 09:17:42 -04:00 committed by GitHub
parent 540f86cbdb
commit 0afb880e95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 12 deletions

View File

@ -171,7 +171,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }}
branches: gh-pages branches: gh-pages
# Deploys using a custom env. # Deploys using a custom env. (Includes subsequent commit)
integration-env: integration-env:
needs: integration-ssh-third-party-client needs: integration-ssh-third-party-client
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -194,6 +194,15 @@ jobs:
target-folder: cat/montezuma4 target-folder: cat/montezuma4
silent: true 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 - name: Cleanup Generated Branch
uses: dawidd6/action-delete-branch@v2.0.1 uses: dawidd6/action-delete-branch@v2.0.1
with: with:
@ -227,7 +236,7 @@ jobs:
clean: true clean: true
silent: 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: integration-branch-creation:
needs: integration-clean needs: integration-clean
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -246,6 +255,16 @@ jobs:
single-commit: true single-commit: true
silent: 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 - name: Cleanup Generated Branch
uses: dawidd6/action-delete-branch@v2.0.1 uses: dawidd6/action-delete-branch@v2.0.1
with: with:

View File

@ -168,7 +168,7 @@ describe('git', () => {
const response = await deploy(action) const response = await deploy(action)
// Includes the call to generateWorktree // Includes the call to generateWorktree
expect(execute).toBeCalledTimes(11) expect(execute).toBeCalledTimes(13)
expect(rmRF).toBeCalledTimes(1) expect(rmRF).toBeCalledTimes(1)
expect(response).toBe(Status.SUCCESS) expect(response).toBe(Status.SUCCESS)
}) })
@ -191,7 +191,7 @@ describe('git', () => {
const response = await deploy(action) const response = await deploy(action)
// Includes the call to generateWorktree // Includes the call to generateWorktree
expect(execute).toBeCalledTimes(10) expect(execute).toBeCalledTimes(12)
expect(rmRF).toBeCalledTimes(1) expect(rmRF).toBeCalledTimes(1)
expect(response).toBe(Status.SUCCESS) expect(response).toBe(Status.SUCCESS)
}) })
@ -296,7 +296,7 @@ describe('git', () => {
const response = await deploy(action) const response = await deploy(action)
// Includes the call to generateWorktree // Includes the call to generateWorktree
expect(execute).toBeCalledTimes(11) expect(execute).toBeCalledTimes(13)
expect(rmRF).toBeCalledTimes(1) expect(rmRF).toBeCalledTimes(1)
expect(fs.existsSync).toBeCalledTimes(2) expect(fs.existsSync).toBeCalledTimes(2)
expect(response).toBe(Status.SUCCESS) expect(response).toBe(Status.SUCCESS)
@ -328,7 +328,7 @@ describe('git', () => {
await deploy(action) await deploy(action)
// Includes the call to generateWorktree // Includes the call to generateWorktree
expect(execute).toBeCalledTimes(8) expect(execute).toBeCalledTimes(10)
expect(rmRF).toBeCalledTimes(1) expect(rmRF).toBeCalledTimes(1)
}) })
}) })
@ -353,7 +353,7 @@ describe('git', () => {
await deploy(action) await deploy(action)
// Includes the call to generateWorktree // Includes the call to generateWorktree
expect(execute).toBeCalledTimes(8) expect(execute).toBeCalledTimes(10)
expect(rmRF).toBeCalledTimes(1) expect(rmRF).toBeCalledTimes(1)
}) })
@ -373,7 +373,7 @@ describe('git', () => {
await deploy(action) await deploy(action)
expect(execute).toBeCalledTimes(8) expect(execute).toBeCalledTimes(10)
expect(rmRF).toBeCalledTimes(1) expect(rmRF).toBeCalledTimes(1)
expect(mkdirP).toBeCalledTimes(1) expect(mkdirP).toBeCalledTimes(1)
}) })
@ -393,7 +393,7 @@ describe('git', () => {
}) })
const response = await deploy(action) const response = await deploy(action)
expect(execute).toBeCalledTimes(8) expect(execute).toBeCalledTimes(10)
expect(rmRF).toBeCalledTimes(1) expect(rmRF).toBeCalledTimes(1)
expect(response).toBe(Status.SKIPPED) expect(response).toBe(Status.SKIPPED)
}) })

View File

@ -49,7 +49,7 @@ describe('main', () => {
debug: true debug: true
}) })
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)
}) })
@ -69,7 +69,7 @@ describe('main', () => {
isTest: TestFlag.HAS_CHANGED_FILES isTest: TestFlag.HAS_CHANGED_FILES
}) })
await run(action) await run(action)
expect(execute).toBeCalledTimes(16) expect(execute).toBeCalledTimes(18)
expect(rmRF).toBeCalledTimes(1) expect(rmRF).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1) expect(exportVariable).toBeCalledTimes(1)
}) })

View File

@ -151,7 +151,9 @@ 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…`) 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(
@ -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. 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 return Status.SKIPPED
} }
@ -201,11 +207,28 @@ export async function deploy(action: ActionInterface): Promise<Status> {
} finally { } finally {
// Cleans up temporary files/folders and restores the git state. // Cleans up temporary files/folders and restores the git state.
info('Running post deployment cleanup jobs… 🗑️') 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( await execute(
`git worktree remove ${temporaryDeploymentDirectory} --force`, `git worktree remove ${temporaryDeploymentDirectory} --force`,
action.workspace, action.workspace,
action.silent action.silent
) )
await rmRF(temporaryDeploymentDirectory) await rmRF(temporaryDeploymentDirectory)
} }
} }