generated from im-open/javascript-action-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Added deployment unit and integration testing #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3815f8c
- Added deployment unit and integration testing
hpractv 9f5d301
Update transpiled build script
hpractv d1739a3
Update transpiled build script
hpractv 9deb3e9
Trying to get the build script to register in the check
hpractv 16d89b7
PR comment changes
hpractv 9e99ad5
spelling fix
hpractv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -70,7 +70,7 @@ jobs: | |
- name: Create GitHub Deployment | ||
id: defaults | ||
continue-on-error: true # Setting to true so the job doesn't fail if updating the board fails. | ||
uses: im-open/[email protected].10 # You may also reference just the major or major.minor version | ||
uses: im-open/[email protected].8 # You may also reference just the major or major.minor version | ||
with: | ||
workflow-actor: ${{ github.actor }} # This will add the user who kicked off the workflow to the deployment payload | ||
token: ${{ secrets.GITHUB_TOKEN }} # If a different token is used, update github-login with the corresponding account | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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,99 @@ | ||
const { describe, test, expect, beforeEach, beforeAll, afterAll } = require('@jest/globals'); | ||
const { | ||
ALLOWED_STATUSES, | ||
WORKFLOW_DEPLOY, | ||
createOctokitClient, | ||
createOctokitGraphQLClient, | ||
getPriorDeployments, | ||
getPriorDeploymentStatuses, | ||
createDeployment | ||
} = require('./deployments.js'); | ||
const { context } = require('./library.js'); | ||
|
||
const token = process.env['GITHUB_TOKEN']; | ||
let octokit; | ||
let octokitGraphQl; | ||
const owner = 'im-open'; | ||
const repo = 'create-github-deployment'; | ||
const create_environment = 'INTEGRATION'; | ||
const pull_environment = 'DEV'; | ||
const entity = 'create-github-deployment'; | ||
const instance = 'action'; | ||
const priorDeployments = []; | ||
const priorDeploymentStatuses = []; | ||
let testDeploymentId = null; | ||
const workflow_actor = 'test-actor'; | ||
|
||
// Create the octokit clients | ||
beforeAll(() => { | ||
octokit = createOctokitClient(token); | ||
octokitGraphQl = createOctokitGraphQLClient(token); | ||
}); | ||
|
||
//clean up test deployment | ||
afterAll(async () => { | ||
if (testDeploymentId !== null) { | ||
setTimeout(async () => { | ||
await octokit.rest.repos.deleteDeployment({ | ||
owner: owner, | ||
repo: repo, | ||
deployment_id: testDeploymentId | ||
}); | ||
octokit = null; | ||
octokitGraphQl = null; | ||
}, 5000); | ||
} | ||
}); | ||
|
||
describe('deployments', () => { | ||
let firstDeploymentId; | ||
|
||
test('get the deployments', async () => { | ||
const deployments = await getPriorDeployments(octokit, entity, instance, { | ||
owner: owner, | ||
repo: repo, | ||
task: WORKFLOW_DEPLOY, | ||
environment: pull_environment, | ||
per_page: 100 | ||
}); | ||
expect(deployments).toBeDefined(); | ||
expect(deployments.length).toBeGreaterThan(0); | ||
expect(deployments[0].payload).toBeDefined(); | ||
firstDeploymentId = deployments[0].node_id; | ||
|
||
priorDeployments.push(...deployments); | ||
}); | ||
|
||
test('get the deployment statuses', async () => { | ||
const statuses = await getPriorDeploymentStatuses(octokitGraphQl, [firstDeploymentId]); | ||
expect(statuses).toBeDefined(); | ||
expect(statuses.length).toBeGreaterThan(0); | ||
|
||
expect(statuses[0].statuses).toBeDefined(); | ||
expect(statuses[0].statuses.nodes).toBeDefined(); | ||
expect(statuses[0].statuses.nodes.length).toBeGreaterThan(0); | ||
|
||
priorDeploymentStatuses.push(...statuses); | ||
}); | ||
|
||
test('create deployment', async () => { | ||
testDeploymentId = await createDeployment( | ||
new context( | ||
workflow_actor, | ||
token, | ||
create_environment, | ||
'v1', | ||
ALLOWED_STATUSES.SUCCESS, | ||
'Testing deployment creation', | ||
entity, | ||
instance, | ||
'https://github.com', | ||
'https://github.com', | ||
owner, | ||
repo | ||
) | ||
); | ||
|
||
expect(Number.isNaN(testDeploymentId)).toBe(false); | ||
}); | ||
}); |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an advantage to defining a function that creates an octokit client as opposed to creating a single client that is passed to the functions that need it? It seems like having a single client that all the different functions use might be better than each function creating its own version of the client.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is getting used by the deployment testing file, too. I wanted to make sure the setting params for these clients were the same in both the runtime code as well as the jest test.