Skip to content

Commit

Permalink
feat!: Update action to use the native API client
Browse files Browse the repository at this point in the history
  • Loading branch information
slewis74 committed Dec 6, 2022
1 parent f1345f3 commit 936b2b9
Show file tree
Hide file tree
Showing 16 changed files with 26,206 additions and 46,390 deletions.
File renamed without changes.
7 changes: 2 additions & 5 deletions .github/workflows/codeql-analysis.yml
Expand Up @@ -19,6 +19,7 @@ on:
branches: [ main ]
schedule:
- cron: '31 23 * * 6'
workflow_dispatch:

jobs:
analyze:
Expand Down Expand Up @@ -46,11 +47,7 @@ jobs:
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql/codeql-config.yml
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
config-file: ./.github/codeql/codeql-config-${{ matrix.language }}.yml

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/test.yml
@@ -1,16 +1,19 @@
name: 'build-test'
on:
push:
branches: '**'
paths-ignore:
- '**/*.md'

schedule:
# Daily 5am australian/brisbane time (7pm UTC)
- cron: '0 19 * * *'
workflow_dispatch:

env:
ADMIN_API_KEY: '${{ secrets.OD_IMAGE_ADMIN_API_KEY }}'
SA_PASSWORD: '${{ secrets.DB_IMAGE_SA_PASSWORD }}'
SERVER_URL: 'http://localhost:8080'

jobs:
test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -50,7 +53,7 @@ jobs:
- name: Compile and run tests
env:
OCTOPUS_TEST_URL: ${{ env.SERVER_URL }}
OCTOPUS_TEST_APIKEY: ${{ env.ADMIN_API_KEY }}
OCTOPUS_TEST_API_KEY: ${{ env.ADMIN_API_KEY }}
run: npm run all

- name: Test Report
Expand All @@ -64,15 +67,14 @@ jobs:
- name: Add server url to CORS
run: |
curl '${{ env.SERVER_URL }}/api/configuration/webportal/values' -X 'PUT' -H 'Content-Type: application/json' -H 'X-Octopus-ApiKey: ${{ env.ADMIN_API_KEY }}' --data-binary '{"Security":{"CorsWhitelist":"http://localhost,${{ env.SERVER_URL }}","ReferrerPolicy":"no-referrer","ContentSecurityPolicyEnabled":true,"HttpStrictTransportSecurityEnabled":false,"HttpStrictTransportSecurityMaxAge":31556926,"XOptions":{"XFrameOptionAllowFrom":null,"XFrameOptions":"None"}}}' -o /dev/null -s -w "%{http_code}\n"
- name: Push build information to Octopus Deploy
uses: ./
env:
OCTOPUS_HOST: ${{ env.SERVER_URL }}
OCTOPUS_URL: ${{ env.SERVER_URL }}
OCTOPUS_API_KEY: ${{ env.ADMIN_API_KEY }}
OCTOPUS_SPACE: 'Spaces-1'
OCTOPUS_SPACE: 'Default'
with:
branch: 'test'
packages: 'Testing'
version: '1.0.0'
debug: true
3 changes: 2 additions & 1 deletion .prettierignore
@@ -1,3 +1,4 @@
dist/
lib/
node_modules/
node_modules/
.github/workflows/
32 changes: 18 additions & 14 deletions README.md
Expand Up @@ -19,9 +19,9 @@ Incorporate the following actions in your workflow to push build information to

```yml
env:
OCTOPUS_URL: ${{ secrets.OCTOPUS_URL }} # address of Octopus Deploy instance (i.e. https://demo.octopus.app)
OCTOPUS_API_KEY: ${{ secrets.OCTOPUS_API_KEY }} # API key used with Octopus Deploy instance
OCTOPUS_HOST: ${{ secrets.OCTOPUS_HOST }} # address of Octopus Deploy instance (i.e. https://demo.octopus.app)
OCTOPUS_SPACE: '<spacename>' # or you can specify a Space ID
OCTOPUS_SPACE: '<spacename>' # or you can specify a Space ID
steps:
- uses: actions/checkout@v2
- name: Push build information to Octopus Deploy 🐙
Expand All @@ -32,22 +32,26 @@ steps:
version: '<versionofpackages>'
```

## 📥 Inputs
## 📥 Environment Variables

The following inputs are required:
| Name | Description |
| :---------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------- |
| `OCTOPUS_URL` | The base URL hosting Octopus Deploy (i.e. `https://octopus.example.com`). It is strongly recommended that this value retrieved from a GitHub secret. |
| `OCTOPUS_API_KEY` | The API key used to access Octopus Deploy. It is strongly recommended that this value retrieved from a GitHub secret. |
| `OCTOPUS_SPACE` | The Name of a space within which this command will be executed. |

| Name | Description | Default |
| :--------- | :------------------------------------------------------------------------- | :-----: |
| `packages` | A multi-line list of packages to push build information to Octopus Deploy. | |
| `version` | The version of the package(s). | |
## 📥 Inputs

