Skip to content

Commit 1e422f5

Browse files
authoredMar 15, 2024
90 tidy up existing input processing functionality (#93)
* Staging * Staging * Some tidying on the way to modular parsers. - Update dependencies - Change email - Adding specific tests for each schema version
1 parent 569c77b commit 1e422f5

16 files changed

+316
-109
lines changed
 

‎.devcontainer/devcontainer.json

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
name: DataDog Service Catalog
3+
on:
4+
push:
5+
workflow_dispatch:
6+
7+
jobs:
8+
automated-testing:
9+
runs-on: ubuntu-latest
10+
steps:
11+
12+
- name: Get current date
13+
id: date
14+
run: echo "date=$(date +'%Y-%m-%d -- %s')" >> $GITHUB_OUTPUT
15+
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: Run CI Tests
20+
env:
21+
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
22+
DATADOG_APPLICATION_KEY: ${{ secrets.DATADOG_APPLICATION_KEY }}
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
run: |
25+
npm install
26+
npm run test
27+
28+
- name: Datadog Service Catalog Metadata Provider Manual Test
29+
uses: ./
30+
with:
31+
schema-version: v2
32+
github-token: ${{ secrets.GITHUB_TOKEN }}
33+
datadog-hostname: api.us5.datadoghq.com
34+
datadog-key: ${{ secrets.DATADOG_API_KEY }}
35+
datadog-app-key: ${{ secrets.DATADOG_APPLICATION_KEY }}
36+
service-name: v2-automated-test
37+
team: Team Name Here
38+
email: team-name-here@fakeemaildomainthatdoesntexist.com
39+
slack-support-channel: 'https://fakeorg.slack.com/archives/A0000000000'
40+
repo: https://github.com/arcxp/datadog-service-catalog-metadata-provider
41+
contacts: |
42+
- name: Testy McTester
43+
type: email
44+
contact: testy@mctester.com
45+
tags: |
46+
- schema-version: v2
47+
- 'application:GitHub Action Config Test'
48+
- intended-env:prod
49+
- infrastructure:serverless
50+
- language:nodejs
51+
- updated:${{ steps.date.outputs.date }}
52+
- internet_accessible: false
53+
repos: |
54+
- name: .github
55+
url: https://github.com/arcxp/.github
56+
provider: github
57+
links: |
58+
- url: https://github.com/actions/toolkit
59+
type: repo
60+
provider: Github
61+
name: '@actions/toolkit'
62+
- name: AMI Version Status Dashboard
63+
url: https://thisisanentirelyfakeurl.seriouslythisisafakehostname.com/dashboard
64+
type: dashboard
65+
- name: GitHub Actions!
66+
url: https://github.com/features/actions
67+
provider: Github Docs
68+
type: doc
69+
- name: Some Runbook
70+
url: https://thisisanentirelyfakeurl.seriouslythisisafakehostname.com/runbook
71+
type: runbook
72+
provider: Confluence
73+
docs: |
74+
- name: Some Docs
75+
url: https://thisisanentirelyfakeurl.seriouslythisisafakehostname.com/docs
76+
provider: Confluence
77+
- name: Datadog Blog
78+
url: https://www.datadoghq.com/blog/
79+
integrations: |
80+
opsgenie:
81+
service-url: https://yourorghere.app.opsgenie.com/service/00000000-0000-0000-0000-000000000000
82+
region: US
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
name: DataDog Service Catalog
3+
on:
4+
push:
5+
workflow_dispatch:
6+
7+
jobs:
8+
automated-testing:
9+
runs-on: ubuntu-latest
10+
steps:
11+
12+
- name: Get current date
13+
id: date
14+
run: echo "date=$(date +'%Y-%m-%d -- %s')" >> $GITHUB_OUTPUT
15+
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: Run CI Tests
20+
env:
21+
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
22+
DATADOG_APPLICATION_KEY: ${{ secrets.DATADOG_APPLICATION_KEY }}
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
run: |
25+
npm install
26+
npm run test
27+
28+
- name: Datadog Service Catalog Metadata Provider Manual Test
29+
uses: ./
30+
with:
31+
schema-version: v2.1
32+
github-token: ${{ secrets.GITHUB_TOKEN }}
33+
datadog-hostname: api.us5.datadoghq.com
34+
datadog-key: ${{ secrets.DATADOG_API_KEY }}
35+
datadog-app-key: ${{ secrets.DATADOG_APPLICATION_KEY }}
36+
service-name: v2.1-automated-test
37+
application: Datadog Service Catalog Metadata Provider
38+
description: This is a test of the Datadog Service Catalog Metadata Provider
39+
lifecycle: production
40+
tier: p3
41+
team: Team Name Here
42+
email: team-name-here@fakeemaildomainthatdoesntexist.com
43+
slack-support-channel: 'https://fakeorg.slack.com/archives/A0000000000'
44+
repo: https://github.com/arcxp/datadog-service-catalog-metadata-provider
45+
tags: |
46+
- schema-version: v2.1
47+
- 'application:GitHub Action Config Test'
48+
- intended-env:prod
49+
- infrastructure:serverless
50+
- language:nodejs
51+
- updated:${{ steps.date.outputs.date }}
52+
- internet_accessible: false
53+
links: |
54+
- url: https://github.com/actions/toolkit
55+
type: repo
56+
provider: Github
57+
name: '@actions/toolkit'
58+
- name: AMI Version Status Dashboard
59+
url: https://thisisanentirelyfakeurl.seriouslythisisafakehostname.com/dashboard
60+
type: dashboard
61+
- name: GitHub Actions!
62+
url: https://github.com/features/actions
63+
provider: Github Docs
64+
type: doc
65+
- name: Some Runbook
66+
url: https://thisisanentirelyfakeurl.seriouslythisisafakehostname.com/runbook
67+
type: runbook
68+
provider: Confluence
69+
- name: Some Docs
70+
url: https://thisisanentirelyfakeurl.seriouslythisisafakehostname.com/docs
71+
type: doc
72+
provider: Confluence
73+
- name: Datadog Blog
74+
type: other
75+
url: https://www.datadoghq.com/blog/
76+
integrations: |
77+
opsgenie:
78+
service-url: https://yourorghere.app.opsgenie.com/service/00000000-0000-0000-0000-000000000000
79+
region: US

‎.github/workflows/automated-testing.yml renamed to ‎.github/workflows/v2.2-automated-testing.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
datadog-hostname: api.us5.datadoghq.com
3434
datadog-key: ${{ secrets.DATADOG_API_KEY }}
3535
datadog-app-key: ${{ secrets.DATADOG_APPLICATION_KEY }}
36-
service-name: datadog-service-catalog-metadata-provider-test
36+
service-name: v2.2-automated-test
3737
application: Datadog Service Catalog Metadata Provider
3838
description: This is a test of the Datadog Service Catalog Metadata Provider
3939
lifecycle: production
@@ -54,6 +54,7 @@ jobs:
5454
- language:nodejs
5555
- updated:${{ steps.date.outputs.date }}
5656
- internet_accessible: false
57+
- schema-version: 2.2
5758
links: |
5859
- url: https://github.com/actions/toolkit
5960
type: repo

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Using a field which is not supported in the schema version you've selected will
8686
| `repos[].name` | The name of the repository. | Yes | | `v2` |
8787
| `repos[].url` | The URL of the repository. | Yes | | `v2` |
8888
| `repos[].provider` | The provider of the repository. Acceptable values are: `Github`. | No | | `v2` |
89-
| `tags` | The list of tags that are associated with the service. This should be a list of key-value pairs separated by colons. | No | |
89+
| `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` |
9090
| `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` |
9191
| `links[].name` | The name of the link. | Yes | | `v2`, `v2.1`, `v2.2` |
9292
| `links[].url` | The URL of the link. | Yes | | `v2`, `v2.1`, `v2.2` |

‎__tests__/lib/fieldMappings-convenience.test.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @fileoverview This test covers all of the field mappings across versions.
33
* @jest-environment node
44
* @group ci
5-
* @author Mike Stemle <themanchicken@duck.com>
5+
* @author Mike Stemle <hello@mikestemle.com>
66
**/
77

88
const core = require('@actions/core')

‎__tests__/lib/fieldMappings-schema.test.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @fileoverview This test covers all of the field mappings across versions.
33
* @jest-environment node
44
* @group ci
5-
* @author Mike Stemle <themanchicken@duck.com>
5+
* @author Mike Stemle <hello@mikestemle.com>
66
**/
77

88
const core = require('@actions/core')

‎__tests__/lib/fieldMappings.test.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @fileoverview This test covers all of the field mappings across versions.
33
* @jest-environment node
44
* @group ci
5-
* @author Mike Stemle <themanchicken@duck.com>
5+
* @author Mike Stemle <hello@mikestemle.com>
66
**/
77

88
const core = require('@actions/core')
@@ -34,4 +34,4 @@ describe('constants', () => {
3434
core.setFailed.mockReset()
3535
core.setFailed.mockClear()
3636
})
37-
})
37+
})

