diff --git a/__tests__/lib/fetch.test.ts b/__tests__/lib/fetch.test.ts index d4abe9454..85b61a99d 100644 --- a/__tests__/lib/fetch.test.ts +++ b/__tests__/lib/fetch.test.ts @@ -4,10 +4,13 @@ import { Headers } from 'node-fetch'; import pkg from '../../package.json'; import fetch, { cleanHeaders, handleRes } from '../../src/lib/fetch'; +import * as isCI from '../../src/lib/isCI'; import getAPIMock from '../helpers/get-api-mock'; describe('#fetch()', () => { describe('GitHub Actions environment', () => { + let spy: jest.SpyInstance; + // List of all GitHub Actions env variables: // https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables beforeEach(() => { @@ -18,6 +21,8 @@ describe('#fetch()', () => { process.env.GITHUB_RUN_ID = '1658821493'; process.env.GITHUB_RUN_NUMBER = '3'; process.env.GITHUB_SHA = 'ffac537e6cbbf934b08745a378932722df287a53'; + spy = jest.spyOn(isCI, 'isGHA'); + spy.mockReturnValue(true); }); afterEach(() => { @@ -28,6 +33,7 @@ describe('#fetch()', () => { delete process.env.GITHUB_RUN_ID; delete process.env.GITHUB_RUN_NUMBER; delete process.env.GITHUB_SHA; + spy.mockReset(); }); it('should have correct headers for requests in GitHub Action env', async () => { diff --git a/package-lock.json b/package-lock.json index d767d7c89..322dc1f79 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,8 @@ "license": "MIT", "dependencies": { "@actions/core": "^1.6.0", - "@npmcli/ci-detect": "^3.0.0", "chalk": "^4.1.2", + "ci-info": "^3.6.1", "command-line-args": "^5.2.0", "command-line-usage": "^6.0.2", "config": "^3.1.0", @@ -53,7 +53,6 @@ "@types/jsonpath": "^0.2.0", "@types/mime-types": "^2.1.1", "@types/node-fetch": "^2.6.2", - "@types/npmcli__ci-detect": "^2.0.0", "@types/parse-link-header": "^2.0.0", "@types/prompts": "^2.0.14", "@types/semver": "^7.3.12", @@ -1383,14 +1382,6 @@ "node": ">= 8" } }, - "node_modules/@npmcli/ci-detect": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@npmcli/ci-detect/-/ci-detect-3.0.1.tgz", - "integrity": "sha512-zQ/qTg2eWnGDToPZH5n7FggNlGC2OYWl6TZv/kDZrTttpm3y2bBcybXSIjlr1ne/ecVp4/vmRNxZP7qTMZo90g==", - "engines": { - "node": "^14.17.0 || ^16.13.0 || >=18.0.0" - } - }, "node_modules/@pkgr/utils": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@pkgr/utils/-/utils-2.3.0.tgz", @@ -1837,12 +1828,6 @@ "integrity": "sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==", "dev": true }, - "node_modules/@types/npmcli__ci-detect": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@types/npmcli__ci-detect/-/npmcli__ci-detect-2.0.0.tgz", - "integrity": "sha512-Nzom9KQvlBNk3gLWKThXZ+DhX/uZ6sDOltOgPFNONo30wi9fePwuwd6V+4+ES9vY+/SVMP4S7Z3QQHXhidAYyg==", - "dev": true - }, "node_modules/@types/parse-link-header": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@types/parse-link-header/-/parse-link-header-2.0.0.tgz", @@ -2733,10 +2718,12 @@ } }, "node_modules/ci-info": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.5.0.tgz", - "integrity": "sha512-yH4RezKOGlOhxkmhbeNuC4eYZKAUsEaGtBuBzDDP1eFUKiccDWzBABxBfOx31IDwDIXMTxWuwAxUGModvkbuVw==", - "dev": true + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.6.1.tgz", + "integrity": "sha512-up5ggbaDqOqJ4UqLKZ2naVkyqSJQgJi5lwD6b6mM748ysrghDBX0bx/qJTUHzw7zu6Mq4gycviSF5hJnwceD8w==", + "engines": { + "node": ">=8" + } }, "node_modules/cjs-module-lexer": { "version": "1.2.2", @@ -10418,11 +10405,6 @@ "fastq": "^1.6.0" } }, - "@npmcli/ci-detect": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@npmcli/ci-detect/-/ci-detect-3.0.1.tgz", - "integrity": "sha512-zQ/qTg2eWnGDToPZH5n7FggNlGC2OYWl6TZv/kDZrTttpm3y2bBcybXSIjlr1ne/ecVp4/vmRNxZP7qTMZo90g==" - }, "@pkgr/utils": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@pkgr/utils/-/utils-2.3.0.tgz", @@ -10828,12 +10810,6 @@ "integrity": "sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==", "dev": true }, - "@types/npmcli__ci-detect": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@types/npmcli__ci-detect/-/npmcli__ci-detect-2.0.0.tgz", - "integrity": "sha512-Nzom9KQvlBNk3gLWKThXZ+DhX/uZ6sDOltOgPFNONo30wi9fePwuwd6V+4+ES9vY+/SVMP4S7Z3QQHXhidAYyg==", - "dev": true - }, "@types/parse-link-header": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@types/parse-link-header/-/parse-link-header-2.0.0.tgz", @@ -11425,10 +11401,9 @@ "dev": true }, "ci-info": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.5.0.tgz", - "integrity": "sha512-yH4RezKOGlOhxkmhbeNuC4eYZKAUsEaGtBuBzDDP1eFUKiccDWzBABxBfOx31IDwDIXMTxWuwAxUGModvkbuVw==", - "dev": true + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.6.1.tgz", + "integrity": "sha512-up5ggbaDqOqJ4UqLKZ2naVkyqSJQgJi5lwD6b6mM748ysrghDBX0bx/qJTUHzw7zu6Mq4gycviSF5hJnwceD8w==" }, "cjs-module-lexer": { "version": "1.2.2", diff --git a/package.json b/package.json index a8b5c52a9..d348a5d36 100644 --- a/package.json +++ b/package.json @@ -36,8 +36,8 @@ }, "dependencies": { "@actions/core": "^1.6.0", - "@npmcli/ci-detect": "^3.0.0", "chalk": "^4.1.2", + "ci-info": "^3.6.1", "command-line-args": "^5.2.0", "command-line-usage": "^6.0.2", "config": "^3.1.0", @@ -76,7 +76,6 @@ "@types/jsonpath": "^0.2.0", "@types/mime-types": "^2.1.1", "@types/node-fetch": "^2.6.2", - "@types/npmcli__ci-detect": "^2.0.0", "@types/parse-link-header": "^2.0.0", "@types/prompts": "^2.0.14", "@types/semver": "^7.3.12", diff --git a/src/lib/isCI.ts b/src/lib/isCI.ts index 0c1e06776..bc1afd969 100644 --- a/src/lib/isCI.ts +++ b/src/lib/isCI.ts @@ -1,4 +1,4 @@ -import ciDetect from '@npmcli/ci-detect'; +import ci from 'ci-info'; /** * Small env check to determine if we're in a GitHub Actions environment. @@ -6,7 +6,7 @@ import ciDetect from '@npmcli/ci-detect'; * @see {@link https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables} */ export function isGHA() { - return ciDetect() === 'github-actions'; + return ci.GITHUB_ACTIONS; } /** @@ -40,5 +40,5 @@ export function isNpmScript() { */ export default function isCI() { /* istanbul ignore next */ - return (ciDetect() && !isTest()) || !!process.env.TEST_RDME_CI; + return (ci.isCI && !isTest()) || !!process.env.TEST_RDME_CI; }