The following inputs are optional:
| Name | Description |
| :--------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `packages` | A multi-line list of packages to push build information to Octopus Deploy. |
| `version` | The version of the package(s). |
| `branch` | The branch name, if omitted the GitHub ref will be used. |
| `overwrite_mode` | Determines the action to perform with build information if it already exists in the repository. Valid input values are `FailIfExists` (default), `OverwriteExisting`, and `IgnoreIfExists`. |
| `server` | The instance URL hosting Octopus Deploy (i.e. "https://octopus.example.com/"). The instance URL is required, but you may also use the OCTOPUS_URL environment variable. |
| `api_key` | The API key used to access Octopus Deploy. An API key is required, but you may also use the OCTOPUS_API_KEY environment variable. It is strongly recommended that this value retrieved from a GitHub secret. |
| `space` | 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. |

| Name | Description | Default |
| :--------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------: |
| `branch` | The branch name, if omitted the GitHub ref will be used. | |
| `debug` | Logs the build information data. | `false` |
| `overwrite_mode` | Determines the action to perform with build information if it already exists in the repository. Valid input values are `FailIfExists`, `OverwriteExisting`, and `IgnoreIfExists`. | `FailIfExists` |
## 🤝 Contributions

Contributions are welcome! :heart: Please read our [Contributing Guide](.github/CONTRIBUTING.md) for information about how to get involved in this project.
38 changes: 35 additions & 3 deletions __tests__/main.test.ts
@@ -1,21 +1,53 @@
import { context } from '@actions/github'
import { Client, ClientConfiguration, Logger } from '@octopusdeploy/api-client'
import * as inputs from '../src/input-parameters'
import * as octopus from '../src/push-build-information'
import { CaptureOutput } from './test-helpers'

const apiClientConfig: ClientConfiguration = {
userAgentApp: 'Test',
apiKey: process.env.OCTOPUS_TEST_API_KEY || 'API-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
instanceURL: process.env.OCTOPUS_TEST_URL || 'http://localhost:8050'
}

describe('inputs', () => {
it('successfully get input parameters', async () => {
const inputParameters = inputs.get()
const inputParameters = inputs.get(false)
expect(inputParameters != undefined)
}, 100000)
})

describe('build information', () => {
it('successfully pushes build information', async () => {
const inputParameters = inputs.get()
const output = new CaptureOutput()

const logger: Logger = {
debug: message => output.debug(message),
info: message => output.info(message),
warn: message => output.warn(message),
error: (message, err) => {
if (err !== undefined) {
output.error(err.message)
} else {
output.error(message)
}
}
}

const config: ClientConfiguration = {
userAgentApp: 'Test',
instanceURL: apiClientConfig.instanceURL,
apiKey: apiClientConfig.apiKey,
logging: logger
}

const client = await Client.create(config)

const inputParameters = inputs.get(false)
const runId = context.runId
if (runId === undefined) {
throw new Error('GitHub run number is not defined')
}
await octopus.pushBuildInformation(runId, inputParameters)
await octopus.pushBuildInformationFromInputs(client, runId, inputParameters)
}, 100000)
})
24 changes: 24 additions & 0 deletions __tests__/test-helpers.ts
@@ -0,0 +1,24 @@
export class CaptureOutput {
msgs: string[]

constructor() {
this.msgs = []
}

debug(message: string): void {
this.msgs.push(`[DEBUG] ${message}`)
}
info(message: string): void {
this.msgs.push(`[INFO] ${message}`)
}
warn(message: string): void {
this.msgs.push(`[WARN] ${message}`)
}
error(message: string): void {
this.msgs.push(`[ERROR] ${message}`)
}

getAllMessages(): string[] {
return this.msgs
}
}
19 changes: 11 additions & 8 deletions action.yml
Expand Up @@ -6,18 +6,21 @@ branding:
icon: 'package'

inputs:
branch:
description: 'The branch name, if omitted the GitHub ref will be used.'
debug:
default: false
description: 'Enable debug logging.'
overwrite_mode:
default: 'FailIfExists'
description: 'Determines the action to perform with build information if it already exists in the repository. Valid values are "FailIfExists", "OverwriteExisting", and "IgnoreIfExists".'
packages:
description: 'A multi-line list of packages to push to Octopus Deploy.'
version:
description: 'The version of the package(s)'
overwrite_mode:
default: 'FailIfExists'
description: 'Determines the action to perform with build information if it already exists in the repository. Valid values are "FailIfExists", "OverwriteExisting", and "IgnoreIfExists".'
branch:
description: 'The branch name, if omitted the GitHub ref will be used.'
api_key:
description: 'The API key used to access Octopus Deploy. You must provide an API key or username and password. If the guest account is enabled, a key of API-GUEST may be used. It is strongly recommended that this value retrieved from a GitHub secret.'
server:
description: 'The base URL hosting Octopus Deploy (i.e. "https://octopus.example.com/"). It is recommended to retrieve this value from an environment variable.'
space:
description: 'The name or ID of a space within which this command will be executed. If omitted, the default space will be used.'

runs:
using: 'node16'
Expand Down

0 comments on commit 936b2b9

Please sign in to comment.