Skip to content

Commit

Permalink
chore(automation): attempt to pass tutone config to generate workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderblue committed Sep 19, 2024
1 parent 40dbd47 commit 05a3bf8
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 90 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
with:
go-version: 1.21.x

- name: Add GOBIN to PATH
run: echo "${{ inputs.apiEndpoints }}"
shell: bash

- name: Add GOBIN to PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash
Expand All @@ -40,6 +44,10 @@ jobs:
- name: Install Tutone
run: go install github.com/newrelic/tutone/cmd/tutone@latest

- name: Check config file contents
run: cat .tutone.yml
shell: bash

# Append configuration to the config file OR write temporary Tutone config file

# - name: Write config file
Expand Down
159 changes: 81 additions & 78 deletions .github/workflows/graphql-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Download artifact
Expand Down Expand Up @@ -58,88 +58,88 @@ jobs:
ls
- name: Check for schema updates
uses: actions/github-script@v7
id: schema-diff
uses: actions/github-script@v7
with:
script: |
const script = require('./scripts/schema-diff-reporter.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. ${{ steps.schema-diff.outputs.hero_mention }}"
},
"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
# - 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. ${{ steps.schema-diff.outputs.hero_mention }}"
# },
# "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.
Expand All @@ -155,12 +155,15 @@ jobs:
if-no-files-found: error
overwrite: true

- name: Check tutone config output
run: echo "${{ toJSON(needs.schema-diff.outputs.tutone_config) }}"

generate-code:
# if: steps.schema-diff.outputs.hero_mention != ''
needs: checkForApiUpdates
uses: newrelic/newrelic-client-go/.github/workflows/generate.yml@feat/automated-codegen
with:
apiEndpoints: '[autoflowsDeleteWorkflowDefinition, autoflowsStopWorkflowRun, autoflowsUpdateWorkflowDefinition]' # ${{needs.checkForApiUpdates.outputs.apiEndpoints}}
apiEndpoints: ${{ toJSON(needs.schema-diff.outputs.tutone_config) }} # '[autoflowsDeleteWorkflowDefinition, autoflowsStopWorkflowRun, autoflowsUpdateWorkflowDefinition]' # ${{needs.checkForApiUpdates.outputs.apiEndpoints}}
# secrets:
# NEW_RELIC_API_KEY: ${{ secrets.NEW_RELIC_API_KEY }}
# DEV_TOOLKIT_TOKEN: ${{ secrets.DEV_TOOLKIT_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions scripts/schema-diff-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = async ({

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

await core.summary
.addHeading('New Relic Client Go | NerdGraph API Report')
Expand Down
25 changes: 13 additions & 12 deletions scripts/schema-differ.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ let schemaLatest = null;
let heroMention = "";

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

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

const schemaFileLatest = fs.readFileSync('../schema-test-new.json', 'utf8');
// const schemaFileLatest = fs.readFileSync('../schema-copy-new.json', 'utf8');
const schemaFileLatest = fs.readFileSync('schema-test-new.json', 'utf8');
// const schemaFileLatest = fs.readFileSync('schema.json', 'utf8');
schemaLatest = JSON.parse(schemaFileLatest);
} catch (err) {
console.error(err);
Expand Down Expand Up @@ -81,7 +81,7 @@ function generatePackageNameForEndpoint(endpointName) {
return endpointName.split(keywords)[0].toLowerCase();
}

console.log('');
// console.log('');

const packages = [];

Expand Down Expand Up @@ -113,7 +113,7 @@ const newMutationsConfigs = newEndpoints.map((endpointName) => {
};
});

console.log('newMutationsConfigs:', newMutationsConfigs);
// console.log('newMutationsConfigs:', newMutationsConfigs);

function mergeObjectsArray(objects) {
return objects.reduce((acc, current) => {
Expand Down Expand Up @@ -149,12 +149,15 @@ const config = mergeObjectsArray(newMutationsConfigs.reduce((arr, mutationConfig
return [...arr, pkg];
}, []));

const tutoneConfigYAML = yaml.stringify(config);

// console.log('packages:', packages);
// console.log('newMutationsConfig:', newMutationsConfigs);


console.log('config:', JSON.stringify(config, null, 2));
console.log('');
// console.log('config:', JSON.stringify(config, null, 2));
// console.log('config:\n\n', yaml.stringify(config));
// console.log('');

// Check to see which mutations the client is missing
const schemaMutations = schemaLatest.mutationType.fields.map(field => field.name);
Expand Down Expand Up @@ -264,11 +267,8 @@ function getTypeName(type) {
function getMaxQueryDepth(type, depth = 1) {
let maxQueryDepth = depth;

// console.log('type:', type);

type = getTypeFromSchema(getTypeName(type));


if (type?.kind === 'INPUT_OBJECT' || type?.ofType?.kind === 'INPUT_OBJECT') {
maxQueryDepth++

Expand Down Expand Up @@ -303,4 +303,5 @@ module.exports = {
newApiMutationsMsg,
clientMutationsDiffMsg,
changedEndpoints,
tutoneConfig: tutoneConfigYAML,
};

0 comments on commit 05a3bf8

Please sign in to comment.