Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NR-199374 // Release script #2179

Merged
merged 9 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 53 additions & 53 deletions .github/workflows/pr-merged.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,56 +111,56 @@ jobs:
})
console.log("Result:", result)

get-pr-number:
name: Get PR number
runs-on: ubuntu-latest
outputs:
pr-number: ${{ steps.output_pr_number.outputs.pr-number }}
steps:
- name: Download artifact
uses: dawidd6/action-download-artifact@v2
with:
workflow: submit_gate.yml
run_id: ${{ github.event.workflow_run.id }}

- name: Get PR number
id: output_pr_number
run: |
export PR_NUMBER=$(cat artifact/pr_number_submit.txt)
echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT

staging:
needs: [generate-uuid, get-pr-number]
uses: ./.github/workflows/reusable.quickstart_submission.yml
with:
pr-number: ${{ needs.get-pr-number.outputs.pr-number }}
dry-run: false
secrets:
nr-api-url: ${{ secrets.NR_API_URL_STAGING }}
nr-api-token: ${{ secrets.NR_API_TOKEN_STAGING }}
github-token: ${{ secrets.GITHUB_TOKEN }}
nr-license-key: ${{ secrets.NEW_RELIC_LICENSE_KEY }}

production:
needs: [staging, get-pr-number]
uses: ./.github/workflows/reusable.quickstart_submission.yml
with:
pr-number: ${{ needs.get-pr-number.outputs.pr-number }}
dry-run: false
secrets:
nr-api-url: ${{ secrets.NR_API_URL }}
nr-api-token: ${{ secrets.NR_API_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
nr-license-key: ${{ secrets.NEW_RELIC_LICENSE_KEY }}

eu-production:
needs: [staging, get-pr-number]
uses: ./.github/workflows/reusable.quickstart_submission.yml
with:
pr-number: ${{ needs.get-pr-number.outputs.pr-number }}
dry-run: false
secrets:
nr-api-url: ${{ secrets.NR_API_URL_EU }}
nr-api-token: ${{ secrets.NR_API_TOKEN_EU }}
github-token: ${{ secrets.GITHUB_TOKEN }}
nr-license-key: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
# get-pr-number:
# name: Get PR number
# runs-on: ubuntu-latest
# outputs:
# pr-number: ${{ steps.output_pr_number.outputs.pr-number }}
# steps:
# - name: Download artifact
# uses: dawidd6/action-download-artifact@v2
# with:
# workflow: submit_gate.yml
# run_id: ${{ github.event.workflow_run.id }}

# - name: Get PR number
# id: output_pr_number
# run: |
# export PR_NUMBER=$(cat artifact/pr_number_submit.txt)
# echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT

# staging:
# needs: [generate-uuid, get-pr-number]
# uses: ./.github/workflows/reusable.quickstart_submission.yml
# with:
# pr-number: ${{ needs.get-pr-number.outputs.pr-number }}
# dry-run: false
# secrets:
# nr-api-url: ${{ secrets.NR_API_URL_STAGING }}
# nr-api-token: ${{ secrets.NR_API_TOKEN_STAGING }}
# github-token: ${{ secrets.GITHUB_TOKEN }}
# nr-license-key: ${{ secrets.NEW_RELIC_LICENSE_KEY }}

# production:
# needs: [staging, get-pr-number]
# uses: ./.github/workflows/reusable.quickstart_submission.yml
# with:
# pr-number: ${{ needs.get-pr-number.outputs.pr-number }}
# dry-run: false
# secrets:
# nr-api-url: ${{ secrets.NR_API_URL }}
# nr-api-token: ${{ secrets.NR_API_TOKEN }}
# github-token: ${{ secrets.GITHUB_TOKEN }}
# nr-license-key: ${{ secrets.NEW_RELIC_LICENSE_KEY }}

# eu-production:
# needs: [staging, get-pr-number]
# uses: ./.github/workflows/reusable.quickstart_submission.yml
# with:
# pr-number: ${{ needs.get-pr-number.outputs.pr-number }}
# dry-run: false
# secrets:
# nr-api-url: ${{ secrets.NR_API_URL_EU }}
# nr-api-token: ${{ secrets.NR_API_TOKEN_EU }}
# github-token: ${{ secrets.GITHUB_TOKEN }}
# nr-license-key: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
3 changes: 2 additions & 1 deletion utils/__tests__/validate_install_plans.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { getInstallPlanId } from '../create-validate-install-plans';

import * as fs from 'fs';
import {readFileSync} from 'fs';
const fs = {readFileSync};

jest.mock('@actions/core');
jest.spyOn(global.console, 'error').mockImplementation(() => {});
Expand Down
33 changes: 20 additions & 13 deletions utils/create-validate-data-sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,17 @@ export const getDataSourceId = (filename: string) => {
return config.id;
};

/**
* Entrypoint.
*/
const main = async () => {
const [GITHUB_API_URL, dryRun] = passedProcessArguments();
const githubToken = process.env.GITHUB_TOKEN;
const isDryRun = dryRun === 'true';

if (!githubToken) {
console.error('GITHUB_TOKEN is not defined.');
process.exit(1);
export const createValidateDataSources = async (
ghUrl: string,
ghToken?: string,
isDryRun = false
) => {
if (!ghToken) {
console.warn('GITHUB_TOKEN is not defined.');
}

logger.info(`Fetching files for pull request ${GITHUB_API_URL}`);
const files = await fetchPaginatedGHResults(GITHUB_API_URL, githubToken);
logger.info(`Fetching files for pull request ${ghUrl}`);
const files = await fetchPaginatedGHResults(ghUrl, ghToken);
logger.info(`Found ${files.length} files`);

const dataSources = filterOutTestFiles(files)
Expand Down Expand Up @@ -79,6 +75,17 @@ const main = async () => {
);

const hasFailed = failures.length > 0;
return hasFailed;
};

/**
* Entrypoint.
*/
const main = async () => {
const [ghUrl, isDryRun] = passedProcessArguments();
const ghToken = process.env.GITHUB_TOKEN;
const dryRun = isDryRun === 'true';
const hasFailed = await createValidateDataSources(ghUrl, ghToken, dryRun);

const event = isDryRun
? CUSTOM_EVENT.VALIDATE_DATA_SOURCES
Expand Down
5 changes: 2 additions & 3 deletions utils/create_validate_pr_quickstarts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const installPlanErrorExists = (error: Error | NerdGraphError): boolean =>

const dataSourceErrorExists = (error: Error | NerdGraphError): boolean =>
'extensions' in error &&
error?.extensions?.argumentPath.includes('dataSourceIds') &&
error?.extensions?.argumentPath?.includes('dataSourceIds') &&
error?.message?.includes('contains a data source that does not exist');

export const countAndOutputErrors = (
Expand Down Expand Up @@ -64,8 +64,7 @@ export const createValidateQuickstarts = async (
isDryRun = false
): Promise<boolean> => {
if (!ghToken) {
console.error('GITHUB_TOKEN is not defined.');
return false;
console.warn('GITHUB_TOKEN is not defined.');
}

if (!ghUrl) {
Expand Down
11 changes: 8 additions & 3 deletions utils/lib/github-api-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fetch from 'node-fetch';
import * as parseLinkHeader from 'parse-link-header';
import parseLinkHeader from 'parse-link-header';
import {
QUICKSTART_CONFIG_REGEXP,
DATA_SOURCE_CONFIG_REGEXP,
Expand All @@ -9,6 +9,9 @@ const INSTALL_CONFIG_REGEXP = new RegExp('install/.+/install.+(yml|yaml)');
const MOCK_FILES_REGEXP = new RegExp('mock_files/.+');
const TEMPLATE_REGEXP = new RegExp('_template/.+');

export const generatePrUrl = (prNumber: string | number) =>
`https://api.github.com/repos/newrelic/newrelic-quickstarts/pulls/${prNumber}/files`;

/**
* Pulls the next page off of a `Link` header
* @param {String|Null} linkHeader the `Link` header value
Expand Down Expand Up @@ -50,16 +53,18 @@ export interface GithubAPIPullRequestFile {
*/
export const fetchPaginatedGHResults = async (
url: string,
token: string
token?: string
): Promise<GithubAPIPullRequestFile[]> => {
logger.debug(`Running fetch against ${url}`, { url });
let files: GithubAPIPullRequestFile[] = [];
let nextPageLink: string | null = url;
try {
while (nextPageLink) {
logger.debug(`Fetching ${nextPageLink}`, { url: nextPageLink });

const headers = token ? { authorization: `token ${token}` } : undefined;
const resp = await fetch(nextPageLink, {
headers: { authorization: `token ${token}` },
headers,
});
// TODO: this should happen after the resp.ok check
const responseJson = await resp.json();
Expand Down
8 changes: 4 additions & 4 deletions utils/lib/nr-graphql-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import { Policy } from 'cockatiel';
import fetch, { Response } from 'node-fetch';
import logger from '../logger';

const NR_API_URL = process.env.NR_API_URL || '';
const NR_API_TOKEN = process.env.NR_API_TOKEN || '';

/**
* Build body param for NR GraphQL request
* @param {{queryString, variables}} queryBody - query string and corresponding variables for request
Expand All @@ -44,8 +41,11 @@ export type ErrorOrNerdGraphError = Error | NerdGraphError;
* @returns {Promise<Object>} An object with the results or errors of a GraphQL request
*/
export const fetchNRGraphqlResults = async <Variables, ResponseData>(
queryBody: NerdGraphRequest<Variables>
queryBody: NerdGraphRequest<Variables>,
): Promise<NerdGraphResponseWithLocalErrors<ResponseData>> => {
const NR_API_URL = process.env.NR_API_URL || '';
const NR_API_TOKEN = process.env.NR_API_TOKEN || '';

let results;
let graphqlErrors: ErrorOrNerdGraphError[] = [];

Expand Down
11 changes: 9 additions & 2 deletions utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"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",
"set-dashboards-required-datasources": "ts-node set-dashboards-required-datasources.ts"
"set-dashboards-required-datasources": "ts-node set-dashboards-required-datasources.ts",
"release": "ts-node release.ts"
},
"dependencies": {
"@actions/core": "^1.10.0",
Expand All @@ -49,8 +50,14 @@
"parse-link-header": "^2.0.0",
"prettier": "2.3.2",
"ts-jest": "^27.1.5",
"ts-node": "^10.7.0",
"typescript": "^4.6.4",
"uuid": "^8.3.2"
},
"devDependencies": {
"@inquirer/confirm": "^2.0.15",
"@inquirer/prompts": "^3.3.0",
"@types/prompt-sync": "^4.2.3",
"dotenv": "^16.3.1",
"ts-node": "^10.9.2"
}
}
Loading
Loading