diff --git a/.github/workflows/validate_packs.yml b/.github/workflows/validate_packs.yml index 00db620abc..7bf178fe86 100644 --- a/.github/workflows/validate_packs.yml +++ b/.github/workflows/validate_packs.yml @@ -1,4 +1,4 @@ -name: Validate Packs +name: Validate quickstarts on: [push, workflow_dispatch, pull_request] @@ -19,10 +19,10 @@ jobs: run: cd utils && yarn install - name: Validate files - run: cd utils && yarn validate-packs + run: cd utils && yarn validate-quickstarts - ensure-pack-names-are-unique: - name: Ensure pack names are unique + ensure-quickstart-names-are-unique: + name: Ensure quickstart names are unique runs-on: ubuntu-latest steps: - name: Checkout repository diff --git a/utils/check_pack_uniqueness.js b/utils/check_quickstart_uniqueness.js similarity index 68% rename from utils/check_pack_uniqueness.js rename to utils/check_quickstart_uniqueness.js index 5e0422a4e8..b3d2f9250b 100644 --- a/utils/check_pack_uniqueness.js +++ b/utils/check_quickstart_uniqueness.js @@ -1,15 +1,15 @@ 'use strict'; const { - readPackFile, + readQuickstartFile, removeRepoPathPrefix, - findMainPackConfigFiles, + findMainQuickstartConfigFiles, } = require('./helpers'); /** * Removes whitespace and punctuation from a string * @returns {String} The string with `-` replacing whitespace and punctuation removed */ -const cleanPackName = (str) => +const cleanQuickstartName = (str) => str .trim() .toLowerCase() @@ -18,14 +18,14 @@ const cleanPackName = (str) => .replace(/[^a-z0-9-]/g, ''); /** - * Returns any packs with matching names - * @param {Object[]} namesAndPaths an array of objects containing the path and name of a pack + * Returns any quickstarts with matching names + * @param {Object[]} namesAndPaths an array of objects containing the path and name of a quickstart * @returns {Object[]} an array of matching values */ const getMatchingNames = (namesAndPaths) => { return namesAndPaths.reduce((acc, { name, path }) => { const duplicates = namesAndPaths.filter( - (pack) => pack.name === name && pack.path !== path + (quickstart) => quickstart.name === name && quickstart.path !== path ); return [...new Set([...acc, ...duplicates])]; @@ -33,21 +33,21 @@ const getMatchingNames = (namesAndPaths) => { }; const main = () => { - const configPaths = findMainPackConfigFiles(); - const configs = configPaths.map(readPackFile); + const configPaths = findMainQuickstartConfigFiles(); + const configs = configPaths.map(readQuickstartFile); const nameAndPaths = configs.map((c) => ({ - name: cleanPackName(c.contents[0].name), + name: cleanQuickstartName(c.contents[0].name), path: c.path, })); const matches = getMatchingNames(nameAndPaths); if (matches.length > 0) { - console.error(`ERROR: Found matching Observability Pack names`); + console.error(`ERROR: Found matching quickstart names`); console.error(`Punctuation and white space are removed before comparison`); matches.forEach((m) => console.error(`${m.name} in ${removeRepoPathPrefix(m.path)}`) ); - console.error(`Please update your pack's name to be unique`); + console.error(`Please update your quickstart's name to be unique`); // `require.main` is equal to `module` when the file is being executed directly // if it isn't, the file is being import/required @@ -55,7 +55,7 @@ const main = () => { process.exit(1); } } else { - console.log(`All Observability Pack names are unique`); + console.log(`All quickstart names are unique`); } }; diff --git a/utils/generate-uuids.js b/utils/generate-uuids.js index dee7f4dc0c..ebbe80f441 100644 --- a/utils/generate-uuids.js +++ b/utils/generate-uuids.js @@ -2,11 +2,11 @@ const fs = require('fs'); const { v4: uuidv4 } = require('uuid'); -const { findMainPackConfigFiles, readYamlFile } = require('./helpers'); +const { findMainQuickstartConfigFiles, readYamlFile } = require('./helpers'); /** - * Checks for and generates UUIDs for packs - * @param {String[]} paths an array of pack config paths + * Checks for and generates UUIDs for quickstarts + * @param {String[]} paths an array of quickstarts config paths **/ const main = (paths) => { for (const path of paths) { @@ -22,11 +22,11 @@ const main = (paths) => { }; /** - * This allows us to check if the script was invoked directly from the command line, i.e 'node validate_packs.js', or if it was imported. + * This allows us to check if the script was invoked directly from the command line, i.e 'node validate_quickstarts.js', or if it was imported. * This would be true if this was used in one of our GitHub workflows, but false when imported for use in a test. * See here: https://nodejs.org/docs/latest/api/modules.html#modules_accessing_the_main_module */ if (require.main === module) { - const configPaths = findMainPackConfigFiles(); + const configPaths = findMainQuickstartConfigFiles(); main(configPaths); } diff --git a/utils/helpers.js b/utils/helpers.js index 7bd4e4f258..10fc20544c 100644 --- a/utils/helpers.js +++ b/utils/helpers.js @@ -32,7 +32,7 @@ const readJsonFile = (filePath) => { * @param {String} filePath - The path to the JSON or YAML file * @returns {Object} An object containing the path and contents of the file */ -const readPackFile = (filePath) => +const readQuickstartFile = (filePath) => path.extname(filePath) === '.json' ? readJsonFile(filePath) : readYamlFile(filePath); @@ -65,12 +65,12 @@ const checkArgs = (length) => { }; /** - * Removes the `newrelic-observability-packs/` path prefix from a string + * Removes the `newrelic-quickstarts/` path prefix from a string * @param {String} filePath the path to change * @returns {String} The path with the prefix */ const removeRepoPathPrefix = (filePath) => - filePath.split(`newrelic-observability-packs/`).pop(); + filePath.split(`newrelic-quickstarts/`).pop(); /** * Checks if a path is a direectory @@ -118,16 +118,18 @@ const globFiles = (dir) => { }; /** - * Finds the path to all top level pack configs + * Finds the path to all top level quickstart configs * @returns {String[]} An array of the file paths */ -const findMainPackConfigFiles = () => - glob.sync(path.resolve(process.cwd(), '../packs/**/config.+(yml|yaml)')); +const findMainQuickstartConfigFiles = () => + glob.sync( + path.resolve(process.cwd(), '../quickstarts/**/config.+(yml|yaml)') + ); module.exports = { readYamlFile, readJsonFile, - readPackFile, + readQuickstartFile, removeCWDPrefix, removeRepoPathPrefix, checkArgs, @@ -136,5 +138,5 @@ module.exports = { getFileExtension, globFiles, isDirectory, - findMainPackConfigFiles, + findMainQuickstartConfigFiles, }; diff --git a/utils/package.json b/utils/package.json index 9cb9a1ff05..bb543b5a1d 100644 --- a/utils/package.json +++ b/utils/package.json @@ -1,13 +1,13 @@ { - "name": "newrelic-observability-packs", + "name": "newrelic-quickstarts", "version": "0.0.1", - "repository": "https://github.com/newrelic/newrelic-observability-packs.git", + "repository": "https://github.com/newrelic/newrelic-quickstarts.git", "author": "NewRelic", "license": "Apache-2.0", "scripts": { - "validate-packs": "node validate_packs.js", + "validate-quickstarts": "node validate_quickstarts.js", "test": "jest -i", - "check-for-matching-names": "node check_pack_uniqueness.js", + "check-for-matching-names": "node check_quickstart_uniqueness.js", "validate-images": "node validate_images.js", "format": "prettier --write \"./**/*.js\"", "validate-icons-and-logos": "node validate_icons_and_logos.js", diff --git a/utils/validate_icons_and_logos.js b/utils/validate_icons_and_logos.js index fff415c2fc..ccb7d542ce 100644 --- a/utils/validate_icons_and_logos.js +++ b/utils/validate_icons_and_logos.js @@ -2,7 +2,10 @@ const fs = require('fs'); const path = require('path'); -const { readPackFile, findMainPackConfigFiles } = require('./helpers'); +const { + readQuickstartFile, + findMainQuickstartConfigFiles, +} = require('./helpers'); /** * Method to validate icons and logos exist if supplied. @@ -15,7 +18,7 @@ const validateIconAndLogo = (mainConfigPaths) => { for (const configPath of mainConfigPaths) { const { contents: [config], - } = readPackFile(configPath); + } = readQuickstartFile(configPath); if ('icon' in config) { // icon and logo will be supplied as relative paths, so we path.join on the directory of where the main config lives. @@ -60,14 +63,14 @@ const handleErrors = (errorMessages) => { const main = () => { console.log(''); // add an extra new line for more visual separation in the workflow - var mainConfigPaths = findMainPackConfigFiles(); + var mainConfigPaths = findMainQuickstartConfigFiles(); var errorMessages = validateIconAndLogo(mainConfigPaths); handleErrors(errorMessages); console.log(''); // add an extra new line for more visual separation in the workflow }; /** - * This allows us to check if the script was invoked directly from the command line, i.e 'node validate_packs.js', or if it was imported. + * This allows us to check if the script was invoked directly from the command line, i.e 'node validate_quickstarts.js', or if it was imported. * This would be true if this was used in one of our GitHub workflows, but false when imported for use in a test. * See here: https://nodejs.org/docs/latest/api/modules.html#modules_accessing_the_main_module */ diff --git a/utils/validate_images.js b/utils/validate_images.js index eb4639ddde..0fd5d148fe 100644 --- a/utils/validate_images.js +++ b/utils/validate_images.js @@ -5,8 +5,8 @@ const { getFileSize, getFileExtension, globFiles, - readPackFile, - findMainPackConfigFiles, + readQuickstartFile, + findMainQuickstartConfigFiles, } = require('./helpers'); const glob = require('glob'); @@ -21,20 +21,20 @@ const ALLOWED_IMG_EXT = ['.png', '.jpeg', '.jpg', '.svg']; * @param {Array} files - The array of globbed file names */ -const validateImageCounts = (packDirs) => { - const directories = packDirs - .map((pack) => { - const packDirName = path.dirname(pack); - // get all images for pack +const validateImageCounts = (quickstartDirs) => { + const directories = quickstartDirs + .map((quickstart) => { + const quickstartDirName = path.dirname(quickstart); + // get all images for a quickstart const imagePaths = glob.sync( - path.resolve(path.dirname(pack), '**/*.+(png|jpeg|jpg|svg)') + path.resolve(path.dirname(quickstart), '**/*.+(png|jpeg|jpg|svg)') ); - const packConfig = readPackFile(pack).contents[0]; - const iconPath = packConfig.icon - ? path.resolve(path.dirname(pack), packConfig.icon) + const quickstartConfig = readQuickstartFile(quickstart).contents[0]; + const iconPath = quickstartConfig.icon + ? path.resolve(path.dirname(quickstart), quickstartConfig.icon) : null; - const logoPath = packConfig.logo - ? path.resolve(path.dirname(pack), packConfig.logo) + const logoPath = quickstartConfig.logo + ? path.resolve(path.dirname(quickstart), quickstartConfig.logo) : null; const screenshotPaths = imagePaths.filter( @@ -43,7 +43,7 @@ const validateImageCounts = (packDirs) => { if (screenshotPaths.length > MAX_NUM_IMG) { return { - folder: packDirName, + folder: quickstartDirName, imageCount: screenshotPaths.length, }; } @@ -98,8 +98,8 @@ const validateImageExtensions = (globbedFiles) => { }; const main = () => { - const packDirs = findMainPackConfigFiles(); - validateImageCounts(packDirs); + const quickstartDirs = findMainQuickstartConfigFiles(); + validateImageCounts(quickstartDirs); const globbedFiles = globFiles(BASE_PATH); validateFileSizes(globbedFiles); @@ -107,7 +107,7 @@ const main = () => { }; /** - * This allows us to check if the script was invoked directly from the command line, i.e 'node validate_packs.js', or if it was imported. + * This allows us to check if the script was invoked directly from the command line, i.e 'node validate_quickstarts.js', or if it was imported. * This would be true if this was used in one of our GitHub workflows, but false when imported for use in a test. * See here: https://nodejs.org/docs/latest/api/modules.html#modules_accessing_the_main_module */ diff --git a/utils/validate_packs.js b/utils/validate_quickstarts.js similarity index 91% rename from utils/validate_packs.js rename to utils/validate_quickstarts.js index 453511d716..0361d06ea1 100644 --- a/utils/validate_packs.js +++ b/utils/validate_quickstarts.js @@ -5,7 +5,7 @@ const Ajv = require('ajv'); const { ErrorObject } = require('ajv'); const ajv = new Ajv({ allErrors: true }); -const { readPackFile, removeRepoPathPrefix } = require('./helpers'); +const { readQuickstartFile, removeRepoPathPrefix } = require('./helpers'); // schemas const mainConfigSchema = require('./schemas/main_config.json'); @@ -120,19 +120,19 @@ const validateFile = (file) => { * @param {String} basePath - the base path to search under, usually the current working directory * @returns {String[]} An array containing the file paths */ -const getPackFilePaths = (basePath) => { +const getQuickstartFilePaths = (basePath) => { const options = { ignore: EXCLUDED_DIRECTORY_PATTERNS.map((d) => path.resolve(basePath, d)), }; const yamlFilePaths = [ - ...glob.sync(path.resolve(basePath, '../packs/**/*.yaml'), options), - ...glob.sync(path.resolve(basePath, '../packs/**/*.yml'), options), + ...glob.sync(path.resolve(basePath, '../quickstarts/**/*.yaml'), options), + ...glob.sync(path.resolve(basePath, '../quickstarts/**/*.yml'), options), ...glob.sync(path.resolve(basePath, '../install/**/*.yml'), options), ]; const jsonFilePaths = glob.sync( - path.resolve(basePath, '../packs/**/*.json'), + path.resolve(basePath, '../quickstarts/**/*.json'), options ); @@ -155,8 +155,8 @@ const printErrors = (filesWithErrors) => { }; const main = () => { - const filePaths = getPackFilePaths(process.cwd()).sort(); - const files = filePaths.map(readPackFile); + const filePaths = getQuickstartFilePaths(process.cwd()).sort(); + const files = filePaths.map(readQuickstartFile); const filesWithErrors = files .map(validateFile) @@ -170,7 +170,7 @@ const main = () => { }; /** - * This allows us to check if the script was invoked directly from the command line, i.e 'node validate_packs.js', or if it was imported. + * This allows us to check if the script was invoked directly from the command line, i.e 'node validate_quickstarts.js', or if it was imported. * This would be true if this was used in one of our GitHub workflows, but false when imported for use in a test. * See here: https://nodejs.org/docs/latest/api/modules.html#modules_accessing_the_main_module */