Skip to content

Commit 0afb880

Browse files
authored
Allow Subsequent Deployments (JamesIves#690)
* Removing artifacts * Update git.ts * Update git.ts * Fixng up unit tests * Update main.test.ts * Update integration.yml * Update integration.yml
1 parent 540f86c commit 0afb880

File tree

4 files changed

+54
-12
lines changed

4 files changed

+54
-12
lines changed

.github/workflows/integration.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ jobs:
171171
github_token: ${{ secrets.GITHUB_TOKEN }}
172172
branches: gh-pages
173173

174-
# Deploys using a custom env.
174+
# Deploys using a custom env. (Includes subsequent commit)
175175
integration-env:
176176
needs: integration-ssh-third-party-client
177177
runs-on: ubuntu-latest
@@ -194,6 +194,15 @@ jobs:
194194
target-folder: cat/montezuma4
195195
silent: true
196196

197+
- name: Build and Deploy
198+
uses: JamesIves/github-pages-deploy-action@releases/v4
199+
with:
200+
ssh-key: ${{ secrets.DEPLOY_KEY }}
201+
branch: gh-pages
202+
folder: integration
203+
target-folder: cat/subsequent
204+
silent: true
205+
197206
- name: Cleanup Generated Branch
198207
uses: dawidd6/action-delete-branch@v2.0.1
199208
with:
@@ -227,7 +236,7 @@ jobs:
227236
clean: true
228237
silent: true
229238

230-
# Deploys to a branch that doesn't exist with SINGLE_COMMIT.
239+
# Deploys to a branch that doesn't exist with SINGLE_COMMIT. (Includes subsequent commit)
231240
integration-branch-creation:
232241
needs: integration-clean
233242
runs-on: ubuntu-latest
@@ -246,6 +255,16 @@ jobs:
246255
single-commit: true
247256
silent: true
248257

258+
- name: Build and Deploy
259+
uses: JamesIves/github-pages-deploy-action@releases/v4
260+
with:
261+
token: ${{ secrets.ACCESS_TOKEN }}
262+
branch: integration-test-delete-prod
263+
folder: integration
264+
single-commit: true
265+
target-folder: jives
266+
silent: true
267+
249268
- name: Cleanup Generated Branch
250269
uses: dawidd6/action-delete-branch@v2.0.1
251270
with:

__tests__/git.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ describe('git', () => {
168168
const response = await deploy(action)
169169

170170
// Includes the call to generateWorktree
171-
expect(execute).toBeCalledTimes(11)
171+
expect(execute).toBeCalledTimes(13)
172172
expect(rmRF).toBeCalledTimes(1)
173173
expect(response).toBe(Status.SUCCESS)
174174
})
@@ -191,7 +191,7 @@ describe('git', () => {
191191
const response = await deploy(action)
192192

193193
// Includes the call to generateWorktree
194-
expect(execute).toBeCalledTimes(10)
194+
expect(execute).toBeCalledTimes(12)
195195
expect(rmRF).toBeCalledTimes(1)
196196
expect(response).toBe(Status.SUCCESS)
197197
})
@@ -296,7 +296,7 @@ describe('git', () => {
296296
const response = await deploy(action)
297297

298298
// Includes the call to generateWorktree
299-
expect(execute).toBeCalledTimes(11)
299+
expect(execute).toBeCalledTimes(13)
300300
expect(rmRF).toBeCalledTimes(1)
301301
expect(fs.existsSync).toBeCalledTimes(2)
302302
expect(response).toBe(Status.SUCCESS)
@@ -328,7 +328,7 @@ describe('git', () => {
328328
await deploy(action)
329329

330330
// Includes the call to generateWorktree
331-
expect(execute).toBeCalledTimes(8)
331+
expect(execute).toBeCalledTimes(10)
332332
expect(rmRF).toBeCalledTimes(1)
333333
})
334334
})
@@ -353,7 +353,7 @@ describe('git', () => {
353353
await deploy(action)
354354

355355
// Includes the call to generateWorktree
356-
expect(execute).toBeCalledTimes(8)
356+
expect(execute).toBeCalledTimes(10)
357357
expect(rmRF).toBeCalledTimes(1)
358358
})
359359

@@ -373,7 +373,7 @@ describe('git', () => {
373373

374374
await deploy(action)
375375

376-
expect(execute).toBeCalledTimes(8)
376+
expect(execute).toBeCalledTimes(10)
377377
expect(rmRF).toBeCalledTimes(1)
378378
expect(mkdirP).toBeCalledTimes(1)
379379
})
@@ -393,7 +393,7 @@ describe('git', () => {
393393
})
394394

395395
const response = await deploy(action)
396-
expect(execute).toBeCalledTimes(8)
396+
expect(execute).toBeCalledTimes(10)
397397
expect(rmRF).toBeCalledTimes(1)
398398
expect(response).toBe(Status.SKIPPED)
399399
})

__tests__/main.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('main', () => {
4949
debug: true
5050
})
5151
await run(action)
52-
expect(execute).toBeCalledTimes(13)
52+
expect(execute).toBeCalledTimes(15)
5353
expect(rmRF).toBeCalledTimes(1)
5454
expect(exportVariable).toBeCalledTimes(1)
5555
})
@@ -69,7 +69,7 @@ describe('main', () => {
6969
isTest: TestFlag.HAS_CHANGED_FILES
7070
})
7171
await run(action)
72-
expect(execute).toBeCalledTimes(16)
72+
expect(execute).toBeCalledTimes(18)
7373
expect(rmRF).toBeCalledTimes(1)
7474
expect(exportVariable).toBeCalledTimes(1)
7575
})

src/git.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ export async function deploy(action: ActionInterface): Promise<Status> {
151151
branchExists && action.singleCommit
152152
? `git diff origin/${action.branch}`
153153
: `git status --porcelain`
154+
154155
info(`Checking if there are files to commit…`)
156+
155157
const hasFilesToCommit =
156158
action.isTest & TestFlag.HAS_CHANGED_FILES ||
157159
(await execute(
@@ -160,7 +162,11 @@ export async function deploy(action: ActionInterface): Promise<Status> {
160162
true // This output is always silenced due to the large output it creates.
161163
))
162164

163-
if (!hasFilesToCommit) {
165+
if (
166+
(!action.singleCommit && !hasFilesToCommit) ||
167+
// Ignores the case where single commit is true with a target folder to prevent incorrect early exiting.
168+
(action.singleCommit && !action.targetFolder && !hasFilesToCommit)
169+
) {
164170
return Status.SKIPPED
165171
}
166172

@@ -201,11 +207,28 @@ export async function deploy(action: ActionInterface): Promise<Status> {
201207
} finally {
202208
// Cleans up temporary files/folders and restores the git state.
203209
info('Running post deployment cleanup jobs… 🗑️')
210+
211+
if (!action.singleCommit) {
212+
info(`Resetting branch and removing artifacts…`)
213+
await execute(
214+
`git checkout -B ${temporaryDeploymentBranch}`,
215+
`${action.workspace}/${temporaryDeploymentDirectory}`,
216+
action.silent
217+
)
218+
219+
await execute(
220+
`git branch -D ${action.branch} --force`,
221+
action.workspace,
222+
action.silent
223+
)
224+
}
225+
204226
await execute(
205227
`git worktree remove ${temporaryDeploymentDirectory} --force`,
206228
action.workspace,
207229
action.silent
208230
)
231+
209232
await rmRF(temporaryDeploymentDirectory)
210233
}
211234
}

0 commit comments

Comments
 (0)