‎__tests__/lib/input-to-registry-document.test.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Tests.
33
* @jest-environment node
44
* @group ci
5-
* @author Mike Stemle <themanchicken@duck.com>
5+
* @author Mike Stemle <hello@mikestemle.com>
66
**/
77

88
const YAML = require('yaml')

‎__tests__/self-workflow-validation.test.cjs

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const path = require('path')
33
process.env.GITHUB_EVENT_PATH = path.join(
44
__dirname,
5-
'./data/github-context-payload.json'
5+
'./data/github-context-payload.json',
66
)
77
process.env.GITHUB_REPOSITORY =
88
'arcxp/datadog-service-catalog-metadata-provider'
@@ -34,20 +34,79 @@ const {
3434
} = require('../lib/org-rules')
3535

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

43-
describe('Read and validate the automated testing workflow', () => {
38+
describe('Validate for schema v2', () => {
39+
const ddSchema_v2 = require('./data/datadog-service-catalog-schema-v2.json')
40+
const validate_v2 = new Ajv({
41+
strict: false,
42+
validateFormats: false,
43+
}).compile(ddSchema_v2)
44+
45+
test('read and validate workflow', async () => {
46+
const workflowContent = await readFile(
47+
'.github/workflows/v2-automated-testing.yml',
48+
{ encoding: 'utf8' },
49+
)
50+
const parsedWorkflow = _.last(
51+
YAML.parse(workflowContent)?.jobs?.['automated-testing']?.steps,
52+
)?.with
53+
54+
core.__setInputsObject(parsedWorkflow)
55+
const serviceDefinition = await inputsToRegistryDocument()
56+
57+
console.log({ parsedWorkflow, serviceDefinition })
58+
const isValid = validate_v2(serviceDefinition)
59+
if (!isValid) {
60+
console.log(validate_v2.errors)
61+
console.log(validate_v2)
62+
}
63+
expect(isValid).toBeTruthy()
64+
})
65+
})
66+
67+
describe('Validate for schema v2.1', () => {
68+
const ddSchema_v2_1 = require('./data/datadog-service-catalog-schema-v2.1.json')
69+
const validate_v2_1 = new Ajv({
70+
strict: false,
71+
validateFormats: false,
72+
}).compile(ddSchema_v2_1)
73+
74+
test('read and validate workflow', async () => {
75+
const workflowContent = await readFile(
76+
'.github/workflows/v2.1-automated-testing.yml',
77+
{ encoding: 'utf8' },
78+
)
79+
const parsedWorkflow = _.last(
80+
YAML.parse(workflowContent)?.jobs?.['automated-testing']?.steps,
81+
)?.with
82+
83+
core.__setInputsObject(parsedWorkflow)
84+
const serviceDefinition = await inputsToRegistryDocument()
85+
86+
console.log({ parsedWorkflow, serviceDefinition })
87+
const isValid = validate_v2_1(serviceDefinition)
88+
if (!isValid) {
89+
console.log(validate_v2_1.errors)
90+
console.log(validate_v2_1)
91+
}
92+
expect(isValid).toBeTruthy()
93+
})
94+
})
95+
96+
describe('Validate for schema v2.2', () => {
97+
const ddSchema_v2_2 = require('./data/datadog-service-catalog-schema-v2.2.json')
98+
const validate_v2_2 = new Ajv({
99+
strict: false,
100+
validateFormats: false,
101+
}).compile(ddSchema_v2_2)
102+
44103
test('read and validate workflow', async () => {
45104
const workflowContent = await readFile(
46-
'.github/workflows/automated-testing.yml',
47-
{ encoding: 'utf8' }
105+
'.github/workflows/v2.2-automated-testing.yml',
106+
{ encoding: 'utf8' },
48107
)
49108
const parsedWorkflow = _.last(
50-
YAML.parse(workflowContent)?.jobs?.['automated-testing']?.steps
109+
YAML.parse(workflowContent)?.jobs?.['automated-testing']?.steps,
51110
)?.with
52111

53112
core.__setInputsObject(parsedWorkflow)

‎action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: 'Datadog Service Catalog Metadata Provider'
33
description: 'This is an action which allows you to provide your Datadog Service Catalog metadata to the Datadog Service Catalog'
4-
author: 'Mike Stemle <themanchicken@duck.com>'
4+
author: 'Mike Stemle <hello@mikestemle.com>'
55
branding:
66
icon: 'monitor'
77
color: 'purple'

0 commit comments

Comments
 (0)