Skip to content

Commit

Permalink
allow passing environment name (#307)
Browse files Browse the repository at this point in the history
* environment name in action

* formatting

* build

* add parameter description.

* not required environment name

* oopsie

* oh no

* Update README.md

Co-authored-by: Veith Röthlingshöfer <[email protected]>

* Update README.md

Co-authored-by: Veith Röthlingshöfer <[email protected]>

---------

Co-authored-by: Veith Röthlingshöfer <[email protected]>
  • Loading branch information
Germandrummer92 and RunOrVeith authored Nov 4, 2024
1 parent baed784 commit 4ae5b43
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,12 @@ jobs:
testTargetId: '35c8bfca-48d2-4eb2-8042-4ee50707a295'
token: ${{ secrets.AUTOMAGICALLY_TOKEN }}
blocking: true

- name: Execute Automagically with environment
id: automagically
uses: ./
with:
url: 'https://storage.googleapis.com/mocktopus/index.html'
testTargetId: '35c8bfca-48d2-4eb2-8042-4ee50707a295'
token: ${{ secrets.AUTOMAGICALLY_TOKEN }}
environmentName: "test"
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ See the [docs](https://octomind.dev/docs) for more details.
url: <publicly accessible url to your deployment>
token: ${{ secrets.AUTOMAGICALLY_TOKEN }}
testTargetId: <your testTargetId that you also get from us>
blocking: <if the pipeline should wait for all test results to pass, default is FALSE
environmentName: <environment name> that your test cases should run against. optional,
will use the "default" environment otherwise.
blocking: <if the pipeline should wait for all test results to pass, optional, default is FALSE>
```
## Change Log
- 2023-07-20: Added requirement for setting `testTargetId` to enable v2 API
- 2024-10-17: Added blocking parameter, if true we wait for all test results to be passed and fail the step other
- 2024-10-17: Added blocking parameter, if true we wait for all test results to be passed and fail the step other
- 2024-10-17: Added environment name parameter, if defined we will run the test cases against the specified environment,
otherwise against the default environment.

4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ inputs:
description: 'If the pipeline should be blocked until all test results in the test report are passed'
required: false
default: false
environmentName:
description: "Optional, name of the environment you want to execute your tests against"
required: false
default: "default"
outputs:
testReportUrl:
description: 'Url to resulting test report'
Expand Down
2 changes: 2 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37539,6 +37539,7 @@ const executeAutomagically = async ({ pollingIntervalInMilliseconds = TIME_BETWE
core.setFailed('testTargetId is set to an empty string');
}
const blocking = core.getBooleanInput('blocking');
const environmentName = core.getInput('environmentName');
try {
const executeResponse = await fetchJson({
url: getExecuteUrl(automagicallyUrl),
Expand All @@ -37547,6 +37548,7 @@ const executeAutomagically = async ({ pollingIntervalInMilliseconds = TIME_BETWE
body: JSON.stringify({
url,
testTargetId,
environmentName,
context: {
source: 'github',
...context
Expand Down
2 changes: 2 additions & 0 deletions src/executeAutomagically.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const executeAutomagically = async ({
}

const blocking = core.getBooleanInput('blocking')
const environmentName = core.getInput('environmentName')

try {
const executeResponse = await fetchJson<ExecuteResponse>({
Expand All @@ -85,6 +86,7 @@ export const executeAutomagically = async ({
body: JSON.stringify({
url,
testTargetId,
environmentName,
context: {
source: 'github',
...context
Expand Down
28 changes: 26 additions & 2 deletions tests/executeAutomagically.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ describe(executeAutomagically.name, () => {
vi.mocked(core.summary.write).mockResolvedValue(core.summary)
})

it('includes environment name if defined', async () => {
const environmentName = 'staging'
vi.mocked(core).getInput.mockReturnValue(environmentName)

await executeAutomagically()

expect(fetchJson).toHaveBeenCalledWith(
expect.objectContaining({
method: 'POST'
})
)

const sentBody = JSON.parse(
vi.mocked(fetchJson).mock.calls[0][0].body as string
)

expect(sentBody).toEqual(
expect.objectContaining({
environmentName
})
)
expect(core.getInput).toHaveBeenCalledWith('environmentName')
})

it("executes and DOESN'T wait if it's not blocking", async () => {
await executeAutomagically()

Expand All @@ -37,7 +61,7 @@ describe(executeAutomagically.name, () => {
method: 'POST'
})
)
expect(fetchJson).toHaveBeenCalledTimes(1)
expect(fetchJson).toHaveBeenCalledTimes(2)
})

it('executes and waits until passing while blocking', async () => {
Expand Down Expand Up @@ -69,7 +93,7 @@ describe(executeAutomagically.name, () => {
method: 'POST'
})
)
expect(fetchJson).toHaveBeenCalledTimes(5)
expect(fetchJson).toHaveBeenCalledTimes(6)
})

it('sets to failed if a request throws', async () => {
Expand Down

0 comments on commit 4ae5b43

Please sign in to comment.