Skip to content

Commit

Permalink
Checkin
Browse files Browse the repository at this point in the history
- Started work on versioning.
- Trying to get the Codespaces workflow going
  • Loading branch information
manchicken committed Jun 16, 2023
1 parent b08309c commit cfb69c2
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 113 deletions.
53 changes: 31 additions & 22 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ runs:
using: node16
main: dist/index.js
inputs:


# Stuff we need for this action
github-token:
description: 'The GitHub token to use for the action; default is `secrets.GITHUB_TOKEN`'
required: false
org-rules-file:
description: 'The path to the org rules file; default is repository `ORG-NAME-HERE/.github` and the `service-catalog-rules.yml` file is expected in the root of that repository.'
required: false

# Stuff we need for the Datadog API
datadog-hostname:
description: 'The Datadog API hostname (this varies by Datadog customer!)'
required: true
Expand All @@ -27,6 +28,8 @@ inputs:
datadog-app-key:
description: 'The Datadog Application key'
required: true

# Fields which are common to all schema versions
schema-version:
description: 'The version of the Datadog Service Catalog Schema. The default is v2. Valid values are `v2` and `v2.1`.'
required: false
Expand All @@ -36,7 +39,29 @@ inputs:
required: true
team:
description: 'The team responsible for the service'
required: true
required: false
contacts:
description: 'The contacts for the service'
required: false
tags:
description: 'The tags to apply to the service'
required: false
links:
description: 'The links to related to the service'
required: false
integrations:
description: 'The integrations for the service'
required: false

# Fields which are unique to v2
docs:
description: 'The documentation for the service'
required: false
repos:
description: 'The repositories for the service'
required: false

# Fields which are unique to v2.1
application:
description: '(v2.1 only) The name of the application that the service belongs to.'
required: false
Expand All @@ -49,6 +74,8 @@ inputs:
lifecycle:
description: '(v2.1 only) The current life cycle phase of the service. For example: sandbox, staging, production, deprecated'
required: false

# These are convenience inputs which are unique to this action.
email:
description: 'The email address of the team responsible for the service'
required: true
Expand All @@ -57,22 +84,4 @@ inputs:
required: false
repo:
description: 'The repository URL for the service. This is a convenience input for when you only have one repository for the service.'
required: false
contacts:
description: 'The contacts for the service'
required: false
repos:
description: 'The repositories for the service'
required: true
tags:
description: 'The tags to apply to the service'
required: false
links:
description: 'The links to related to the service'
required: false
docs:
description: 'The documentation for the service'
required: false
integrations:
description: 'The integrations for the service'
required: false
required: false
27 changes: 18 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
/***/ 8454:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

/**
* input-expander.js
* DDSCMP
* @desc This module contains all of the functions which expand scalar
* input from GitHub Actions into hydrated structures for the DD API.
*
* @author Michael D. Stemle, Jr
*/

const core = __nccwpck_require__(2186)
const YAML = __nccwpck_require__(4083)

