From 38b2132c7cc314f2425c062d72053cb42d657573 Mon Sep 17 00:00:00 2001 From: Andrew Anguiano Date: Wed, 26 Jun 2024 11:28:12 -0400 Subject: [PATCH] feat: Remove generate-schema-docs scripts and job --- .github/workflows/release.yml | 96 +------------------ utils/graphql-schemas/constants.js | 82 ---------------- utils/graphql-schemas/generate-schema-docs.js | 70 -------------- utils/package.json | 1 - 4 files changed, 1 insertion(+), 248 deletions(-) delete mode 100644 utils/graphql-schemas/constants.js delete mode 100644 utils/graphql-schemas/generate-schema-docs.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3725559044..a0571afec9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,100 +10,6 @@ env: THIRD_PARTY_GIT_AUTHOR_NAME: nr-opensource-bot jobs: - generate-schema-docs: - name: Generate GraphQL schema documentation - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - token: ${{ secrets.OPENSOURCE_BOT_TOKEN }} - ref: "main" - fetch-depth: 0 - - - name: Setup workspace - uses: './.github/actions/bootstrap' - - - name: Generate schema docs for GraphQl - id: generate-schema - env: - NR_API_URL: ${{ secrets.NR_API_URL }} - NR_API_TOKEN: ${{ secrets.NR_API_TOKEN }} - run: cd utils && yarn generate-schema-docs - - - name: Commit changes - id: commit-changes - run: | - git config --local user.email "${{ env.THIRD_PARTY_GIT_AUTHOR_EMAIL }}" - git config --local user.name "${{ env.THIRD_PARTY_GIT_AUTHOR_NAME }}" - git add ./docs/* - git diff-index --quiet HEAD ./docs/* || git commit -m 'chore: generate schema documentation [skip ci]' - echo "commit=true" >> $GITHUB_ENV - - - name: Temporarily disable branch protections - id: disable-branch-protection - if: always() - uses: actions/github-script@v6 - with: - github-token: ${{ secrets.OPENSOURCE_BOT_TOKEN }} - script: | - const result = await github.rest.repos.updateBranchProtection({ - owner: context.repo.owner, - repo: context.repo.repo, - branch: 'main', - required_status_checks: null, - restrictions: null, - enforce_admins: null, - required_pull_request_reviews: null - }) - console.log("Result:", result) - - - name: Push Commit - if: env.commit == 'true' - run: git push origin HEAD - - - name: Re-enable branch protections - id: enable-branch-protection - if: always() - uses: actions/github-script@v6 - with: - github-token: ${{ secrets.OPENSOURCE_BOT_TOKEN }} - script: | - const result = await github.rest.repos.updateBranchProtection({ - owner: context.repo.owner, - repo: context.repo.repo, - branch: 'main', - required_status_checks: { - strict: true, - contexts: [ - 'Validation / Image count and extension compliance', - 'Validation / Ensure icons exist', - 'Validation / Install plan ids exist', - 'Validation / Data source ids exist', - 'Validation / Install plan schema compliance', - 'Validation / Data source schema compliance', - 'Validation / Quickstart id are unique', - 'Validation / Validate Quickstart Schema', - 'Validation / Quickstart dashboard name is unique' - ] - }, - restrictions: { - "users":[], - "teams":[], - "apps":[] - }, - enforce_admins: true, - required_pull_request_reviews: { - dismiss_stale_reviews: true, - required_approving_review_count: 1, - dismissal_restrictions: { - users: [], - teams: [] - } - } - }) - console.log("Result:", result) - generate-third-party-notices: runs-on: ubuntu-latest steps: @@ -115,7 +21,7 @@ jobs: fetch-depth: 2 - name: Setup workspace - uses: './.github/actions/bootstrap' + uses: "./.github/actions/bootstrap" - name: Install OSS CLI working-directory: ./utils diff --git a/utils/graphql-schemas/constants.js b/utils/graphql-schemas/constants.js deleted file mode 100644 index 3420348a63..0000000000 --- a/utils/graphql-schemas/constants.js +++ /dev/null @@ -1,82 +0,0 @@ -const fullSchemaQuery = ` -query IntrospectionQuery { - __schema { - types { - ...FullType - } - } -} -fragment FullType on __Type { - kind - name - description - fields(includeDeprecated: true) { - name - description - args { - ...InputValue - } - type { - ...TypeRef - } - isDeprecated - deprecationReason - } - inputFields { - ...InputValue - } - interfaces { - ...TypeRef - } - enumValues(includeDeprecated: true) { - name - description - isDeprecated - deprecationReason - } - possibleTypes { - ...TypeRef - } -} -fragment InputValue on __InputValue { - name - description - type { - ...TypeRef - } - defaultValue -} -fragment TypeRef on __Type { - kind - name - ofType { - kind - name - ofType { - kind - name - ofType { - kind - name - ofType { - kind - name - ofType { - kind - name - ofType { - kind - name - ofType { - kind - name - } - } - } - } - } - } - } -}`; - -module.exports = { fullSchemaQuery }; diff --git a/utils/graphql-schemas/generate-schema-docs.js b/utils/graphql-schemas/generate-schema-docs.js deleted file mode 100644 index c62c2be649..0000000000 --- a/utils/graphql-schemas/generate-schema-docs.js +++ /dev/null @@ -1,70 +0,0 @@ -const fs = require('fs'); -const { fetchNRGraphqlResults } = require('../lib/nr-graphql-helpers'); -const { fullSchemaQuery } = require('./constants'); -const { renderSchema } = require('graphql-markdown'); - -/** - * Print function to pass to renderSchema, writes each line separately to a file - * @param {String} data - The data to write to the file - */ -const printData = (data) => { - fs.appendFileSync('../docs/graphql-schema-docs.md', `${data}\n`); -}; - -/** - * Filters the data to only include NR1Catalog endpoints - * @param {Object} data - The data to filter - * @returns {Object} The filtered data in schema form for graphql-markdown - */ -const filterData = (data) => { - const { - data: { - __schema: { types }, - }, - } = data; - const endpoints = types.filter( - (type) => - type.name.startsWith('Nr1CatalogQuickstart') || - type.name.startsWith('Nr1CatalogInstall') - ); - - // Stringifies the data and replaces the NR internal strings in all descriptions - const removedInternalData = JSON.parse( - JSON.stringify(endpoints).replace( - /(\\n\\n---\\n\*\*NR Internal\*\*)(.*?)(\\n\\n)/g, - '' - ) - ); - - // Return in a GraphQL schema pattern so that graphql-markdown can render correctly - return { __schema: { types: removedInternalData } }; -}; - -const main = async () => { - const { NR_API_URL, NR_API_TOKEN } = process.env; - if (!NR_API_URL || !NR_API_TOKEN) { - console.error( - 'Please set the NR_API_URL and NR_API_TOKEN environment variables' - ); - process.exit(1); - } - - const result = await fetchNRGraphqlResults({ - queryString: fullSchemaQuery, - }); - const endpoints = filterData(result); - - // Clear the file before writing to it, as each line is written separately - fs.writeFileSync('../docs/graphql-schema-docs.md', ''); - renderSchema(endpoints, { printer: printData }); - process.exit(0); -}; - -/** - * This allows us to check if the script was invoked directly from the command line, i.e 'node validate_quickstarts.js', or if it was imported. - * This would be true if this was used in one of our GitHub workflows, but false when imported for use in a test. - * See here: https://nodejs.org/docs/latest/api/modules.html#modules_accessing_the_main_module - */ -if (require.main === module) { - main(); -} diff --git a/utils/package.json b/utils/package.json index 6f87bde0d5..8f19b3e9d8 100644 --- a/utils/package.json +++ b/utils/package.json @@ -19,7 +19,6 @@ "generate-uuids": "ts-node generate-uuids.ts", "sanitize-dashboard": "ts-node sanitize_dashboards.ts", "dashboard-helper": "ts-node dashboard-helper.ts", - "generate-schema-docs": "ts-node graphql-schemas/generate-schema-docs.js", "preview": "ts-node preview.ts", "create-preview-links": "ts-node create-preview-links.ts", "set-alert-policy-required-datasources": "ts-node set-alert-policy-required-datasources.ts",