Skip to content

Commit

Permalink
feat: Check quickstart IDs in PR from release to main
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickey Ryan committed Sep 11, 2024
1 parent 4cbbd1d commit 5683e90
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
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: |
yarn validate-quickstart-ids.ts
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 5683e90

Please sign in to comment.