Expand Down Expand Up @@ -204,7 +213,7 @@ module.exports = { inputsToRegistryDocument }
*/
const validateDatadogHostname = (ddHost) => {
// Verify the host.
if (!ddHost || !ddHost.match(/^[a-z0-9.-]+\.datadoghq\.(com|eu|us)$/)) {
if (!ddHost || !ddHost.match(/^[a-z0-9.-]+\.(datadoghq\.(com|eu|us)|ddog-gov\.com)$/)) {
throw new Error(
`Invalid DataDog host: ${ddHost}. See here for more details: https://docs.datadoghq.com/getting_started/site/`,
)
Expand Down Expand Up @@ -32499,7 +32508,7 @@ const prettifyError = (src, lc) => (error) => {
let count = 1;
const end = error.linePos[1];
if (end && end.line === line && end.col > col) {
count = Math.min(end.col - col, 80 - ci);
count = Math.max(1, Math.min(end.col - col, 80 - ci));
}
const pointer = ' '.repeat(ci) + '^'.repeat(count);
error.message += `:\n\n${lineStr}\n${pointer}\n`;
Expand Down Expand Up @@ -37408,7 +37417,7 @@ function stringifyFlowCollection({ comment, items }, ctx, { flowChars, itemInden
}
}
if (comment) {
str += stringifyComment.lineComment(str, commentString(comment), indent);
str += stringifyComment.lineComment(str, indent, commentString(comment));
if (onComment)
onComment();
}
Expand Down Expand Up @@ -37758,8 +37767,8 @@ exports.stringifyPair = stringifyPair;
var Scalar = __nccwpck_require__(9338);
var foldFlowLines = __nccwpck_require__(2889);

const getFoldOptions = (ctx) => ({
indentAtStart: ctx.indentAtStart,
const getFoldOptions = (ctx, isBlock) => ({
indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
lineWidth: ctx.options.lineWidth,
minContentWidth: ctx.options.minContentWidth
});
Expand Down Expand Up @@ -37872,7 +37881,7 @@ function doubleQuotedString(value, ctx) {
str = start ? str + json.slice(start) : json;
return implicitKey
? str
: foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx));
: foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx, false));
}
function singleQuotedString(value, ctx) {
if (ctx.options.singleQuote === false ||
Expand All @@ -37884,7 +37893,7 @@ function singleQuotedString(value, ctx) {
const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
return ctx.implicitKey
? res
: foldFlowLines.foldFlowLines(res, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
: foldFlowLines.foldFlowLines(res, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx, false));
}
function quotedString(value, ctx) {
const { singleQuote } = ctx.options;
Expand Down Expand Up @@ -37982,7 +37991,7 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
.replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
// ^ more-ind. ^ empty ^ capture next empty lines only at end of indent
.replace(/\n+/g, `$&${indent}`);
const body = foldFlowLines.foldFlowLines(`${start}${value}${end}`, indent, foldFlowLines.FOLD_BLOCK, getFoldOptions(ctx));
const body = foldFlowLines.foldFlowLines(`${start}${value}${end}`, indent, foldFlowLines.FOLD_BLOCK, getFoldOptions(ctx, true));
return `${header}\n${indent}${body}`;
}
function plainString(item, ctx, onComment, onChompKeep) {
Expand Down Expand Up @@ -38032,7 +38041,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
}
return implicitKey
? str
: foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
: foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx, false));
}
function stringifyString(item, ctx, onComment, onChompKeep) {
const { implicitKey, inFlow } = ctx;
Expand Down
61 changes: 61 additions & 0 deletions lib/fieldMappings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const { expandObjectInputs, forceArray, forceObject } = require('./input-expander')

const useSharedMappings = (versions, mapper) => Object.assign(...versions.map((x) => ({ [x]: mapper })))

const passThru = (value) => value


/**
* This is the list of mappings which tracks which fields map to different versions in different ways.
* - Keyed by the GitHub Actions input name (action.yml)
* - Values are objects keyed with version tags
* - Values of those objects are the function which maps the input value to the registry document value.
**/
const mappings = {

'github-token': {
'v2
},
'org-rules-file': {},
'datadog-hostname': {},
'datadog-key': {},
'datadog-app-key': {},
'schema-version': {},
'service-name': {},
'team': {},
'contacts': {},
'tags': {},
'links': {},
'integrations': {},
'docs': {},
'repo': {},
'application': {},
'description': {},
'tier': {},
'lifecycle': {},
'email': {},
'slack-support-channel': {},
'repo': {},
}

module.exports = { mappings }
53 changes: 52 additions & 1 deletion lib/input-expander.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
const core = require('@actions/core')
const YAML = require('yaml')

/*
/**
* As part of our recursive implementation, we need
* to engage in a little bit of type inference.
* @private
* @param {string} x - The input value.
* @returns {Object|Symbol} The parsed YAML object, or a Symbol.
*/
const parseSafely = (x) => {
try {
Expand All @@ -21,11 +24,38 @@ const parseSafely = (x) => {
return Symbol('This will never match.')
}
}

/**
* As part of our recursive implementation, we need to be able to break down different types. This tells us if it's an Array.
* @returns {boolean} Whether or not the input is an array.
* @private
**/
const isArray = Array.isArray

/**
* As part of our recursive implementation, we need to be able to break down different types. This tells us if it's an Object.
* @param {Object} x - The input value.
* @returns {boolean} Whether or not the input is an object.
* @private
**/
const isObject = (x) => x?.constructor === Object
// this is because `YAML.parse(1)` returns `null`.

/**
* As part of our recursive implementation, we need to be able to break down different types. This tells us if it's a scalar or scalar equivalent.
* @param {any} x - The input value.
* @returns {boolean} Whether or not the input is a scalar or scalar equivalent.
* @private
**/
const isYamlScalarEquivalent = (x) =>
!x || ['string', 'number', 'boolean'].includes(typeof x)

/**
* As part of our recursive implementation, we need to be able to break down different types. This tells us if it's a scalar.
* @param {any} x - The input value.
* @returns {boolean} Whether or not the input is a scalar.
* @private
**/
const isJustAScalar = (x) => !x || x[0] === '@' || x === parseSafely(`${x}`)

/**
Expand Down Expand Up @@ -70,6 +100,27 @@ const expandObjectInputs = (str) => {
}
}

/**
* This function takes an input and forces it to be an array.
* @param {any} input - The input to force into an array.
* @returns {array} - The input as an array.
* @public
* @function
*/
const forceArray = (input) =>
Array.isArray(input) ? input : input && input.length > 0 ? [input] : []

/**
* This function takes an input and forces it to be an object.
* @param {any} input - The input to force into an object.
* @returns {object} - The input as an object.
* @public
* @function
*/
const forceObject = (input) => (typeof input === 'object' ? input : {})

module.exports = {
expandObjectInputs,
forceArray,
forceObject,
}
30 changes: 10 additions & 20 deletions lib/input-to-registry-document.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
/**
* This module contains the logic for converting the Action inputs into a registry document for Datadog.
* @module lib/input-to-registry-document
* @requires fs
* @requires path
* @requires @actions/core
* @requires lodash
**/

const fs = require('fs')
const path = require('path')
const core = require('@actions/core')
const _ = require('lodash')
const { expandObjectInputs } = require('./input-expander')

/**
* This function takes an input and forces it to be an array.
* @param {any} input - The input to force into an array.
* @returns {array} - The input as an array.
* @private
* @function
*/
const forceArray = (input) =>
Array.isArray(input) ? input : input && input.length > 0 ? [input] : []

/**
* This function takes an input and forces it to be an object.
* @param {any} input - The input to force into an object.
* @returns {object} - The input as an object.
* @private
* @function
*/
const forceObject = (input) => (typeof input === 'object' ? input : {})
const { expandObjectInputs, forceArray, forceObject } = require('./input-expander')

/**
* This function takes the inputs from the Action and converts them into a registry document for Datadog.
Expand Down
5 changes: 5 additions & 0 deletions lib/schema-versions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @fileoverview This file contains the schema versions, their differences, and mappings between them.
* @module lib/schema-versions
**/

const VersionDifferences = {
v2: {
uniqueFields: ['docs', 'repos'],
Expand Down
Loading

0 comments on commit cfb69c2

Please sign in to comment.