Skip to content

Commit

Permalink
Merge branch 'main' into add-incident-title-template-support
Browse files Browse the repository at this point in the history
  • Loading branch information
baNROne authored May 20, 2024
2 parents 57b5783 + 88082e5 commit 817de1a
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 21 deletions.
152 changes: 152 additions & 0 deletions .github/workflows/graphql-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: NerdGraph Schema Diff
on:
workflow_dispatch:
schedule:
# Cron executes at 0800, 1200, 1600 UTC (8am, 12pm, 4pm)
# Monday through Friday
- cron: "0 8,12,16 * * 1-5"

jobs:
checkForApiUpdates:
name: Check for API updates
runs-on: ubuntu-latest
steps:
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x

- name: Checkout code
uses: actions/checkout@v4

- name: Check for schema updates
run: ls scripts && npm install yaml

- name: Download artifact
uses: actions/github-script@v7
env:
WORKFLOW_FILENAME: graphql-schema.yml
ARTIFACT_NAME: schema
ARTIFACT_FILENAME: schema.zip
UNZIP_DIR: ./
with:
script: |
const script = require('./scripts/download-previous-artifact.js')
await script({github, context, core})
- name: Rename schema.json to schema-old.json
run: |
find ./ -type f -name "schema.json"
mv schema.json schema-old.json
- name: Fetch GraphQL Schema
env:
NEW_RELIC_API_KEY: ${{ secrets.NEW_RELIC_API_KEY }}
run: |
go install github.com/newrelic/tutone/cmd/tutone@latest
tutone fetch --refetch
ls
- name: Check for schema updates
uses: actions/github-script@v7
id: schema-diff
with:
script: |
const script = require('./scripts/schema-diff.js')
await script({core})
- name: Send report to Slack
id: slack

