diff --git a/.envrc.example b/.envrc.example new file mode 100644 index 00000000..b3e446af --- /dev/null +++ b/.envrc.example @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +export GRAPHQL_HOST='https://api.nes.herodevs.com'; +export EOL_REPORT_URL='https://eol-report-card.apps.herodevs.com/reports'; diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 472295fe..8db13975 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,9 @@ jobs: - windows-latest name: "${{matrix.platform}} w/ Node.js ${{matrix.node}}.x" runs-on: ${{matrix.platform}} + env: + GRAPHQL_HOST: ${{ secrets.GRAPHQL_HOST }} + EOL_REPORT_URL: ${{ secrets.EOL_REPORT_URL }} steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: "Use Node.js ${{matrix.node}}.x" diff --git a/.github/workflows/dry-run.yml b/.github/workflows/dry-run.yml index 75de3e8d..065381e3 100644 --- a/.github/workflows/dry-run.yml +++ b/.github/workflows/dry-run.yml @@ -32,6 +32,9 @@ jobs: test: runs-on: ubuntu-latest needs: check-version + env: + GRAPHQL_HOST: ${{ secrets.GRAPHQL_HOST }} + EOL_REPORT_URL: ${{ secrets.EOL_REPORT_URL }} steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 diff --git a/.github/workflows/manual-release.yml b/.github/workflows/manual-release.yml index aad21db2..5e2cbe33 100644 --- a/.github/workflows/manual-release.yml +++ b/.github/workflows/manual-release.yml @@ -46,6 +46,9 @@ jobs: test: runs-on: ubuntu-latest needs: check-version + env: + GRAPHQL_HOST: ${{ secrets.GRAPHQL_HOST }} + EOL_REPORT_URL: ${{ secrets.EOL_REPORT_URL }} steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 diff --git a/.gitignore b/.gitignore index 0e57e95e..61deaad9 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ yarn.lock pnpm-lock.yaml **/packages/cli-*/bin/ **/tsconfig.tsbuildinfo +.envrc diff --git a/bin/dev.js b/bin/dev.js index 0451d4b8..2874bd45 100755 --- a/bin/dev.js +++ b/bin/dev.js @@ -1,8 +1,5 @@ #!/usr/bin/env node -process.env.GRAPHQL_HOST = 'https://api.dev.nes.herodevs.com'; -process.env.EOL_REPORT_URL = 'https://eol-report-card.stage.apps.herodevs.io/reports'; - import main from './main.js'; try { diff --git a/e2e/scan/eol.test.ts b/e2e/scan/eol.test.ts index 798b95d9..1165ef44 100644 --- a/e2e/scan/eol.test.ts +++ b/e2e/scan/eol.test.ts @@ -1,4 +1,4 @@ -import { doesNotThrow } from 'node:assert'; +import { doesNotThrow, notStrictEqual } from 'node:assert'; import { doesNotMatch, match, strictEqual } from 'node:assert/strict'; import { exec } from 'node:child_process'; import { existsSync, readFileSync, unlinkSync } from 'node:fs'; @@ -12,14 +12,19 @@ import { config } from '../../src/config/constants'; const execAsync = promisify(exec); -const GRAPHQL_HOST = 'https://api.dev.nes.herodevs.com'; +describe('environment', () => { + it('should not be configured to run against the production environment', () => { + notStrictEqual(process.env.GRAPHQL_HOST, 'https://api.nes.herodevs.com'); + notStrictEqual(process.env.EOL_REPORT_URL, 'https://eol-report-card.apps.herodevs.io/reports'); + notStrictEqual(config.graphqlHost, 'https://api.nes.herodevs.com'); + notStrictEqual(config.eolReportUrl, 'https://eol-report-card.apps.herodevs.io/reports'); + }); +}); describe('default arguments', () => { it('defaults to scan:eol -t when no arguments are provided', async () => { // Run the CLI directly with no arguments - const { stdout } = await execAsync('node bin/run.js', { - env: { ...process.env, GRAPHQL_HOST }, - }); + const { stdout } = await execAsync('node bin/run.js'); // Match table header match(stdout, /┌.*┬.*┬.*┬.*┬.*┐/, 'Should show table top border'); @@ -42,9 +47,7 @@ describe('default arguments', () => { }); it('runs scan:eol -a -t when -a -t is passed in', async () => { - const { stdout, stderr } = await execAsync('node bin/run.js -a -t', { - env: { ...process.env, GRAPHQL_HOST }, - }); + const { stdout, stderr } = await execAsync('node bin/run.js -a -t'); // Verify command executed successfully match(stdout, /components scanned/, 'Should show components scanned message'); @@ -52,9 +55,7 @@ describe('default arguments', () => { it('runs scan:eol --json when --json is passed in', async () => { // Run the CLI with --json flag - const { stdout } = await execAsync('node bin/run.js --json', { - env: { ...process.env, GRAPHQL_HOST }, - }); + const { stdout } = await execAsync('node bin/run.js --json'); // Verify JSON output doesNotMatch(stdout, /Here are the results of the scan:/, 'Should not show results header'); @@ -62,9 +63,7 @@ describe('default arguments', () => { }); it('shows help for scan:eol when --help is passed in', async () => { - const { stdout } = await execAsync('node bin/run.js --help', { - env: { ...process.env, GRAPHQL_HOST }, - }); + const { stdout } = await execAsync('node bin/run.js --help'); // Verify help output match(stdout, /USAGE/, 'Should show usage section'); @@ -73,9 +72,7 @@ describe('default arguments', () => { }); it('shows global help when help is passed in', async () => { - const { stdout } = await execAsync('node bin/run.js help', { - env: { ...process.env, GRAPHQL_HOST }, - }); + const { stdout } = await execAsync('node bin/run.js help'); // Verify help output match(stdout, /USAGE/, 'Should show usage section'); @@ -96,9 +93,6 @@ describe('scan:eol e2e', () => { const angular17Purls = path.resolve(__dirname, '../fixtures/npm/angular-17.purls.json'); async function run(cmd: string) { - // Set up environment - process.env.GRAPHQL_HOST = GRAPHQL_HOST; - // Ensure fixtures directory exists and is clean await mkdir(fixturesDir, { recursive: true }); @@ -159,7 +153,7 @@ describe('scan:eol e2e', () => { unlinkSync(reportPath); }); - it('scans extra-large.purls.json for EOL components', async () => { + it.skip('scans extra-large.purls.json for EOL components', async () => { const cmd = `scan:eol --purls ${extraLargePurlsPath}`; const { stdout } = await run(cmd); @@ -306,10 +300,6 @@ describe('scan:eol e2e directory', () => { const reportPath = path.join(simpleDir, 'eol.report.json'); async function run(cmd: string) { - // Set up environment - process.env.GRAPHQL_HOST = GRAPHQL_HOST; - // process.env.GRAPHQL_HOST = 'http://localhost:3000'; - // Ensure test directory exists and is clean await mkdir(simpleDir, { recursive: true }); diff --git a/src/api/nes/nes.client.ts b/src/api/nes/nes.client.ts index ac15f7b8..6284275a 100644 --- a/src/api/nes/nes.client.ts +++ b/src/api/nes/nes.client.ts @@ -50,6 +50,7 @@ function submitScan(purls: string[], options: ScanInputOptions): Promise