From 0afb880e95cf38d78fca29d8a2b4382ae896637e Mon Sep 17 00:00:00 2001 From: James Ives Date: Mon, 10 May 2021 09:17:42 -0400 Subject: [PATCH] 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 --- .github/workflows/integration.yml | 23 +++++++++++++++++++++-- __tests__/git.test.ts | 14 +++++++------- __tests__/main.test.ts | 4 ++-- src/git.ts | 25 ++++++++++++++++++++++++- 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 1b1b1e91..9f21eaa5 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -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: diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index 3f976a6a..843d7fd5 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -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) }) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 1738f0dd..510e7c65 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -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) }) diff --git a/src/git.ts b/src/git.ts index 4313a9d4..221226ae 100644 --- a/src/git.ts +++ b/src/git.ts @@ -151,7 +151,9 @@ export async function deploy(action: ActionInterface): Promise { 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 { 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 { } 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) } }