Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85405d4dd5 | ||
|
|
d85d214cc6 | ||
|
|
b9a6975827 | ||
|
|
7c4b591cf6 | ||
|
|
0b1dd44709 | ||
|
|
e1bf32ad68 | ||
|
|
61b479a8a4 |
18
CHANGELOG.md
18
CHANGELOG.md
@@ -2,6 +2,24 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||||
|
|
||||||
|
# [3.3.0-0](https://github.com/peaceiris/actions-gh-pages/compare/v3.2.0...v3.3.0-0) (2020-02-20)
|
||||||
|
|
||||||
|
|
||||||
|
### chore
|
||||||
|
|
||||||
|
* Add vim ([b9a6975](https://github.com/peaceiris/actions-gh-pages/commit/b9a697582713e95c1d628172933226631d3825af))
|
||||||
|
|
||||||
|
### deps
|
||||||
|
|
||||||
|
* bump @types/jest from 25.1.2 to 25.1.3 (#118) ([0b1dd44](https://github.com/peaceiris/actions-gh-pages/commit/0b1dd44709acc2ba27cf43e181767b92e78d1577)), closes [#118](https://github.com/peaceiris/actions-gh-pages/issues/118)
|
||||||
|
* bump ts-jest from 25.2.0 to 25.2.1 (#117) ([e1bf32a](https://github.com/peaceiris/actions-gh-pages/commit/e1bf32ad68fadb9a32147579d6dc49b51d6ddefb)), closes [#117](https://github.com/peaceiris/actions-gh-pages/issues/117)
|
||||||
|
|
||||||
|
### feat
|
||||||
|
|
||||||
|
* Add disable_nojekyll and cname options ([7c4b591](https://github.com/peaceiris/actions-gh-pages/commit/7c4b591cf65cf4daf0464fba89b32ff4e764b427)), closes [#112](https://github.com/peaceiris/actions-gh-pages/issues/112)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [3.2.0](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.0...v3.2.0) (2020-02-19)
|
# [3.2.0](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.0...v3.2.0) (2020-02-19)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ RUN apt-get update && \
|
|||||||
libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev autoconf \
|
libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev autoconf \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
wget \
|
wget \
|
||||||
ssh && \
|
ssh \
|
||||||
|
vim && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
WORKDIR /git
|
WORKDIR /git
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ afterEach(() => {
|
|||||||
delete process.env['INPUT_COMMIT_MESSAGE'];
|
delete process.env['INPUT_COMMIT_MESSAGE'];
|
||||||
delete process.env['INPUT_TAG_NAME'];
|
delete process.env['INPUT_TAG_NAME'];
|
||||||
delete process.env['INPUT_TAG_MESSAGE'];
|
delete process.env['INPUT_TAG_MESSAGE'];
|
||||||
|
delete process.env['INPUT_DISABLE_NOJEKYLL'];
|
||||||
|
delete process.env['INPUT_CNAME'];
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getInputs()', () => {
|
describe('getInputs()', () => {
|
||||||
@@ -30,15 +32,6 @@ describe('getInputs()', () => {
|
|||||||
// process.env['INPUT_PERSONAL_TOKEN'] = 'test_personal_token';
|
// process.env['INPUT_PERSONAL_TOKEN'] = 'test_personal_token';
|
||||||
process.env['INPUT_PUBLISH_BRANCH'] = 'gh-pages';
|
process.env['INPUT_PUBLISH_BRANCH'] = 'gh-pages';
|
||||||
process.env['INPUT_PUBLISH_DIR'] = 'public';
|
process.env['INPUT_PUBLISH_DIR'] = 'public';
|
||||||
// process.env['INPUT_EXTERNAL_REPOSITORY'] = 'user/repo';
|
|
||||||
// process.env['INPUT_ALLOW_EMPTY_COMMIT'] = 'true';
|
|
||||||
// process.env['INPUT_KEEP_FILES'] = 'true';
|
|
||||||
// process.env['INPUT_FORCE_ORPHAN'] = 'true';
|
|
||||||
// process.env['INPUT_USER_NAME'] = 'username';
|
|
||||||
// process.env['INPUT_USER_EMAIL'] = 'github@github.com';
|
|
||||||
// process.env['INPUT_COMMIT_MESSAGE'] = 'feat: Add new feature';
|
|
||||||
// process.env['INPUT_TAG_NAME'] = 'deploy-v1.2.3';
|
|
||||||
// process.env['INPUT_TAG_MESSAGE'] = 'Deployment v1.2.3';
|
|
||||||
|
|
||||||
const inps: Inputs = getInputs();
|
const inps: Inputs = getInputs();
|
||||||
|
|
||||||
@@ -56,6 +49,8 @@ describe('getInputs()', () => {
|
|||||||
expect(inps.CommitMessage).toMatch('');
|
expect(inps.CommitMessage).toMatch('');
|
||||||
expect(inps.TagName).toMatch('');
|
expect(inps.TagName).toMatch('');
|
||||||
expect(inps.TagMessage).toMatch('');
|
expect(inps.TagMessage).toMatch('');
|
||||||
|
expect(inps.DisableNoJekyll).toBe(false);
|
||||||
|
expect(inps.CNAME).toMatch('');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('get spec inputs', () => {
|
test('get spec inputs', () => {
|
||||||
@@ -73,6 +68,8 @@ describe('getInputs()', () => {
|
|||||||
process.env['INPUT_COMMIT_MESSAGE'] = 'feat: Add new feature';
|
process.env['INPUT_COMMIT_MESSAGE'] = 'feat: Add new feature';
|
||||||
process.env['INPUT_TAG_NAME'] = 'deploy-v1.2.3';
|
process.env['INPUT_TAG_NAME'] = 'deploy-v1.2.3';
|
||||||
process.env['INPUT_TAG_MESSAGE'] = 'Deployment v1.2.3';
|
process.env['INPUT_TAG_MESSAGE'] = 'Deployment v1.2.3';
|
||||||
|
process.env['INPUT_DISABLE_NOJEKYLL'] = 'true';
|
||||||
|
process.env['INPUT_CNAME'] = 'github.com';
|
||||||
|
|
||||||
const inps: Inputs = getInputs();
|
const inps: Inputs = getInputs();
|
||||||
|
|
||||||
@@ -90,5 +87,7 @@ describe('getInputs()', () => {
|
|||||||
expect(inps.CommitMessage).toMatch('feat: Add new feature');
|
expect(inps.CommitMessage).toMatch('feat: Add new feature');
|
||||||
expect(inps.TagName).toMatch('deploy-v1.2.3');
|
expect(inps.TagName).toMatch('deploy-v1.2.3');
|
||||||
expect(inps.TagMessage).toMatch('Deployment v1.2.3');
|
expect(inps.TagMessage).toMatch('Deployment v1.2.3');
|
||||||
|
expect(inps.DisableNoJekyll).toBe(true);
|
||||||
|
expect(inps.CNAME).toMatch('github.com');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
160
__tests__/utils.test.ts
Normal file
160
__tests__/utils.test.ts
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
import {
|
||||||
|
getHomeDir,
|
||||||
|
getWorkDirName,
|
||||||
|
createWorkDir,
|
||||||
|
addNoJekyll,
|
||||||
|
addCNAME
|
||||||
|
} from '../src/utils';
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
|
});
|
||||||
|
|
||||||
|
// afterEach(() => {
|
||||||
|
|
||||||
|
// });
|
||||||
|
|
||||||
|
describe('getHomeDir()', () => {
|
||||||
|
test('get home directory name', async () => {
|
||||||
|
let test = '';
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
test = 'C:\\Users\\runneradmin';
|
||||||
|
} else {
|
||||||
|
test = `${process.env.HOME}`;
|
||||||
|
}
|
||||||
|
const homeDir = await getHomeDir();
|
||||||
|
expect(homeDir).toMatch(test);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
async function getWorkDir(): Promise<string> {
|
||||||
|
const date = new Date();
|
||||||
|
const unixTime = date.getTime();
|
||||||
|
let workDir = '';
|
||||||
|
workDir = await getWorkDirName(`${unixTime}`);
|
||||||
|
await createWorkDir(workDir);
|
||||||
|
return workDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('addNoJekyll()', () => {
|
||||||
|
test('add .nojekyll gh-pages', async () => {
|
||||||
|
let workDir = '';
|
||||||
|
(async (): Promise<void> => {
|
||||||
|
workDir = await getWorkDir();
|
||||||
|
})();
|
||||||
|
const filepath = path.join(workDir, '.nojekyll');
|
||||||
|
|
||||||
|
await addNoJekyll(workDir, false, 'gh-pages');
|
||||||
|
const test1 = fs.existsSync(filepath);
|
||||||
|
expect(test1).toBe(true);
|
||||||
|
|
||||||
|
fs.unlinkSync(filepath);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('add .nojekyll master', async () => {
|
||||||
|
let workDir = '';
|
||||||
|
(async (): Promise<void> => {
|
||||||
|
workDir = await getWorkDir();
|
||||||
|
})();
|
||||||
|
const filepath = path.join(workDir, '.nojekyll');
|
||||||
|
|
||||||
|
await addNoJekyll(workDir, false, 'master');
|
||||||
|
const test2 = fs.existsSync(filepath);
|
||||||
|
expect(test2).toBe(true);
|
||||||
|
|
||||||
|
fs.unlinkSync(filepath);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('not add .nojekyll disable_nojekyll gh-pages', async () => {
|
||||||
|
let workDir = '';
|
||||||
|
(async (): Promise<void> => {
|
||||||
|
workDir = await getWorkDir();
|
||||||
|
})();
|
||||||
|
const filepath = path.join(workDir, '.nojekyll');
|
||||||
|
|
||||||
|
await addNoJekyll(workDir, true, 'gh-pages');
|
||||||
|
const test3 = fs.existsSync(filepath);
|
||||||
|
expect(test3).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('not add .nojekyll disable_nojekyll master', async () => {
|
||||||
|
let workDir = '';
|
||||||
|
(async (): Promise<void> => {
|
||||||
|
workDir = await getWorkDir();
|
||||||
|
})();
|
||||||
|
const filepath = path.join(workDir, '.nojekyll');
|
||||||
|
|
||||||
|
await addNoJekyll(workDir, true, 'master');
|
||||||
|
const test4 = fs.existsSync(filepath);
|
||||||
|
expect(test4).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('not add .nojekyll other-branch', async () => {
|
||||||
|
let workDir = '';
|
||||||
|
(async (): Promise<void> => {
|
||||||
|
workDir = await getWorkDir();
|
||||||
|
})();
|
||||||
|
const filepath = path.join(workDir, '.nojekyll');
|
||||||
|
|
||||||
|
await addNoJekyll(workDir, false, 'other-branch');
|
||||||
|
const test5 = fs.existsSync(filepath);
|
||||||
|
expect(test5).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('not add .nojekyll disable_nojekyll other-branch', async () => {
|
||||||
|
let workDir = '';
|
||||||
|
(async (): Promise<void> => {
|
||||||
|
workDir = await getWorkDir();
|
||||||
|
})();
|
||||||
|
const filepath = path.join(workDir, '.nojekyll');
|
||||||
|
|
||||||
|
await addNoJekyll(workDir, true, 'other-branch');
|
||||||
|
const test6 = fs.existsSync(filepath);
|
||||||
|
expect(test6).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('addCNAME()', () => {
|
||||||
|
test('add CNAME', async () => {
|
||||||
|
let workDir = '';
|
||||||
|
(async (): Promise<void> => {
|
||||||
|
workDir = await getWorkDir();
|
||||||
|
})();
|
||||||
|
const filepath = path.join(workDir, 'CNAME');
|
||||||
|
|
||||||
|
await addCNAME(workDir, 'github.com');
|
||||||
|
const test1 = fs.readFileSync(filepath, 'utf8');
|
||||||
|
expect(test1).toMatch('github.com');
|
||||||
|
|
||||||
|
fs.unlinkSync(filepath);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('do nothing', async () => {
|
||||||
|
let workDir = '';
|
||||||
|
(async (): Promise<void> => {
|
||||||
|
workDir = await getWorkDir();
|
||||||
|
})();
|
||||||
|
const filepath = path.join(workDir, 'CNAME');
|
||||||
|
|
||||||
|
await addCNAME(workDir, '');
|
||||||
|
const test2 = fs.existsSync(filepath);
|
||||||
|
expect(test2).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('CNAME already exists', async () => {
|
||||||
|
let workDir = '';
|
||||||
|
(async (): Promise<void> => {
|
||||||
|
workDir = await getWorkDir();
|
||||||
|
})();
|
||||||
|
const filepath = path.join(workDir, 'CNAME');
|
||||||
|
|
||||||
|
await addCNAME(workDir, 'github.io');
|
||||||
|
await addCNAME(workDir, 'github.com');
|
||||||
|
const test3 = fs.readFileSync(filepath, 'utf8');
|
||||||
|
expect(test3).toMatch('github.io');
|
||||||
|
|
||||||
|
fs.unlinkSync(filepath);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -55,3 +55,10 @@ inputs:
|
|||||||
tag_message:
|
tag_message:
|
||||||
description: 'Set tag message'
|
description: 'Set tag message'
|
||||||
required: false
|
required: false
|
||||||
|
disable_nojekyll:
|
||||||
|
description: 'Disable adding .nojekyll file to master or gh-pages branches'
|
||||||
|
required: false
|
||||||
|
default: 'false'
|
||||||
|
cname:
|
||||||
|
description: 'Set custom domain'
|
||||||
|
required: false
|
||||||
|
|||||||
113
lib/index.js
113
lib/index.js
@@ -2252,6 +2252,7 @@ const exec = __importStar(__webpack_require__(986));
|
|||||||
const get_inputs_1 = __webpack_require__(452);
|
const get_inputs_1 = __webpack_require__(452);
|
||||||
const set_tokens_1 = __webpack_require__(615);
|
const set_tokens_1 = __webpack_require__(615);
|
||||||
const git = __importStar(__webpack_require__(496));
|
const git = __importStar(__webpack_require__(496));
|
||||||
|
const utils_1 = __webpack_require__(163);
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
@@ -2261,12 +2262,15 @@ function run() {
|
|||||||
core.debug(`[INFO] remoteURL: ${remoteURL}`);
|
core.debug(`[INFO] remoteURL: ${remoteURL}`);
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const unixTime = date.getTime();
|
const unixTime = date.getTime();
|
||||||
yield git.setRepo(inps, remoteURL, `${unixTime}`);
|
const workDir = yield utils_1.getWorkDirName(`${unixTime}`);
|
||||||
|
yield git.setRepo(inps, remoteURL, workDir);
|
||||||
|
yield utils_1.addNoJekyll(workDir, inps.DisableNoJekyll, inps.PublishBranch);
|
||||||
|
yield utils_1.addCNAME(workDir, inps.CNAME);
|
||||||
try {
|
try {
|
||||||
yield exec.exec('git', ['remote', 'rm', 'origin']);
|
yield exec.exec('git', ['remote', 'rm', 'origin']);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
core.info(`[INFO] e`);
|
core.info(`[INFO] ${e}`);
|
||||||
}
|
}
|
||||||
yield exec.exec('git', ['remote', 'add', 'origin', remoteURL]);
|
yield exec.exec('git', ['remote', 'add', 'origin', remoteURL]);
|
||||||
yield exec.exec('git', ['add', '--all']);
|
yield exec.exec('git', ['add', '--all']);
|
||||||
@@ -2665,6 +2669,15 @@ function paginatePlugin(octokit) {
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
if (mod && mod.__esModule) return mod;
|
if (mod && mod.__esModule) return mod;
|
||||||
var result = {};
|
var result = {};
|
||||||
@@ -2672,20 +2685,75 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
result["default"] = mod;
|
result["default"] = mod;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
|
const io = __importStar(__webpack_require__(1));
|
||||||
|
const path_1 = __importDefault(__webpack_require__(622));
|
||||||
|
const fs_1 = __importDefault(__webpack_require__(747));
|
||||||
function getHomeDir() {
|
function getHomeDir() {
|
||||||
let homedir = '';
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
if (process.platform === 'win32') {
|
let homedir = '';
|
||||||
homedir = process.env['USERPROFILE'] || 'C:\\';
|
if (process.platform === 'win32') {
|
||||||
}
|
homedir = process.env['USERPROFILE'] || 'C:\\';
|
||||||
else {
|
}
|
||||||
homedir = `${process.env.HOME}`;
|
else {
|
||||||
}
|
homedir = `${process.env.HOME}`;
|
||||||
core.debug(`homeDir: ${homedir}`);
|
}
|
||||||
return homedir;
|
core.debug(`homeDir: ${homedir}`);
|
||||||
|
return homedir;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
exports.getHomeDir = getHomeDir;
|
exports.getHomeDir = getHomeDir;
|
||||||
|
function getWorkDirName(unixTime) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const homeDir = yield getHomeDir();
|
||||||
|
const workDirName = path_1.default.join(homeDir, `actions_github_pages_${unixTime}`);
|
||||||
|
return workDirName;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.getWorkDirName = getWorkDirName;
|
||||||
|
function createWorkDir(workDirName) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
yield io.mkdirP(workDirName);
|
||||||
|
core.debug(`Created: ${workDirName}`);
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.createWorkDir = createWorkDir;
|
||||||
|
function addNoJekyll(workDir, DisableNoJekyll, PublishBranch) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (DisableNoJekyll) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (PublishBranch === 'master' || PublishBranch === 'gh-pages') {
|
||||||
|
const filepath = path_1.default.join(workDir, '.nojekyll');
|
||||||
|
if (fs_1.default.existsSync(filepath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fs_1.default.closeSync(fs_1.default.openSync(filepath, 'w'));
|
||||||
|
core.info(`[INFO] Created ${filepath}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.addNoJekyll = addNoJekyll;
|
||||||
|
function addCNAME(workDir, content) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (content === '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const filepath = path_1.default.join(workDir, 'CNAME');
|
||||||
|
if (fs_1.default.existsSync(filepath)) {
|
||||||
|
core.warning(`CNAME already exists`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fs_1.default.writeFileSync(filepath, content + '\n');
|
||||||
|
core.info(`[INFO] Created ${filepath}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.addCNAME = addCNAME;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@@ -5996,6 +6064,8 @@ function showInputs(inps) {
|
|||||||
core.info(`[INFO] CommitMessage: ${inps.CommitMessage}`);
|
core.info(`[INFO] CommitMessage: ${inps.CommitMessage}`);
|
||||||
core.info(`[INFO] TagName: ${inps.TagName}`);
|
core.info(`[INFO] TagName: ${inps.TagName}`);
|
||||||
core.info(`[INFO] TagMessage: ${inps.TagMessage}`);
|
core.info(`[INFO] TagMessage: ${inps.TagMessage}`);
|
||||||
|
core.info(`[INFO] DisableNoJekyll: ${inps.DisableNoJekyll}`);
|
||||||
|
core.info(`[INFO] CNAME: ${inps.CNAME}`);
|
||||||
}
|
}
|
||||||
function getInputs() {
|
function getInputs() {
|
||||||
const inps = {
|
const inps = {
|
||||||
@@ -6012,7 +6082,9 @@ function getInputs() {
|
|||||||
UserEmail: core.getInput('user_email'),
|
UserEmail: core.getInput('user_email'),
|
||||||
CommitMessage: core.getInput('commit_message'),
|
CommitMessage: core.getInput('commit_message'),
|
||||||
TagName: core.getInput('tag_name'),
|
TagName: core.getInput('tag_name'),
|
||||||
TagMessage: core.getInput('tag_message')
|
TagMessage: core.getInput('tag_message'),
|
||||||
|
DisableNoJekyll: (core.getInput('disable_nojekyll') || 'false').toUpperCase() === 'TRUE',
|
||||||
|
CNAME: core.getInput('cname')
|
||||||
};
|
};
|
||||||
showInputs(inps);
|
showInputs(inps);
|
||||||
return inps;
|
return inps;
|
||||||
@@ -8331,14 +8403,6 @@ const io = __importStar(__webpack_require__(1));
|
|||||||
const path_1 = __importDefault(__webpack_require__(622));
|
const path_1 = __importDefault(__webpack_require__(622));
|
||||||
const fs_1 = __importDefault(__webpack_require__(747));
|
const fs_1 = __importDefault(__webpack_require__(747));
|
||||||
const utils_1 = __webpack_require__(163);
|
const utils_1 = __webpack_require__(163);
|
||||||
function createWorkDir(workDirName) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
yield io.mkdirP(workDirName);
|
|
||||||
core.debug(`workDir was created: ${workDirName}`);
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.createWorkDir = createWorkDir;
|
|
||||||
function createBranchForce(branch) {
|
function createBranchForce(branch) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
yield exec.exec('git', ['init']);
|
yield exec.exec('git', ['init']);
|
||||||
@@ -8375,13 +8439,12 @@ function copyAssets(publishDir, workDir) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.copyAssets = copyAssets;
|
exports.copyAssets = copyAssets;
|
||||||
function setRepo(inps, remoteURL, unixTime) {
|
function setRepo(inps, remoteURL, workDir) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const workDir = path_1.default.join(utils_1.getHomeDir(), `actions_github_pages_${unixTime}`);
|
|
||||||
const publishDir = path_1.default.join(`${process.env.GITHUB_WORKSPACE}`, inps.PublishDir);
|
const publishDir = path_1.default.join(`${process.env.GITHUB_WORKSPACE}`, inps.PublishDir);
|
||||||
core.info(`[INFO] ForceOrphan: ${inps.ForceOrphan}`);
|
core.info(`[INFO] ForceOrphan: ${inps.ForceOrphan}`);
|
||||||
if (inps.ForceOrphan) {
|
if (inps.ForceOrphan) {
|
||||||
yield createWorkDir(workDir);
|
yield utils_1.createWorkDir(workDir);
|
||||||
process.chdir(workDir);
|
process.chdir(workDir);
|
||||||
yield createBranchForce(inps.PublishBranch);
|
yield createBranchForce(inps.PublishBranch);
|
||||||
yield copyAssets(publishDir, workDir);
|
yield copyAssets(publishDir, workDir);
|
||||||
@@ -8426,7 +8489,7 @@ function setRepo(inps, remoteURL, unixTime) {
|
|||||||
catch (e) {
|
catch (e) {
|
||||||
core.info(`[INFO] first deployment, create new branch ${inps.PublishBranch}`);
|
core.info(`[INFO] first deployment, create new branch ${inps.PublishBranch}`);
|
||||||
core.info(e);
|
core.info(e);
|
||||||
yield createWorkDir(workDir);
|
yield utils_1.createWorkDir(workDir);
|
||||||
process.chdir(workDir);
|
process.chdir(workDir);
|
||||||
yield createBranchForce(inps.PublishBranch);
|
yield createBranchForce(inps.PublishBranch);
|
||||||
yield copyAssets(publishDir, workDir);
|
yield copyAssets(publishDir, workDir);
|
||||||
@@ -9531,7 +9594,7 @@ exports.setPublishRepo = setPublishRepo;
|
|||||||
function setSSHKey(inps, publishRepo) {
|
function setSSHKey(inps, publishRepo) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.info('[INFO] setup SSH deploy key');
|
core.info('[INFO] setup SSH deploy key');
|
||||||
const homeDir = utils_1.getHomeDir();
|
const homeDir = yield utils_1.getHomeDir();
|
||||||
const sshDir = path_1.default.join(homeDir, '.ssh');
|
const sshDir = path_1.default.join(homeDir, '.ssh');
|
||||||
yield io.mkdirP(sshDir);
|
yield io.mkdirP(sshDir);
|
||||||
yield exec.exec('chmod', ['700', sshDir]);
|
yield exec.exec('chmod', ['700', sshDir]);
|
||||||
|
|||||||
39
package-lock.json
generated
39
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "actions-github-pages",
|
"name": "actions-github-pages",
|
||||||
"version": "3.2.0",
|
"version": "3.3.0-0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -740,9 +740,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@types/jest": {
|
"@types/jest": {
|
||||||
"version": "25.1.2",
|
"version": "25.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-25.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-25.1.3.tgz",
|
||||||
"integrity": "sha512-EsPIgEsonlXmYV7GzUqcvORsSS9Gqxw/OvkGwHfAdpjduNRxMlhsav0O5Kb0zijc/eXSO/uW6SJt9nwull8AUQ==",
|
"integrity": "sha512-jqargqzyJWgWAJCXX96LBGR/Ei7wQcZBvRv0PLEu9ZByMfcs23keUJrKv9FMR6YZf9YCbfqDqgmY+JUBsnqhrg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"jest-diff": "^25.1.0",
|
"jest-diff": "^25.1.0",
|
||||||
@@ -5216,9 +5216,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"make-error": {
|
"make-error": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.6",
|
||||||
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz",
|
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
|
||||||
"integrity": "sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==",
|
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"makeerror": {
|
"makeerror": {
|
||||||
@@ -7418,9 +7418,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"ts-jest": {
|
"ts-jest": {
|
||||||
"version": "25.2.0",
|
"version": "25.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-25.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-25.2.1.tgz",
|
||||||
"integrity": "sha512-VaRdb0da46eorLfuHEFf0G3d+jeREcV+Wb/SvW71S4y9Oe8SHWU+m1WY/3RaMknrBsnvmVH0/rRjT8dkgeffNQ==",
|
"integrity": "sha512-TnntkEEjuXq/Gxpw7xToarmHbAafgCaAzOpnajnFC6jI7oo1trMzAHA04eWpc3MhV6+yvhE8uUBAmN+teRJh0A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"bs-logger": "0.x",
|
"bs-logger": "0.x",
|
||||||
@@ -7432,24 +7432,7 @@
|
|||||||
"mkdirp": "0.x",
|
"mkdirp": "0.x",
|
||||||
"resolve": "1.x",
|
"resolve": "1.x",
|
||||||
"semver": "^5.5",
|
"semver": "^5.5",
|
||||||
"yargs-parser": "10.x"
|
"yargs-parser": "^16.1.0"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"camelcase": {
|
|
||||||
"version": "4.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz",
|
|
||||||
"integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"yargs-parser": {
|
|
||||||
"version": "10.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-10.1.0.tgz",
|
|
||||||
"integrity": "sha512-VCIyR1wJoEBZUqk5PA+oOBF6ypbwh5aNB3I50guxAL/quggdfs4TtNHQrSazFA3fYZ+tEqfs0zIGlv0c/rgjbQ==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"camelcase": "^4.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tslib": {
|
"tslib": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "actions-github-pages",
|
"name": "actions-github-pages",
|
||||||
"version": "3.2.0",
|
"version": "3.3.0-0",
|
||||||
"description": "GitHub Actions for GitHub Pages",
|
"description": "GitHub Actions for GitHub Pages",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
"@actions/io": "^1.0.2"
|
"@actions/io": "^1.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^25.1.2",
|
"@types/jest": "^25.1.3",
|
||||||
"@types/node": "~12",
|
"@types/node": "~12",
|
||||||
"@typescript-eslint/eslint-plugin": "^2.20.0",
|
"@typescript-eslint/eslint-plugin": "^2.20.0",
|
||||||
"@typescript-eslint/parser": "^2.20.0",
|
"@typescript-eslint/parser": "^2.20.0",
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
"lint-staged": "^10.0.7",
|
"lint-staged": "^10.0.7",
|
||||||
"prettier": "1.19.1",
|
"prettier": "1.19.1",
|
||||||
"standard-version": "^7.1.0",
|
"standard-version": "^7.1.0",
|
||||||
"ts-jest": "^25.2.0",
|
"ts-jest": "^25.2.1",
|
||||||
"typescript": "^3.7.5"
|
"typescript": "^3.7.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ function showInputs(inps: Inputs): void {
|
|||||||
core.info(`[INFO] CommitMessage: ${inps.CommitMessage}`);
|
core.info(`[INFO] CommitMessage: ${inps.CommitMessage}`);
|
||||||
core.info(`[INFO] TagName: ${inps.TagName}`);
|
core.info(`[INFO] TagName: ${inps.TagName}`);
|
||||||
core.info(`[INFO] TagMessage: ${inps.TagMessage}`);
|
core.info(`[INFO] TagMessage: ${inps.TagMessage}`);
|
||||||
|
core.info(`[INFO] DisableNoJekyll: ${inps.DisableNoJekyll}`);
|
||||||
|
core.info(`[INFO] CNAME: ${inps.CNAME}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getInputs(): Inputs {
|
export function getInputs(): Inputs {
|
||||||
@@ -41,7 +43,10 @@ export function getInputs(): Inputs {
|
|||||||
UserEmail: core.getInput('user_email'),
|
UserEmail: core.getInput('user_email'),
|
||||||
CommitMessage: core.getInput('commit_message'),
|
CommitMessage: core.getInput('commit_message'),
|
||||||
TagName: core.getInput('tag_name'),
|
TagName: core.getInput('tag_name'),
|
||||||
TagMessage: core.getInput('tag_message')
|
TagMessage: core.getInput('tag_message'),
|
||||||
|
DisableNoJekyll:
|
||||||
|
(core.getInput('disable_nojekyll') || 'false').toUpperCase() === 'TRUE',
|
||||||
|
CNAME: core.getInput('cname')
|
||||||
};
|
};
|
||||||
|
|
||||||
showInputs(inps);
|
showInputs(inps);
|
||||||
|
|||||||
@@ -5,13 +5,7 @@ import * as io from '@actions/io';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import {Inputs, CmdResult} from './interfaces';
|
import {Inputs, CmdResult} from './interfaces';
|
||||||
import {getHomeDir} from './utils';
|
import {createWorkDir} from './utils';
|
||||||
|
|
||||||
export async function createWorkDir(workDirName: string): Promise<void> {
|
|
||||||
await io.mkdirP(workDirName);
|
|
||||||
core.debug(`workDir was created: ${workDirName}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createBranchForce(branch: string): Promise<void> {
|
export async function createBranchForce(branch: string): Promise<void> {
|
||||||
await exec.exec('git', ['init']);
|
await exec.exec('git', ['init']);
|
||||||
@@ -41,9 +35,8 @@ export async function copyAssets(
|
|||||||
export async function setRepo(
|
export async function setRepo(
|
||||||
inps: Inputs,
|
inps: Inputs,
|
||||||
remoteURL: string,
|
remoteURL: string,
|
||||||
unixTime: string
|
workDir: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const workDir = path.join(getHomeDir(), `actions_github_pages_${unixTime}`);
|
|
||||||
const publishDir = path.join(
|
const publishDir = path.join(
|
||||||
`${process.env.GITHUB_WORKSPACE}`,
|
`${process.env.GITHUB_WORKSPACE}`,
|
||||||
inps.PublishDir
|
inps.PublishDir
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ export interface Inputs {
|
|||||||
readonly CommitMessage: string;
|
readonly CommitMessage: string;
|
||||||
readonly TagName: string;
|
readonly TagName: string;
|
||||||
readonly TagMessage: string;
|
readonly TagMessage: string;
|
||||||
|
readonly DisableNoJekyll: boolean;
|
||||||
|
readonly CNAME: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CmdResult {
|
export interface CmdResult {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {Inputs} from './interfaces';
|
|||||||
import {getInputs} from './get-inputs';
|
import {getInputs} from './get-inputs';
|
||||||
import {setTokens} from './set-tokens';
|
import {setTokens} from './set-tokens';
|
||||||
import * as git from './git-utils';
|
import * as git from './git-utils';
|
||||||
|
import {getWorkDirName, addNoJekyll, addCNAME} from './utils';
|
||||||
|
|
||||||
export async function run(): Promise<void> {
|
export async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
@@ -16,12 +17,16 @@ export async function run(): Promise<void> {
|
|||||||
|
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const unixTime = date.getTime();
|
const unixTime = date.getTime();
|
||||||
await git.setRepo(inps, remoteURL, `${unixTime}`);
|
const workDir = await getWorkDirName(`${unixTime}`);
|
||||||
|
await git.setRepo(inps, remoteURL, workDir);
|
||||||
|
|
||||||
|
await addNoJekyll(workDir, inps.DisableNoJekyll, inps.PublishBranch);
|
||||||
|
await addCNAME(workDir, inps.CNAME);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await exec.exec('git', ['remote', 'rm', 'origin']);
|
await exec.exec('git', ['remote', 'rm', 'origin']);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.info(`[INFO] e`);
|
core.info(`[INFO] ${e}`);
|
||||||
}
|
}
|
||||||
await exec.exec('git', ['remote', 'add', 'origin', remoteURL]);
|
await exec.exec('git', ['remote', 'add', 'origin', remoteURL]);
|
||||||
await exec.exec('git', ['add', '--all']);
|
await exec.exec('git', ['add', '--all']);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export async function setSSHKey(
|
|||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
core.info('[INFO] setup SSH deploy key');
|
core.info('[INFO] setup SSH deploy key');
|
||||||
|
|
||||||
const homeDir = getHomeDir();
|
const homeDir = await getHomeDir();
|
||||||
const sshDir = path.join(homeDir, '.ssh');
|
const sshDir = path.join(homeDir, '.ssh');
|
||||||
await io.mkdirP(sshDir);
|
await io.mkdirP(sshDir);
|
||||||
await exec.exec('chmod', ['700', sshDir]);
|
await exec.exec('chmod', ['700', sshDir]);
|
||||||
|
|||||||
51
src/utils.ts
51
src/utils.ts
@@ -1,6 +1,9 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
import * as io from '@actions/io';
|
||||||
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
export function getHomeDir(): string {
|
export async function getHomeDir(): Promise<string> {
|
||||||
let homedir = '';
|
let homedir = '';
|
||||||
|
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
@@ -13,3 +16,49 @@ export function getHomeDir(): string {
|
|||||||
|
|
||||||
return homedir;
|
return homedir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getWorkDirName(unixTime: string): Promise<string> {
|
||||||
|
const homeDir = await getHomeDir();
|
||||||
|
const workDirName = path.join(homeDir, `actions_github_pages_${unixTime}`);
|
||||||
|
return workDirName;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createWorkDir(workDirName: string): Promise<void> {
|
||||||
|
await io.mkdirP(workDirName);
|
||||||
|
core.debug(`Created: ${workDirName}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function addNoJekyll(
|
||||||
|
workDir: string,
|
||||||
|
DisableNoJekyll: boolean,
|
||||||
|
PublishBranch: string
|
||||||
|
): Promise<void> {
|
||||||
|
if (DisableNoJekyll) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (PublishBranch === 'master' || PublishBranch === 'gh-pages') {
|
||||||
|
const filepath = path.join(workDir, '.nojekyll');
|
||||||
|
if (fs.existsSync(filepath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fs.closeSync(fs.openSync(filepath, 'w'));
|
||||||
|
core.info(`[INFO] Created ${filepath}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function addCNAME(
|
||||||
|
workDir: string,
|
||||||
|
content: string
|
||||||
|
): Promise<void> {
|
||||||
|
if (content === '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const filepath = path.join(workDir, 'CNAME');
|
||||||
|
if (fs.existsSync(filepath)) {
|
||||||
|
core.warning(`CNAME already exists`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fs.writeFileSync(filepath, content + '\n');
|
||||||
|
core.info(`[INFO] Created ${filepath}`);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user