feat: Add GHES support 🏢 (#580)
Changes for #579 Co-authored-by: dom <dominik.meyer01@sap.com>
This commit is contained in:
parent
a0db9b66be
commit
3623583f73
|
@ -4,3 +4,4 @@ coverage
|
|||
.eslintcache
|
||||
.env
|
||||
node_modules
|
||||
.husky/_
|
|
@ -57,7 +57,11 @@ All Actions runners: Linux (Ubuntu), macOS, and Windows are supported.
|
|||
|
||||
2. WIP, See [Issue #87](https://github.com/peaceiris/actions-gh-pages/issues/87)
|
||||
|
||||
### GitHub Enterprise Server Support
|
||||
|
||||
✅️ GitHub Enterprise Server is supported above `2.22.6`.
|
||||
|
||||
Note that the `GITHUB_TOKEN` that is created by the runner might not inherently have push/publish privileges on GHES. You might need to create/request a technical user with write permissions to your target repository.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
import {setPersonalToken, setGithubToken} from '../src/set-tokens';
|
||||
|
||||
const OLD_ENV = process.env;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
process.env = {...OLD_ENV};
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
process.env = OLD_ENV; // Restore old environment
|
||||
});
|
||||
|
||||
describe('setGithubToken()', () => {
|
||||
test('return remote url with GITHUB_TOKEN gh-pages', () => {
|
||||
process.env.GITHUB_SERVER_URL = 'https://github.enterprise.server';
|
||||
const expected = 'https://x-access-token:GITHUB_TOKEN@github.enterprise.server/owner/repo.git';
|
||||
const test = setGithubToken(
|
||||
'GITHUB_TOKEN',
|
||||
'owner/repo',
|
||||
'gh-pages',
|
||||
'',
|
||||
'refs/heads/master',
|
||||
'push'
|
||||
);
|
||||
expect(test).toMatch(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setPersonalToken()', () => {
|
||||
test('return remote url with personal access token', () => {
|
||||
process.env.GITHUB_SERVER_URL = 'https://github.enterprise.server';
|
||||
const expected = 'https://x-access-token:pat@github.enterprise.server/owner/repo.git';
|
||||
const test = setPersonalToken('pat', 'owner/repo');
|
||||
expect(test).toMatch(expected);
|
||||
});
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
module.exports=(()=>{var e={607:(e,r,t)=>{e=t.nmd(e);if(require.main!==e){throw new Error("This file should not be required")}var i=t(129);var s=t(747);var a=process.argv[2];var d=s.readFileSync(a,"utf8");var o=JSON.parse(d);var p=o.command;var _=o.execOptions;var c=o.pipe;var u=o.stdoutFile;var n=o.stderrFile;var l=i.exec(p,_,function(e){if(!e){process.exitCode=0}else if(e.code===undefined){process.exitCode=1}else{process.exitCode=e.code}});var v=s.createWriteStream(u);var f=s.createWriteStream(n);l.stdout.pipe(v);l.stderr.pipe(f);l.stdout.pipe(process.stdout);l.stderr.pipe(process.stderr);if(c){l.stdin.end(c)}},129:e=>{"use strict";e.exports=require("child_process")},747:e=>{"use strict";e.exports=require("fs")}};var r={};function __nccwpck_require__(t){if(r[t]){return r[t].exports}var i=r[t]={id:t,loaded:false,exports:{}};var s=true;try{e[t](i,i.exports,__nccwpck_require__);s=false}finally{if(s)delete r[t]}i.loaded=true;return i.exports}(()=>{__nccwpck_require__.nmd=(e=>{e.paths=[];if(!e.children)e.children=[];return e})})();__nccwpck_require__.ab=__dirname+"/";return __nccwpck_require__(607)})();
|
File diff suppressed because one or more lines are too long
|
@ -7,6 +7,7 @@
|
|||
"": {
|
||||
"name": "actions-github-pages",
|
||||
"version": "3.7.3",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
|
|
|
@ -3,6 +3,7 @@ import * as exec from '@actions/exec';
|
|||
import * as glob from '@actions/glob';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import {URL} from 'url';
|
||||
import {Inputs, CmdResult} from './interfaces';
|
||||
import {createDir} from './utils';
|
||||
import {cp, rm} from 'shelljs';
|
||||
|
@ -13,6 +14,10 @@ export async function createBranchForce(branch: string): Promise<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
export function getServerUrl(): URL {
|
||||
return new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
||||
}
|
||||
|
||||
export async function deleteExcludedAssets(destDir: string, excludeAssets: string): Promise<void> {
|
||||
if (excludeAssets === '') return;
|
||||
core.info(`[INFO] delete excluded assets`);
|
||||
|
|
|
@ -10,6 +10,7 @@ const cpSpawnSync = require('child_process').spawnSync;
|
|||
const cpexec = require('child_process').execFileSync;
|
||||
import {Inputs} from './interfaces';
|
||||
import {getHomeDir} from './utils';
|
||||
import {getServerUrl} from './git-utils';
|
||||
|
||||
export async function setSSHKey(inps: Inputs, publishRepo: string): Promise<string> {
|
||||
core.info('[INFO] setup SSH deploy key');
|
||||
|
@ -20,10 +21,12 @@ export async function setSSHKey(inps: Inputs, publishRepo: string): Promise<stri
|
|||
await exec.exec('chmod', ['700', sshDir]);
|
||||
|
||||
const knownHosts = path.join(sshDir, 'known_hosts');
|
||||
// ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts on Ubuntu
|
||||
// ssh-keyscan -t rsa github.com or serverUrl >> ~/.ssh/known_hosts on Ubuntu
|
||||
const cmdSSHkeyscanOutput = `\
|
||||
# github.com:22 SSH-2.0-babeld-1f0633a6
|
||||
github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
|
||||
# ${getServerUrl().host}.com:22 SSH-2.0-babeld-1f0633a6
|
||||
${
|
||||
getServerUrl().host
|
||||
} ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
|
||||
`;
|
||||
fs.writeFileSync(knownHosts, cmdSSHkeyscanOutput + '\n');
|
||||
core.info(`[INFO] wrote ${knownHosts}`);
|
||||
|
@ -36,8 +39,8 @@ github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXY
|
|||
|
||||
const sshConfigPath = path.join(sshDir, 'config');
|
||||
const sshConfigContent = `\
|
||||
Host github
|
||||
HostName github.com
|
||||
Host ${getServerUrl().host}
|
||||
HostName ${getServerUrl().host}
|
||||
IdentityFile ~/.ssh/github
|
||||
User git
|
||||
`;
|
||||
|
@ -60,7 +63,7 @@ Watch https://github.com/peaceiris/actions-gh-pages/issues/87
|
|||
core.exportVariable('SSH_AUTH_SOCK', '/tmp/ssh-auth.sock');
|
||||
await exec.exec('ssh-add', [idRSA]);
|
||||
|
||||
return `git@github.com:${publishRepo}.git`;
|
||||
return `git@${getServerUrl().host}:${publishRepo}.git`;
|
||||
}
|
||||
|
||||
export function setGithubToken(
|
||||
|
@ -94,12 +97,12 @@ This operation is prohibited to protect your contents
|
|||
}
|
||||
}
|
||||
|
||||
return `https://x-access-token:${githubToken}@github.com/${publishRepo}.git`;
|
||||
return `https://x-access-token:${githubToken}@${getServerUrl().host}/${publishRepo}.git`;
|
||||
}
|
||||
|
||||
export function setPersonalToken(personalToken: string, publishRepo: string): string {
|
||||
core.info('[INFO] setup personal access token');
|
||||
return `https://x-access-token:${personalToken}@github.com/${publishRepo}.git`;
|
||||
return `https://x-access-token:${personalToken}@${getServerUrl().host}/${publishRepo}.git`;
|
||||
}
|
||||
|
||||
export function getPublishRepo(externalRepository: string, owner: string, repo: string): string {
|
||||
|
|
Loading…
Reference in New Issue