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 20, 2024
1 parent 40dbd47 commit e7a5dc9
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 126 deletions.
63 changes: 27 additions & 36 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,48 +44,35 @@ jobs:
- name: Install Tutone
run: go install github.com/newrelic/tutone/cmd/tutone@latest

# Append configuration to the config file OR write temporary Tutone config file
# - name: Check config file contents
# run: cat .tutone.yml
# shell: bash

# - name: Write config file
# uses: DamianReeves/write-file-action@master
# with:
# path: .tutone.tmp.yml
# contents: |
# log_level: debug
# cache:
# schema_file: schema.json
# endpoint: https://api.newrelic.com/graphql
# auth:
# header: Api-Key
# api_key_env_var: NEW_RELIC_API_KEY
# Append configuration to the config file OR write temporary Tutone config file

# packages:
# - name: ${{ 'createPackageNameDynamically' }}
# path: pkg/${{ 'createPackageNameDynamically' }}
# import_path: github.com/newrelic/newrelic-client-go/v2/pkg/${{ 'createPackageNameDynamically' }}
# generators:
# - typegen
# - nerdgraphclient
# imports:
# - github.com/newrelic/newrelic-client-go/v2/pkg/common
# - github.com/newrelic/newrelic-client-go/v2/pkg/nrtime
# mutations:
# - name: accountManagementCreateAccount
# max_query_field_depth: ${{ 'calculatedInDiffReporter' }}
# - name: accountManagementUpdateAccount
# max_query_field_depth: ${{ 'calculatedInDiffReporter' }}
# - name: accountManagementCancelAccount
# max_query_field_depth: ${{ 'calculatedInDiffReporter' }}
# write-mode: overwrite
- name: Write config file
uses: DamianReeves/write-file-action@master
with:
path: .tutone.tmp.yml
contents: |
log_level: debug
cache:
schema_file: schema.json
endpoint: https://api.newrelic.com/graphql
auth:
header: Api-Key
api_key_env_var: NEW_RELIC_API_KEY
packages:
${{ inputs.apiEndpoints }}
- name: Check config file contents
run: cat .tutone.yml
run: cat .tutone.tmp.yml
shell: bash

# - name: Generate new code
# run: tutone generate -c .tutone.tmp.yml
# env:
# NEW_RELIC_API_KEY: ${{ secrets.NEW_RELIC_API_KEY }}
- name: Generate new code
run: tutone generate -c .tutone.tmp.yml
env:
NEW_RELIC_API_KEY: ${{ secrets.NEW_RELIC_API_KEY }}

# - name: Create Pull Request
# uses: peter-evans/create-pull-request@v3
Expand Down
161 changes: 82 additions & 79 deletions .github/workflows/graphql-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Check for API updates
runs-on: ubuntu-latest
outputs:
apiEndpoints: ${{ steps.schema-diff.outputs.new_api_mutations }}
apiEndpoints: ${{ steps.schema-diff.outputs.tutone_config }}
steps:
- name: Install Node
uses: actions/setup-node@v4
Expand All @@ -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.checkForApiUpdates.outputs.apiEndpoints) }}"

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: ${{ needs.checkForApiUpdates.outputs.apiEndpoints }} # '[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
27 changes: 16 additions & 11 deletions scripts/schema-differ.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ let schemaOld = null;
let schemaLatest = null;
let heroMention = "";

const pathPrefix = '';
try {
const tutoneConfigFile = fs.readFileSync('../.tutone.yml', 'utf8')
const tutoneConfigFile = fs.readFileSync(`${pathPrefix}.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(`${pathPrefix}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(`${pathPrefix}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 +82,7 @@ function generatePackageNameForEndpoint(endpointName) {
return endpointName.split(keywords)[0].toLowerCase();
}

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

const packages = [];

Expand Down Expand Up @@ -113,7 +114,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 +150,18 @@ 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('config JSON:\n\n', JSON.stringify(config, null, 2));
console.log('');
console.log('Tutone config:');
console.log('');
console.log(tutoneConfigYAML);
// 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 +271,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 +307,5 @@ module.exports = {
newApiMutationsMsg,
clientMutationsDiffMsg,
changedEndpoints,
tutoneConfig: tutoneConfigYAML,
};

0 comments on commit e7a5dc9

Please sign in to comment.