Skip to content

Commit

Permalink
90 tidy up existing input processing functionality (#93)
Browse files Browse the repository at this point in the history
* Staging

* Staging

* Some tidying on the way to modular parsers.
- Update dependencies
- Change email
- Adding specific tests for each schema version
  • Loading branch information
manchicken committed Mar 15, 2024
1 parent 569c77b commit 1e422f5
Show file tree
Hide file tree
Showing 16 changed files with 316 additions and 109 deletions.
14 changes: 0 additions & 14 deletions .devcontainer/devcontainer.json

This file was deleted.

82 changes: 82 additions & 0 deletions .github/workflows/v2-automated-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
name: DataDog Service Catalog
on:
push:
workflow_dispatch:

jobs:
automated-testing:
runs-on: ubuntu-latest
steps:

- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d -- %s')" >> $GITHUB_OUTPUT

- name: Checkout
uses: actions/checkout@v3

- name: Run CI Tests
env:
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
DATADOG_APPLICATION_KEY: ${{ secrets.DATADOG_APPLICATION_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm install
npm run test
- name: Datadog Service Catalog Metadata Provider Manual Test
uses: ./
with:
schema-version: v2
github-token: ${{ secrets.GITHUB_TOKEN }}
datadog-hostname: api.us5.datadoghq.com
datadog-key: ${{ secrets.DATADOG_API_KEY }}
datadog-app-key: ${{ secrets.DATADOG_APPLICATION_KEY }}
service-name: v2-automated-test
team: Team Name Here
email: team-name-here@fakeemaildomainthatdoesntexist.com
slack-support-channel: 'https://fakeorg.slack.com/archives/A0000000000'
repo: https://github.com/arcxp/datadog-service-catalog-metadata-provider
contacts: |
- name: Testy McTester
type: email
contact: testy@mctester.com
tags: |
- schema-version: v2
- 'application:GitHub Action Config Test'
- intended-env:prod
- infrastructure:serverless
- language:nodejs
- updated:${{ steps.date.outputs.date }}
- internet_accessible: false
repos: |
- name: .github
url: https://github.com/arcxp/.github
provider: github
links: |
- url: https://github.com/actions/toolkit
type: repo
provider: Github
name: '@actions/toolkit'
- name: AMI Version Status Dashboard
url: https://thisisanentirelyfakeurl.seriouslythisisafakehostname.com/dashboard
type: dashboard
- name: GitHub Actions!
url: https://github.com/features/actions
provider: Github Docs
type: doc
- name: Some Runbook
url: https://thisisanentirelyfakeurl.seriouslythisisafakehostname.com/runbook
type: runbook
provider: Confluence
docs: |
- name: Some Docs
url: https://thisisanentirelyfakeurl.seriouslythisisafakehostname.com/docs
provider: Confluence
- name: Datadog Blog
url: https://www.datadoghq.com/blog/
integrations: |
opsgenie:
service-url: https://yourorghere.app.opsgenie.com/service/00000000-0000-0000-0000-000000000000
region: US
79 changes: 79 additions & 0 deletions .github/workflows/v2.1-automated-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
name: DataDog Service Catalog
on:
push:
workflow_dispatch:

jobs:
automated-testing:
runs-on: ubuntu-latest
steps:

- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d -- %s')" >> $GITHUB_OUTPUT

- name: Checkout
uses: actions/checkout@v3

- name: Run CI Tests
env:
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
DATADOG_APPLICATION_KEY: ${{ secrets.DATADOG_APPLICATION_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm install
npm run test
- name: Datadog Service Catalog Metadata Provider Manual Test
uses: ./
with:
schema-version: v2.1
github-token: ${{ secrets.GITHUB_TOKEN }}
datadog-hostname: api.us5.datadoghq.com
datadog-key: ${{ secrets.DATADOG_API_KEY }}
datadog-app-key: ${{ secrets.DATADOG_APPLICATION_KEY }}
service-name: v2.1-automated-test
application: Datadog Service Catalog Metadata Provider
description: This is a test of the Datadog Service Catalog Metadata Provider
lifecycle: production
tier: p3
team: Team Name Here
email: team-name-here@fakeemaildomainthatdoesntexist.com
slack-support-channel: 'https://fakeorg.slack.com/archives/A0000000000'
repo: https://github.com/arcxp/datadog-service-catalog-metadata-provider
tags: |
- schema-version: v2.1
- 'application:GitHub Action Config Test'
- intended-env:prod
- infrastructure:serverless
- language:nodejs
- updated:${{ steps.date.outputs.date }}
- internet_accessible: false
links: |
- url: https://github.com/actions/toolkit
type: repo
provider: Github
name: '@actions/toolkit'
- name: AMI Version Status Dashboard
url: https://thisisanentirelyfakeurl.seriouslythisisafakehostname.com/dashboard
type: dashboard
- name: GitHub Actions!
url: https://github.com/features/actions
provider: Github Docs
type: doc
- name: Some Runbook
url: https://thisisanentirelyfakeurl.seriouslythisisafakehostname.com/runbook
type: runbook
provider: Confluence
- name: Some Docs
url: https://thisisanentirelyfakeurl.seriouslythisisafakehostname.com/docs
type: doc
provider: Confluence
- name: Datadog Blog
type: other
url: https://www.datadoghq.com/blog/
integrations: |
opsgenie:
service-url: https://yourorghere.app.opsgenie.com/service/00000000-0000-0000-0000-000000000000
region: US
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
datadog-hostname: api.us5.datadoghq.com
datadog-key: ${{ secrets.DATADOG_API_KEY }}
datadog-app-key: ${{ secrets.DATADOG_APPLICATION_KEY }}
service-name: datadog-service-catalog-metadata-provider-test
service-name: v2.2-automated-test
application: Datadog Service Catalog Metadata Provider
description: This is a test of the Datadog Service Catalog Metadata Provider
lifecycle: production
Expand All @@ -54,6 +54,7 @@ jobs:
- language:nodejs
- updated:${{ steps.date.outputs.date }}
- internet_accessible: false
- schema-version: 2.2
links: |
- url: https://github.com/actions/toolkit
type: repo
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Using a field which is not supported in the schema version you've selected will
| `repos[].name` | The name of the repository. | Yes | | `v2` |
| `repos[].url` | The URL of the repository. | Yes | | `v2` |
| `repos[].provider` | The provider of the repository. Acceptable values are: `Github`. | No | | `v2` |
| `tags` | The list of tags that are associated with the service. This should be a list of key-value pairs separated by colons. | No | |
| `tags` | The list of tags that are associated with the service. This should be a list of key-value pairs separated by colons. | No | `v2`, `v2.1`, `v2.2` |
| `links` | A list of links associated with the service. These links are objects with a variety of properties, but due to the limitations of GitHub Actions, please supply these object properties as a multi-line string. | No | `[]` | `v2`, `v2.1`, `v2.2` |
| `links[].name` | The name of the link. | Yes | | `v2`, `v2.1`, `v2.2` |
| `links[].url` | The URL of the link. | Yes | | `v2`, `v2.1`, `v2.2` |
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lib/fieldMappings-convenience.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @fileoverview This test covers all of the field mappings across versions.
* @jest-environment node
* @group ci
* @author Mike Stemle <themanchicken@duck.com>
* @author Mike Stemle <hello@mikestemle.com>
**/

const core = require('@actions/core')
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lib/fieldMappings-schema.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @fileoverview This test covers all of the field mappings across versions.
* @jest-environment node
* @group ci
* @author Mike Stemle <themanchicken@duck.com>
* @author Mike Stemle <hello@mikestemle.com>
**/

const core = require('@actions/core')
Expand Down
4 changes: 2 additions & 2 deletions __tests__/lib/fieldMappings.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @fileoverview This test covers all of the field mappings across versions.
* @jest-environment node
* @group ci
* @author Mike Stemle <themanchicken@duck.com>
* @author Mike Stemle <hello@mikestemle.com>
**/

const core = require('@actions/core')
Expand Down Expand Up @@ -34,4 +34,4 @@ describe('constants', () => {
core.setFailed.mockReset()
core.setFailed.mockClear()
})
})
})
2 changes: 1 addition & 1 deletion __tests__/lib/input-to-registry-document.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Tests.
* @jest-environment node
* @group ci
* @author Mike Stemle <themanchicken@duck.com>
* @author Mike Stemle <hello@mikestemle.com>
**/

const YAML = require('yaml')
Expand Down
79 changes: 69 additions & 10 deletions __tests__/self-workflow-validation.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const path = require('path')
process.env.GITHUB_EVENT_PATH = path.join(
__dirname,
'./data/github-context-payload.json'
'./data/github-context-payload.json',
)
process.env.GITHUB_REPOSITORY =
'arcxp/datadog-service-catalog-metadata-provider'
Expand Down Expand Up @@ -34,20 +34,79 @@ const {
} = require('../lib/org-rules')

const Ajv = require('ajv')
const ddSchema_v2_2 = require('./data/datadog-service-catalog-schema-v2.2.json')
const validate_v2_2 = new Ajv({
strict: false,
validateFormats: false,
}).compile(ddSchema_v2_2)

describe('Read and validate the automated testing workflow', () => {
describe('Validate for schema v2', () => {
const ddSchema_v2 = require('./data/datadog-service-catalog-schema-v2.json')
const validate_v2 = new Ajv({
strict: false,
validateFormats: false,
}).compile(ddSchema_v2)

test('read and validate workflow', async () => {
const workflowContent = await readFile(
'.github/workflows/v2-automated-testing.yml',
{ encoding: 'utf8' },
)
const parsedWorkflow = _.last(
YAML.parse(workflowContent)?.jobs?.['automated-testing']?.steps,
)?.with

core.__setInputsObject(parsedWorkflow)
const serviceDefinition = await inputsToRegistryDocument()

console.log({ parsedWorkflow, serviceDefinition })
const isValid = validate_v2(serviceDefinition)
if (!isValid) {
console.log(validate_v2.errors)
console.log(validate_v2)
}
expect(isValid).toBeTruthy()
})
})

describe('Validate for schema v2.1', () => {
const ddSchema_v2_1 = require('./data/datadog-service-catalog-schema-v2.1.json')
const validate_v2_1 = new Ajv({
strict: false,
validateFormats: false,
}).compile(ddSchema_v2_1)

test('read and validate workflow', async () => {
const workflowContent = await readFile(
'.github/workflows/v2.1-automated-testing.yml',
{ encoding: 'utf8' },
)
const parsedWorkflow = _.last(
YAML.parse(workflowContent)?.jobs?.['automated-testing']?.steps,
)?.with

core.__setInputsObject(parsedWorkflow)
const serviceDefinition = await inputsToRegistryDocument()

console.log({ parsedWorkflow, serviceDefinition })
const isValid = validate_v2_1(serviceDefinition)
if (!isValid) {
console.log(validate_v2_1.errors)
console.log(validate_v2_1)
}
expect(isValid).toBeTruthy()
})
})

describe('Validate for schema v2.2', () => {
const ddSchema_v2_2 = require('./data/datadog-service-catalog-schema-v2.2.json')
const validate_v2_2 = new Ajv({
strict: false,
validateFormats: false,
}).compile(ddSchema_v2_2)

test('read and validate workflow', async () => {
const workflowContent = await readFile(
'.github/workflows/automated-testing.yml',
{ encoding: 'utf8' }
'.github/workflows/v2.2-automated-testing.yml',
{ encoding: 'utf8' },
)
const parsedWorkflow = _.last(
YAML.parse(workflowContent)?.jobs?.['automated-testing']?.steps
YAML.parse(workflowContent)?.jobs?.['automated-testing']?.steps,
)?.with

core.__setInputsObject(parsedWorkflow)
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: 'Datadog Service Catalog Metadata Provider'
description: 'This is an action which allows you to provide your Datadog Service Catalog metadata to the Datadog Service Catalog'
author: 'Mike Stemle <themanchicken@duck.com>'
author: 'Mike Stemle <hello@mikestemle.com>'
branding:
icon: 'monitor'
color: 'purple'
Expand Down
Loading

0 comments on commit 1e422f5

Please sign in to comment.