Skip to content
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
6 changes: 6 additions & 0 deletions __tests__/lib/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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(() => {
Expand All @@ -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 () => {
Expand Down
45 changes: 10 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚮

"@types/parse-link-header": "^2.0.0",
"@types/prompts": "^2.0.14",
"@types/semver": "^7.3.12",
Expand Down
6 changes: 3 additions & 3 deletions src/lib/isCI.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ciDetect from '@npmcli/ci-detect';
import ci from 'ci-info';

/**
* Small env check to determine if we're in a GitHub Actions environment.
*
* @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;
}

/**
Expand Down Expand Up @@ -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;
}