Skip to content
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

Changed the task output #4

Merged
merged 12 commits into from
Dec 9, 2022
16 changes: 15 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,18 @@ jobs:
server_task_id: ${{ steps.npm_tests.outputs.gha_selftest_server_task_id }} # see integration.test.ts

- name: Echo success status from self-test
run: echo "Deployment succeeded = [${{ steps.self_test.outputs.completed_successfully }}]"
run: echo "Deployment succeeded = [${{ steps.self_test.outputs.task_state }}]"

- name: GitHub Action self-test-2
id: self_test_2
uses: ./
continue-on-error: true
env:
OCTOPUS_URL: ${{ env.SERVER_URL }}
OCTOPUS_API_KEY: ${{ env.ADMIN_API_KEY }}
OCTOPUS_SPACE: 'Default'
with:
server_task_id: 'ServerTasks-99999'

- name: Echo success status from self-test-2
run: echo "Deployment succeeded = [${{ steps.self_test_2.outputs.task_state }}]"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ steps:

## 📤 Outputs

| Name | Description |
| :----------------------- | :----------------------------------------------------------------- |
| `completed_successfully` | Boolean indicating whether the task completed successfully or not. |
| Name | Description |
| :----------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `task_state` | The final [TaskState](https://github.com/OctopusDeploy/api-client.ts/blob/main/src/features/serverTasks/taskState.ts) returned from Octopus, or undefined if Octopus couldn't be contacted to retrieve the state |

## 🤝 Contributions

Expand Down
7 changes: 4 additions & 3 deletions __tests__/integration/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
RunCondition,
RunConditionForAction,
SpaceRepository,
StartTrigger
StartTrigger,
TaskState
} from '@octopusdeploy/api-client'
import { randomBytes } from 'crypto'
import { setOutput } from '@actions/core'
Expand Down Expand Up @@ -225,9 +226,9 @@ describe('integration tests', () => {
const space = (await spaceRepository.list({ partialName: spaceName })).Items[0]

// The first release in the project, so it should always have 0.0.1
expect(result).toBe(true)
expect(result).toBe(TaskState.Success)
expect(output.getAllMessages()).toContain(
`[INFO] 🐙 waiting for task [${standardInputParameters.serverTaskId}](${standardInputParameters.server}/app#/${space.Id}/tasks/${standardInputParameters.serverTaskId}) in Octopus Deploy...`
`[INFO] 🐙 waiting for task ${standardInputParameters.server}/app#/${space.Id}/tasks/${standardInputParameters.serverTaskId} in Octopus Deploy...`
)

// re-queue another deployment to the same environment, which the self test is going to wait for via localServerTaskId
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ inputs:
description: 'The name of a space within which this command will be executed. The space name is required, but you may also use the OCTOPUS_SPACE environment variable.'

outputs:
completed_successfully:
description: 'Boolean indicating whether the task completed successfully or not.'
task_state:
description: 'The final TaskState returned from Octopus, or undefined if Octopus could not be contacted to retrieve the state'
slewis74 marked this conversation as resolved.
Show resolved Hide resolved

runs:
using: 'node16'
Expand Down
7,775 changes: 4,034 additions & 3,741 deletions dist/index.js

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@actions/core": "^1.10.0",
"@octopusdeploy/api-client": "^2.0.0",
"@octopusdeploy/api-client": "github:OctopusDeploy/api-client.ts#bug-waiterrorhandling",
slewis74 marked this conversation as resolved.
Show resolved Hide resolved
"tmp": "^0.2.1"
},
"description": "GitHub Action to Create a Release in Octopus Deploy",
Expand Down
6 changes: 3 additions & 3 deletions src/api-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export interface DeploymentResult {
environmentName: string
}

export async function waitForTask(client: Client, parameters: InputParameters): Promise<boolean> {
export async function waitForTask(client: Client, parameters: InputParameters): Promise<TaskState | undefined> {
const spaceId = await resolveSpaceId(client, parameters.space)
client.info(
`🐙 waiting for task [${parameters.serverTaskId}](${parameters.server}/app#/${spaceId}/tasks/${parameters.serverTaskId}) in Octopus Deploy...`
`🐙 waiting for task ${parameters.server}/app#/${spaceId}/tasks/${parameters.serverTaskId} in Octopus Deploy...`
)

const waiter = new ServerTaskWaiter(client, parameters.space)
Expand All @@ -26,5 +26,5 @@ export async function waitForTask(client: Client, parameters: InputParameters):
}
)

return serverTask?.State === TaskState.Success
return serverTask?.State
}
18 changes: 12 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getInputParameters } from './input-parameters'
import { debug, info, warning, error, setFailed, setOutput, isDebug } from '@actions/core'
import { writeFileSync } from 'fs'
import { Client, ClientConfiguration, Logger } from '@octopusdeploy/api-client'
import { Client, ClientConfiguration, Logger, TaskState } from '@octopusdeploy/api-client'
import { waitForTask } from './api-wrapper'

// GitHub actions entrypoint
Expand Down Expand Up @@ -35,20 +35,26 @@ import { waitForTask } from './api-wrapper'

const client = await Client.create(config)

const completedSuccessfully = await waitForTask(client, parameters)
const taskState = await waitForTask(client, parameters)

setOutput('completed_successfully', completedSuccessfully)
setOutput('task_state', taskState)

const stepSummaryFile = process.env.GITHUB_STEP_SUMMARY
if (stepSummaryFile) {
writeFileSync(
stepSummaryFile,
`🐙 Octopus Deploy task ${completedSuccessfully ? 'completed successfully' : 'did not complete successfully'}.`
`🐙 Octopus Deploy task ${
taskState === TaskState.Success ? 'completed successfully' : 'did not complete successfully'
}.`
)
}

if (!completedSuccessfully) {
setFailed('🐙 Octopus Deploy task did not complete successfully')
if (taskState !== TaskState.Success) {
if (taskState) {
setFailed(`🐙 Octopus Deploy task did not complete successfully (state: ${taskState})`)
} else {
setFailed('🐙 Could not determine Octopus Deploy task state')
}
}
} catch (e: unknown) {
if (e instanceof Error) {
Expand Down