Skip to content

Commit 846cac2

Browse files
authored
Merge pull request #396 from crazy-max/github-isghes
github: isGHES func
2 parents 931b62d + 83d63d1 commit 846cac2

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

__tests__/github.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,28 @@ describe('apiURL', () => {
8585
});
8686
});
8787

88+
describe('isGHES', () => {
89+
afterEach(() => {
90+
process.env.GITHUB_SERVER_URL = '';
91+
});
92+
it('should return false when the request domain is github.com', () => {
93+
process.env.GITHUB_SERVER_URL = 'https://github.com';
94+
expect(GitHub.isGHES).toBe(false);
95+
});
96+
it('should return false when the request domain ends with ghe.com', () => {
97+
process.env.GITHUB_SERVER_URL = 'https://my.domain.ghe.com';
98+
expect(GitHub.isGHES).toBe(false);
99+
});
100+
it('should return false when the request domain ends with ghe.localhost', () => {
101+
process.env.GITHUB_SERVER_URL = 'https://my.domain.ghe.localhost';
102+
expect(GitHub.isGHES).toBe(false);
103+
});
104+
it('should return true when the request domain is specific to an enterprise', () => {
105+
process.env.GITHUB_SERVER_URL = 'https://my-enterprise.github.com';
106+
expect(GitHub.isGHES).toBe(true);
107+
});
108+
});
109+
88110
describe('repository', () => {
89111
it('returns GitHub repository', async () => {
90112
expect(GitHub.repository).toEqual('docker/actions-toolkit');

src/github.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import os from 'os';
2222
import path from 'path';
2323
import {CreateArtifactRequest, FinalizeArtifactRequest, StringValue} from '@actions/artifact/lib/generated';
2424
import {internalArtifactTwirpClient} from '@actions/artifact/lib/internal/shared/artifact-twirp-client';
25-
import {isGhes} from '@actions/artifact/lib/internal/shared/config';
2625
import {getBackendIdsFromToken} from '@actions/artifact/lib/internal/shared/util';
2726
import {getExpiration} from '@actions/artifact/lib/internal/upload/retention';
2827
import {InvalidResponseError, NetworkError} from '@actions/artifact';
@@ -67,6 +66,14 @@ export class GitHub {
6766
return process.env.GITHUB_API_URL || 'https://api.github.com';
6867
}
6968

69+
static get isGHES(): boolean {
70+
const serverURL = new URL(GitHub.serverURL);
71+
const hostname = serverURL.hostname.trimEnd().toUpperCase();
72+
const isGitHubHost = hostname === 'GITHUB.COM';
73+
const isGHESHost = hostname.endsWith('.GHE.COM') || hostname.endsWith('.GHE.LOCALHOST');
74+
return !isGitHubHost && !isGHESHost;
75+
}
76+
7077
static get repository(): string {
7178
return `${github.context.repo.owner}/${github.context.repo.repo}`;
7279
}
@@ -124,7 +131,7 @@ export class GitHub {
124131
}
125132

126133
public static async uploadArtifact(opts: UploadArtifactOpts): Promise<UploadArtifactResponse> {
127-
if (isGhes()) {
134+
if (GitHub.isGHES) {
128135
throw new Error('@actions/artifact v2.0.0+ is currently not supported on GHES.');
129136
}
130137

0 commit comments

Comments
 (0)