Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New validation/release workflow #2551

Merged
merged 53 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
bca74e7
feat: Create reusable validation workflow
Sep 9, 2024
4e014be
WIP: Initial workflow
Sep 9, 2024
bdb3959
chore: Remove inputs from workflow
Sep 9, 2024
37488f5
chore: Replace workflow_call trigger
Sep 9, 2024
d6507d4
feat: Finish artifact creation workflow
Sep 9, 2024
91604d3
fix: Kebab case for script name
Sep 10, 2024
097c49e
feat: Update trigger for validation workflow
Sep 10, 2024
3f32dad
feat: Add trigger for main pushes
Sep 10, 2024
a91572f
feat: Remove workflow_call trigger
Sep 10, 2024
75df800
Merge pull request #2548 from newrelic/campfire/NR-273120-pr-workflow
Sep 10, 2024
173ca5d
refactor: Move setup workspace into workflow
Sep 10, 2024
6c801be
feat: Update artifact script to save to filesystem
Sep 10, 2024
22540ce
feat: Copy the schema to the build output
Sep 10, 2024
87f5913
feat: Add ability to output artifact from workflow when triggered on …
Sep 10, 2024
7e69b7e
fix: Use single quotes in expression
Sep 10, 2024
99be0d1
fix: Move checkout back into action
Sep 10, 2024
6b93d17
refactor: Restructure workflow
Sep 10, 2024
6b9d076
feat: Upload artifact (testing)
Sep 10, 2024
1792779
chore: Add debug output
Sep 10, 2024
517479c
fix: Correct upload path
Sep 10, 2024
d11babb
feat: Create release (testing)
Sep 10, 2024
c96c11c
feat: Remove upload artifact (testing)
Sep 10, 2024
28e4301
feat: Add tag release workflow
Sep 10, 2024
8e9a1e1
feat: Remove debugging output
Sep 10, 2024
43e4b7d
feat: Add release job to PR workflow
Sep 10, 2024
1211e1e
feat: Remove if for testing purposes
Sep 10, 2024
7160e4e
fix: Add github token to release tag action
Sep 10, 2024
7833f01
feat: Run workflow on tag creation
Sep 10, 2024
8f7be76
feat: Rework release workflow
Sep 10, 2024
deb7761
fix: Checkout repo in release job
Sep 10, 2024
fee517d
fix: Correct path to shared workflow
Sep 10, 2024
4fac6ec
feat: Fix syntax for reusable workflows
Sep 10, 2024
e94944c
fix: Pass new tag to release
Sep 10, 2024
1842a16
feat: Slight refactor so tags are only created on branch pushes
Sep 10, 2024
ea73b38
feat: Swap out version bump action
Sep 11, 2024
629679d
feat: Change branch trigger filter for testing
Sep 11, 2024
ce9ae7f
feat: Checkout repo before bumping version
Sep 11, 2024
f4ddc09
feat: Swap out version action again
Sep 11, 2024
ed94e03
feat: Add attestation
Sep 11, 2024
a28ed39
feat: Fix permissions
Sep 11, 2024
594433b
refactor: Clean up and rename some things
Sep 11, 2024
4cbbd1d
refactor: Rename job step
Sep 11, 2024
bde0e28
feat: Exit 1 if artifact output fails
Sep 11, 2024
949517f
feat: Have release run on main (undoes testing trigger)
Sep 11, 2024
08560c7
feat: Change input for build-validate-artifact
Sep 11, 2024
b8df1d8
feat: Remove workflow_call trigger
Sep 11, 2024
77df649
Merge pull request #2549 from newrelic/andrew/NR-268466-main-validation
Sep 11, 2024
fd4f90e
Adds in data source ids to schema under definition
josephgregoryii Sep 11, 2024
e25f5c1
test breaking validaiton
josephgregoryii Sep 11, 2024
f0cb4d2
Test schema update
josephgregoryii Sep 11, 2024
d748cb7
Update schema to reference data source ids
josephgregoryii Sep 11, 2024
27ef019
remove invalid data source
josephgregoryii Sep 11, 2024
b413c6f
Merge pull request #2553 from newrelic/campfire/schema/add-data-sourc…
josephgregoryii Sep 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/actions/build-validate-artifact/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build and Validate Artifact
description: Reusable action to build and validate the component artifact
inputs:
output-artifact:
description: 'If provided, the action will output the artifact to the build directory'
required: false

