-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: wait for deployments to be ready
- Loading branch information
1 parent
833d8ed
commit 8b75e27
Showing
9 changed files
with
204 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import core from '@actions/core' | ||
import axios from 'axios' | ||
|
||
export default async function waitForDeployment( | ||
token, | ||
accountId, | ||
accountEmail, | ||
projectId, | ||
deploymentId | ||
) { | ||
const apiUrl = `https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectId}/deployments` | ||
|
||
core.info(`Checking deployment status: ${deploymentId}`) | ||
|
||
const { data } = await axios.get(apiUrl, { | ||
headers: { | ||
'X-Auth-Key': token, | ||
'X-Auth-Email': accountEmail | ||
}, | ||
responseType: 'json', | ||
responseEncoding: 'utf8' | ||
}) | ||
|
||
const build = data.result.filter((d) => d.id === deploymentId)[0] | ||
|
||
if (!build) { | ||
core.error(data) | ||
core.setFailed('no build with this ID found.') | ||
} | ||
|
||
return ( | ||
build.latest_stage.name === 'deploy' && | ||
build.latest_stage.status === 'success' | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* eslint-disable node/no-unsupported-features/es-syntax */ | ||
import checkDeploymentStatus from '../cloudflare-statuscheck.mjs' | ||
import axios from 'axios' | ||
|
||
jest.mock('@actions/core', () => { | ||
return { | ||
info: jest.fn() | ||
} | ||
}) | ||
jest.mock('axios') | ||
|
||
test('waitForDeployment() should wait until a deployment is successful', async () => { | ||
axios.get.mockResolvedValueOnce({ | ||
data: { | ||
result: [ | ||
{ | ||
id: '123abc', | ||
environment: 'preview', | ||
latest_stage: { | ||
name: 'deploy', | ||
status: 'initialized' | ||
} | ||
} | ||
] | ||
} | ||
}) | ||
|
||
axios.get.mockResolvedValueOnce({ | ||
data: { | ||
result: [ | ||
{ | ||
id: '123abc', | ||
environment: 'preview', | ||
latest_stage: { | ||
name: 'deploy', | ||
status: 'success' | ||
} | ||
} | ||
] | ||
} | ||
}) | ||
|
||
const firstCheck = await checkDeploymentStatus( | ||
'123xyz', | ||
'zentered', | ||
'[email protected]', | ||
'cf-project', | ||
'123abc' | ||
) | ||
|
||
const secondCheck = await checkDeploymentStatus( | ||
'123xyz', | ||
'zentered', | ||
'[email protected]', | ||
'cf-project', | ||
'123abc' | ||
) | ||
expect(firstCheck).toEqual(false) | ||
expect(secondCheck).toEqual(true) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters