Skip to content

Commit

Permalink
Merge pull request #2550 from newrelic/mickey/NR-305852-quickstart-ids
Browse files Browse the repository at this point in the history
feat: NR-305852 Check for missing quickstart IDs
  • Loading branch information
mickeyryan42 authored Sep 12, 2024
2 parents f3f13a9 + 6c40d8f commit 38dd155
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Validate PR Artifact

on:
on:
pull_request:

jobs:
Expand All @@ -15,3 +15,16 @@ jobs:
uses: "./.github/actions/bootstrap"
- name: Validate PR Artifact
uses: "./.github/actions/build-validate-artifact"
validate-quickstart-ids:
runs-on: ubuntu-latest
if: ${{ github.base_ref == 'main' && github.head_ref == 'release' }}
steps:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
ref: ${{ github.sha }}
- name: Setup workspace
uses: "./.github/actions/bootstrap"
- name: Validate Quickstart IDs
run: |
cd utils && yarn validate-quickstart-ids
3 changes: 2 additions & 1 deletion utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"set-alert-policy-required-datasources": "ts-node set-alert-policy-required-datasources.ts",
"set-dashboards-required-datasources": "ts-node set-dashboards-required-datasources.ts",
"release": "ts-node release.ts",
"add-datasource-ids": "cd ./schema && ts-node add-datasource-ids.ts"
"add-datasource-ids": "cd ./schema && ts-node add-datasource-ids.ts",
"validate-quickstart-ids": "ts-node validate-quickstart-ids.ts"
},
"dependencies": {
"@actions/core": "^1.10.0",
Expand Down
1 change: 0 additions & 1 deletion utils/schema/artifact.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
}
},
"required": [
"id",
"description",
"summary",
"title",
Expand Down
43 changes: 43 additions & 0 deletions utils/validate-quickstart-ids.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as fs from 'fs';
import * as path from 'path';
import * as glob from 'glob';
import * as yaml from 'js-yaml';

import { QuickstartConfig } from './types/QuickstartConfig';

const getQuickstartPaths = () =>
glob.sync(path.resolve('..', 'quickstarts', '**', 'config.+(yml|yaml)'));

const findMissingIds = (quickstartPaths: string[]) => {
const quickstartsMissingIds: string[] = [];

quickstartPaths.forEach((filePath) => {
const config = yaml.load(
fs.readFileSync(filePath).toString('utf-8')
) as QuickstartConfig;

if (!config.id) {
quickstartsMissingIds.push(config.title);
}
});

return quickstartsMissingIds;
};

const main = () => {
const quickstartPaths = getQuickstartPaths();
const quickstartsMissingIds = findMissingIds(quickstartPaths);

if (quickstartsMissingIds.length > 0) {
console.log('\nThe following quickstarts are missing IDs:');
quickstartsMissingIds.forEach((title) => console.log(`\t- ${title}`));

process.exit(1);
}

console.log('[*] All quickstarts have IDs');
};

if (require.main === module) {
main();
}

0 comments on commit 38dd155

Please sign in to comment.