runs:
using: composite
steps:
- name: Add data source ids to schema
shell: bash
run: |
cd utils && yarn add-datasource-ids

- name: Build & Validate Artifact
shell: bash
id: build-validate-artifact
run: |
cd utils && yarn build-validate-quickstart-artifact ${{ inputs.output-artifact && '--output-artifact' || '' }}

- name: Debugging output
shell: bash
if: ${{ runner.debug }}
run: ls -la utils/build
16 changes: 16 additions & 0 deletions .github/actions/bump-version-tag/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Bump version tag
description: Bumps the version tag based on the latest version
outputs:
tag:
description: The new tag prefixed with `v`
value: ${{ steps.versions.outputs.v-version }}
runs:
using: composite
steps:
- name: Get next version
uses: reecetech/version-increment@a5d65984a6c6e8bbc30ece69d53d96e40736f24c
id: versions
with:
scheme: semver
increment: minor
use_api: true
17 changes: 17 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Validate PR Artifact

on:
pull_request:

jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
ref: ${{ github.sha }}
- name: Setup workspace
uses: "./.github/actions/bootstrap"
- name: Validate PR Artifact
uses: "./.github/actions/build-validate-artifact"
50 changes: 50 additions & 0 deletions .github/workflows/release-artifact.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This workflow runs when a tag is created with the `v` prefix or a push
# to main occurs. It runs our validation script, outputs the artifact,
# creates a new tag, Github release, and uploads/associates the artifact with the release.

name: Release artifact
on:
push:
branches:
- main
tags:
- 'v*'

