Skip to content

Commit dca8468

Browse files
Update self-hosted environment validation and bump undici version (#556)
* Fix self-hosted environment check * Update isSelfHosted logic
1 parent 691cc35 commit dca8468

File tree

4 files changed

+75
-9
lines changed

4 files changed

+75
-9
lines changed

__tests__/utils.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import {isSelfHosted} from '../src/utils';
2+
3+
describe('utils', () => {
4+
describe('isSelfHosted', () => {
5+
let AGENT_ISSELFHOSTED: string | undefined;
6+
let RUNNER_ENVIRONMENT: string | undefined;
7+
8+
beforeEach(() => {
9+
AGENT_ISSELFHOSTED = process.env['AGENT_ISSELFHOSTED'];
10+
delete process.env['AGENT_ISSELFHOSTED'];
11+
RUNNER_ENVIRONMENT = process.env['RUNNER_ENVIRONMENT'];
12+
delete process.env['RUNNER_ENVIRONMENT'];
13+
});
14+
15+
afterEach(() => {
16+
if (AGENT_ISSELFHOSTED === undefined) {
17+
delete process.env['AGENT_ISSELFHOSTED'];
18+
} else {
19+
process.env['AGENT_ISSELFHOSTED'] = AGENT_ISSELFHOSTED;
20+
}
21+
if (RUNNER_ENVIRONMENT === undefined) {
22+
delete process.env['RUNNER_ENVIRONMENT'];
23+
} else {
24+
process.env['RUNNER_ENVIRONMENT'] = RUNNER_ENVIRONMENT;
25+
}
26+
});
27+
28+
it('isSelfHosted should be true if no environment variables set', () => {
29+
expect(isSelfHosted()).toBeTruthy();
30+
});
31+
32+
it('isSelfHosted should be true if environment variable is not set to denote GitHub hosted', () => {
33+
process.env['RUNNER_ENVIRONMENT'] = 'some';
34+
expect(isSelfHosted()).toBeTruthy();
35+
});
36+
37+
it('isSelfHosted should be true if environment variable set to denote Azure Pipelines self hosted', () => {
38+
process.env['AGENT_ISSELFHOSTED'] = '1';
39+
expect(isSelfHosted()).toBeTruthy();
40+
});
41+
42+
it('isSelfHosted should be false if environment variable set to denote GitHub hosted', () => {
43+
process.env['RUNNER_ENVIRONMENT'] = 'github-hosted';
44+
expect(isSelfHosted()).toBeFalsy();
45+
});
46+
47+
it('isSelfHosted should be false if environment variable is not set to denote Azure Pipelines self hosted', () => {
48+
process.env['AGENT_ISSELFHOSTED'] = 'some';
49+
expect(isSelfHosted()).toBeFalsy();
50+
});
51+
});
52+
});

dist/setup/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93353,8 +93353,7 @@ function cacheWindowsDir(extPath, tool, version, arch) {
9335393353
if (os_1.default.platform() !== 'win32')
9335493354
return false;
9335593355
// make sure the action runs in the hosted environment
93356-
if (process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' &&
93357-
process.env['AGENT_ISSELFHOSTED'] === '1')
93356+
if ((0, utils_1.isSelfHosted)())
9335893357
return false;
9335993358
const defaultToolCacheRoot = process.env['RUNNER_TOOL_CACHE'];
9336093359
if (!defaultToolCacheRoot)
@@ -93861,12 +93860,21 @@ exports.getArch = getArch;
9386193860
"use strict";
9386293861

9386393862
Object.defineProperty(exports, "__esModule", ({ value: true }));
93864-
exports.StableReleaseAlias = void 0;
93863+
exports.isSelfHosted = exports.StableReleaseAlias = void 0;
9386593864
var StableReleaseAlias;
9386693865
(function (StableReleaseAlias) {
9386793866
StableReleaseAlias["Stable"] = "stable";
9386893867
StableReleaseAlias["OldStable"] = "oldstable";
9386993868
})(StableReleaseAlias || (exports.StableReleaseAlias = StableReleaseAlias = {}));
93869+
const isSelfHosted = () => process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' &&
93870+
(process.env['AGENT_ISSELFHOSTED'] === '1' ||
93871+
process.env['AGENT_ISSELFHOSTED'] === undefined);
93872+
exports.isSelfHosted = isSelfHosted;
93873+
/* the above is simplified from:
93874+
process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && process.env['AGENT_ISSELFHOSTED'] === '1'
93875+
||
93876+
process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && process.env['AGENT_ISSELFHOSTED'] === undefined
93877+
*/
9387093878

9387193879

9387293880
/***/ }),

src/installer.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as httpm from '@actions/http-client';
66
import * as sys from './system';
77
import fs from 'fs';
88
import os from 'os';
9-
import {StableReleaseAlias} from './utils';
9+
import {StableReleaseAlias, isSelfHosted} from './utils';
1010

1111
const MANIFEST_REPO_OWNER = 'actions';
1212
const MANIFEST_REPO_NAME = 'go-versions';
@@ -180,11 +180,7 @@ async function cacheWindowsDir(
180180
if (os.platform() !== 'win32') return false;
181181

182182
// make sure the action runs in the hosted environment
183-
if (
184-
process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' &&
185-
process.env['AGENT_ISSELFHOSTED'] === '1'
186-
)
187-
return false;
183+
if (isSelfHosted()) return false;
188184

189185
const defaultToolCacheRoot = process.env['RUNNER_TOOL_CACHE'];
190186
if (!defaultToolCacheRoot) return false;

src/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,13 @@ export enum StableReleaseAlias {
22
Stable = 'stable',
33
OldStable = 'oldstable'
44
}
5+
6+
export const isSelfHosted = (): boolean =>
7+
process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' &&
8+
(process.env['AGENT_ISSELFHOSTED'] === '1' ||
9+
process.env['AGENT_ISSELFHOSTED'] === undefined);
10+
/* the above is simplified from:
11+
process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && process.env['AGENT_ISSELFHOSTED'] === '1'
12+
||
13+
process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' && process.env['AGENT_ISSELFHOSTED'] === undefined
14+
*/

0 commit comments

Comments
 (0)