diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml index 4e390546..8837e69e 100644 --- a/.github/workflows/generate.yml +++ b/.github/workflows/generate.yml @@ -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 @@ -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 diff --git a/.github/workflows/graphql-schema.yml b/.github/workflows/graphql-schema.yml index 8e64e755..6af66017 100644 --- a/.github/workflows/graphql-schema.yml +++ b/.github/workflows/graphql-schema.yml @@ -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 @@ -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 @@ -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/slack-github-action@v1.26 - 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/slack-github-action@v1.26 + # 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. @@ -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 }} diff --git a/scripts/schema-diff-reporter.js b/scripts/schema-diff-reporter.js index 157fb9ec..da71678b 100755 --- a/scripts/schema-diff-reporter.js +++ b/scripts/schema-diff-reporter.js @@ -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') diff --git a/scripts/schema-differ.js b/scripts/schema-differ.js index af1f79da..b6b8ca6c 100644 --- a/scripts/schema-differ.js +++ b/scripts/schema-differ.js @@ -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); @@ -81,7 +82,7 @@ function generatePackageNameForEndpoint(endpointName) { return endpointName.split(keywords)[0].toLowerCase(); } -console.log(''); +// console.log(''); const packages = []; @@ -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) => { @@ -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); @@ -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++ @@ -303,4 +307,5 @@ module.exports = { newApiMutationsMsg, clientMutationsDiffMsg, changedEndpoints, + tutoneConfig: tutoneConfigYAML, };