# Permissions for attestation
permissions:
id-token: write
contents: write
attestations: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
ref: ${{ github.ref }}
- name: Setup workspace
uses: "./.github/actions/bootstrap"
- name: Validate and generate artifact
uses: "./.github/actions/build-validate-artifact"
with:
output-artifact: 'true'
- name: Attest artifact
uses: actions/attest-build-provenance@1c608d11d69870c2092266b3f9a6f3abbf17002c
with:
subject-path: utils/build/*
- name: Create new release tag
# Only run if this is a branch push (we'll need a new tag)
if: ${{ startsWith(github.ref, 'refs/heads') }}
id: version
uses: "./.github/actions/bump-version-tag"
- name: Create release
uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191
with:
files: utils/build/*
fail_on_unmatched_files: true
make_latest: true
# If we have a tag output from the previous step, use that as the tag
# name, otherwise use the current ref which should be the tag.
tag_name: ${{ steps.version.outputs.tag || github.ref }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
utils/node_modules
utils/newrelic_agent.log
utils/build

# IDE files
.DS_Store
Expand All @@ -17,4 +18,4 @@ snapshots/
yarn.lock
.yarn-integrity
yarn-error.log
utils/yarn-error.log
utils/yarn-error.log
59 changes: 40 additions & 19 deletions utils/build-validate-quickstart-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Dashboard, { DashboardConfig } from "./lib/Dashboard";
import Ajv, { type ErrorObject } from 'ajv';
import { QuickstartConfig, QuickstartConfigAlert } from './types/QuickstartConfig';
import { DataSourceConfig } from './types/DataSourceConfig';
import { passedProcessArguments } from './lib/helpers';

type ArtifactSchema = Record<string, unknown>;

Expand Down Expand Up @@ -74,7 +75,7 @@ export const validateArtifact = (schema: ArtifactSchema, artifact: Artifact): Er
return ajv.errors ?? [];
}

const main = () => {
const main = (shouldOutputArtifact: boolean = false) => {
const schema = getSchema('./schema/artifact.json');
const components = getArtifactComponents();
const dataSourceIds = getDataSourceIds('./schema/core-datasource-ids.json', components.dataSources);
Expand All @@ -88,6 +89,25 @@ const main = () => {
}

console.log('[*] Validation succeeded');

if (shouldOutputArtifact) {
outputArtifact(artifact);
}
}

const outputArtifact = (artifact: Artifact) => {
console.log('[*] Outputting the artifact');
try {
fs.mkdirSync('./build', { recursive: true });

// Dump the artifact to artifact.json
fs.writeFileSync('./build/artifact.json', JSON.stringify(artifact));
// Copy the schema to schema.json
fs.copyFileSync('./schema/artifact.json', './build/schema.json');
} catch (e) {
console.error('Error writing artifact to file:', e);
process.exit(1);
}
}

const getInvalidItems = (errors: ErrorObject[], artifact: ArtifactSchema): InvalidItem[] => {
Expand All @@ -108,25 +128,26 @@ const getInvalidItems = (errors: ErrorObject[], artifact: ArtifactSchema): Inval
}

const printErrors = (invalidItems: InvalidItem[]): void => {
console.error('*** Validation failed. See errors below. ***');
console.error('--------------------------------------------');

invalidItems.forEach(({ value, component, error }, idx) => {
console.error(`Error #${idx + 1}:`, error);
console.error('');
console.error('Received value:', value);

console.error('');
if (component !== value) {
console.error('Invalid component:', component);
}

if (idx < invalidItems.length - 1) {
console.error('************************************');
}
});
console.error('*** Validation failed. See errors below. ***');
console.error('--------------------------------------------');

invalidItems.forEach(({ value, component, error }, idx) => {
console.error(`Error #${idx + 1}:`, error);
console.error('');
console.error('Received value:', value);

console.error('');
if (component !== value) {
console.error('Invalid component:', component);
}

if (idx < invalidItems.length - 1) {
console.error('************************************');
}
});
}

if (require.main === module) {
main();
const shouldOutputArtifact = passedProcessArguments().includes('--output-artifact');
main(shouldOutputArtifact);
}
1 change: 1 addition & 0 deletions utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"validate-quickstart-data-sources": "ts-node validate-quickstart-data-sources.ts",
"create-validate-data-sources": "ts-node create-validate-data-sources.ts",
"create-validate-pr-quickstarts": "ts-node create_validate_pr_quickstarts.ts",
"build-validate-quickstart-artifact": "ts-node build-validate-quickstart-artifact.ts",
"check-dashboard-name-uniqueness": "ts-node check_dashboard_name_uniqueness.ts",
"test": "jest -i",
"check-quickstart-uniqueness": "ts-node check_quickstart_uniqueness.ts",
Expand Down
6 changes: 3 additions & 3 deletions utils/schema/add-datasource-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const CORE_DATASOURCE_IDS_PATH = './core-datasource-ids.json';
const DATASOURCE_BASE_PATH = '../../';

type ArtifactSchema = {
properties: {
definitions: {
dataSourceIds: {
enum: string[];
};
Expand Down Expand Up @@ -50,8 +50,8 @@ const updateSchema = (
): ArtifactSchema => {
return {
...schema,
properties: {
...schema.properties,
definitions: {
...schema.definitions,
dataSourceIds: { enum: ids },
},
};
Expand Down
18 changes: 12 additions & 6 deletions utils/schema/artifact.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"items": { "$ref": "#/definitions/dashboard" }
},
"dataSourceIds": {
"type": "array", "items": { "type": "string" }
"type": "array",
"items": { "$ref": "#/definitions/dataSourceIds" }
}
},
"required": [
Expand All @@ -41,7 +42,8 @@
"summary": { "type": "string" },
"title": { "type": "string" },
"authors": {
"type": "array", "items": { "type": "string" }
"type": "array",
"items": { "type": "string" }
},
"documentation": {
"type": "array",
Expand All @@ -59,17 +61,21 @@
"level": { "enum": ["New Relic", "Community", "Verified"] },
"icon": { "type": "string" },
"keywords": {
"type": "array", "items": { "type": "string" }
"type": "array",
"items": { "type": "string" }
},
"slug": { "type": "string" },
"alertPolicies": {
"type": "array", "items": { "type": "string" }
"type": "array",
"items": { "type": "string" }
},
"dashboards": {
"type": "array", "items": { "type": "string" }
"type": "array",
"items": { "type": "string" }
},
"dataSourceIds": {
"type": "array", "items": { "type": "string" }
"type": "array",
"items": { "$ref": "#/definitions/dataSourceIds" }
}
},
"required": [
Expand Down
Loading