uses: slackapi/[email protected]
with:
# Uses Slack's Block Kit to build the message
# https://app.slack.com/block-kit-builder
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":mag_right: *New Relic Client Go | NerdGraph API Report*"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*API Mutations Count:* ${{ steps.schema-diff.outputs.total_api_mutations_count }}\n*Client Mutations Count:* ${{ steps.schema-diff.outputs.client_mutations_count }}\n*Client Mutations Missing Count:* ${{ steps.schema-diff.outputs.client_mutations_missing_count }}\n"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*New API Mutations*"
}
},
{
"type": "context",
"elements": [
{
"type": "plain_text",
"text": ${{ toJSON(steps.schema-diff.outputs.new_api_mutations) }}
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "More information can be viewed in the job summary."
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Job Summary",
"emoji": true
},
"value": "View Job Summary",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"action_id": "button-action"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "\n\n"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

# After reporting changes to the schema, upload the most
# recent version so we can compare on the next run.
- name: Upload latest schema.json
uses: actions/upload-artifact@v4
with:
# Duration after which artifact will expire in days. 0 means using default retention.
# Minimum 1 day.
# Maximum 90 days unless changed from the repository settings page.
retention-days: 90
name: schema
path: schema.json
if-no-files-found: error
overwrite: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ schema.json

.vscode/
.DS_Store
.idea
.idea
18 changes: 6 additions & 12 deletions .tutone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,29 +249,23 @@ packages:
# overrides and specifications of fields associated with the syntheticsStartAutomatedTest mutation start here
- name: SyntheticsAutomatedTestConfigInput
struct_tags:
- json
- yaml
tags: [json, yaml]
- name: SyntheticsAutomatedTestMonitorInput
struct_tags:
- json
- yaml
tags: [json, yaml]
- name: SyntheticsAutomatedTestMonitorConfigInput
struct_tags:
- json
- yaml
tags: [json, yaml]
- name: SyntheticsAutomatedTestOverridesInput
field_type_override: "*SyntheticsAutomatedTestOverridesInput"
struct_tags:
- json
- yaml
tags: [json, yaml]
- name: SyntheticsScriptDomainOverrideInput
struct_tags:
- json
- yaml
tags: [json, yaml]
- name: SyntheticsSecureCredentialOverrideInput
struct_tags:
- json
- yaml
tags: [json, yaml]
# overrides and specifications of fields associated with the automatedTestResults query start here
- name: Milliseconds
field_type_override: int
Expand Down
65 changes: 65 additions & 0 deletions scripts/download-previous-artifact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module.exports = async ({
github,
context,
core
}) => {
const owner = context.repo.owner;
const repo = context.repo.repo;

const workflows = await github.rest.actions.listRepoWorkflows({
owner,
repo
});

const workflow = workflows.data.workflows.find(w => w.path.includes(process.env.WORKFLOW_FILENAME));

if (!workflow) {
core.setFailed("No workflow found");
return;
}

const runs = await github.rest.actions.listWorkflowRuns({
owner,
repo,
workflow_id: workflow.id,
status: "success",
per_page: 10
});

let artifacts
for (let i = 0; i < runs.data.workflow_runs.length; i++) {
const result = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: runs.data.workflow_runs[i].id
});

if (result.data.artifacts.length) {
artifacts = result.data.artifacts
break
}
}

console.log("Artifacts:", JSON.stringify(artifacts, null, 2));

if (runs.data.total_count === 0) {
core.setFailed("No runs found");
return;
}

const artifact = artifacts.find(artifact => artifact.name === process.env.ARTIFACT_NAME);
if (artifact) {
const response = await github.rest.actions.downloadArtifact({
owner,
repo,
artifact_id: artifact.id,
archive_format: 'zip'
});
require('fs').writeFileSync(process.env.ARTIFACT_FILENAME, Buffer.from(response.data));
require('child_process').execSync(`unzip -o ${process.env.ARTIFACT_FILENAME} -d ${process.env.UNZIP_DIR}`);

console.log("Artifact downloaded successfully");
} else {
core.setFailed("No artifact found");
}
}
74 changes: 74 additions & 0 deletions scripts/schema-diff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
module.exports = async ({
core
}) => {
const fs = require('fs');
const yaml = require('yaml');

let tutoneConfig = null
let schemaOld = null
let schemaLatest = null

try {
const tutoneConfigFile = fs.readFileSync('.tutone.yml', 'utf8')
tutoneConfig = yaml.parse(tutoneConfigFile)

const schemaFileOld = fs.readFileSync('schema-old.json', 'utf8');
schemaOld = JSON.parse(schemaFileOld);

const schemaFileLatest = fs.readFileSync('schema.json', 'utf8');
schemaLatest = JSON.parse(schemaFileLatest);
} catch (err) {
console.error(err);
}

// Check for any newly added mutations
const endpointsOld = schemaOld.mutationType.fields.map(field => field.name);
const endpointsLatest = schemaLatest.mutationType.fields.map(field => field.name);
const endpointsDiff = endpointsLatest.filter(x => !endpointsOld.includes(x));

// Get the mutations the client has implemented
const clientMutations = tutoneConfig.packages.map(pkg => {
if (!pkg.mutations) {
return null
}

if (!pkg.mutations.length) {
return null
}

return pkg.mutations.map(m => m.name)
}).flat().reduce((acc, i) => i ? [...acc, i] : acc, []);

// Check to see which mutations the client is missing
const schemaMutations = schemaLatest.mutationType.fields.map(field => field.name);
const clientMutationsDiff = schemaMutations.filter(x => !clientMutations.includes(x));

console.log('Client Mutations:', clientMutations);
console.log('Client is still missing the following mutations:\n', clientMutationsDiff);

let newApiMutationsMsg = 'No new mutations since last check';
if (endpointsDiff.length > 0) {
newApiMutationsMsg = `'${endpointsDiff.join('\n')}'`;
}

let clientMutationsDiffMsg = ''
if (clientMutationsDiff.length > 0) {
clientMutationsDiffMsg = `'${clientMutationsDiff.join('\n')}'`;
}


core.setOutput('total_api_mutations_count', schemaMutations.length);
core.setOutput('client_mutations_count', clientMutations.length);
core.setOutput('client_mutations_missing_count', clientMutationsDiff.length);

core.setOutput('new_api_mutations', newApiMutationsMsg);
core.setOutput('client_mutations_missing', clientMutationsDiffMsg);

await core.summary
.addHeading('New Relic Client Go | NerdGraph API Report')
.addRaw('Client mutations:')
.addList(clientMutations)
.addRaw('Client is missing the following mutations:')
.addList(clientMutationsDiff)
.write()
}
6 changes: 3 additions & 3 deletions tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/git-chglog/git-chglog v0.15.1
github.com/golangci/golangci-lint v1.53.3
github.com/goreleaser/goreleaser v1.15.2
github.com/newrelic/tutone v0.10.1
github.com/newrelic/tutone v0.11.0
github.com/psampaz/go-mod-outdated v0.8.0
github.com/stretchr/testify v1.8.4
github.com/x-motemen/gobump v0.2.0
Expand Down Expand Up @@ -57,7 +57,7 @@ require (
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/OpenPeeDeeP/depguard/v2 v2.1.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
Expand Down Expand Up @@ -220,7 +220,7 @@ require (
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/iancoleman/orderedmap v0.2.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
Loading

0 comments on commit 817de1a

Please sign in to comment.