|
|
|
@@ -1,4 +1,5 @@
|
|
|
|
|
import {
|
|
|
|
|
copyAssets,
|
|
|
|
|
setRepo,
|
|
|
|
|
getUserName,
|
|
|
|
|
getUserEmail,
|
|
|
|
@@ -10,6 +11,17 @@ import {Inputs} from '../src/interfaces';
|
|
|
|
|
import {getWorkDirName, createDir} from '../src/utils';
|
|
|
|
|
import {CmdResult} from '../src/interfaces';
|
|
|
|
|
import * as exec from '@actions/exec';
|
|
|
|
|
import {cp, rm} from 'shelljs';
|
|
|
|
|
import path from 'path';
|
|
|
|
|
import fs from 'fs';
|
|
|
|
|
|
|
|
|
|
const testRoot = path.resolve(__dirname);
|
|
|
|
|
|
|
|
|
|
async function createTestDir(name: string): Promise<string> {
|
|
|
|
|
const date = new Date();
|
|
|
|
|
const unixTime = date.getTime();
|
|
|
|
|
return await getWorkDirName(`${unixTime}_${name}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
jest.resetModules();
|
|
|
|
@@ -22,6 +34,96 @@ afterEach(() => {
|
|
|
|
|
delete process.env['GITHUB_REPOSITORY'];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('copyAssets', () => {
|
|
|
|
|
let gitTempDir = '';
|
|
|
|
|
(async (): Promise<void> => {
|
|
|
|
|
const date = new Date();
|
|
|
|
|
const unixTime = date.getTime();
|
|
|
|
|
gitTempDir = await getWorkDirName(`${unixTime}_git`);
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
|
await createDir(gitTempDir);
|
|
|
|
|
process.chdir(gitTempDir);
|
|
|
|
|
await exec.exec('git', ['init']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('copy assets from publish_dir to root, delete .github', async () => {
|
|
|
|
|
const publishDir = await createTestDir('src');
|
|
|
|
|
const destDir = await createTestDir('dst');
|
|
|
|
|
cp('-Rf', path.resolve(testRoot, 'fixtures/publish_dir_1'), publishDir);
|
|
|
|
|
cp('-Rf', gitTempDir, destDir);
|
|
|
|
|
|
|
|
|
|
await copyAssets(publishDir, destDir, '.github');
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, '.github'))).toBeFalsy();
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, 'index.html'))).toBeTruthy();
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, 'assets/lib.css'))).toBeTruthy();
|
|
|
|
|
rm('-rf', publishDir, destDir);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('copy assets from publish_dir to root, delete .github,main.js', async () => {
|
|
|
|
|
const publishDir = await createTestDir('src');
|
|
|
|
|
const destDir = await createTestDir('dst');
|
|
|
|
|
cp('-Rf', path.resolve(testRoot, 'fixtures/publish_dir_1'), publishDir);
|
|
|
|
|
cp('-Rf', gitTempDir, destDir);
|
|
|
|
|
|
|
|
|
|
await copyAssets(publishDir, destDir, '.github,main.js');
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, '.github'))).toBeFalsy();
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, 'index.html'))).toBeTruthy();
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, 'main.js'))).toBeFalsy();
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, 'assets/lib.css'))).toBeTruthy();
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, 'assets/lib.js'))).toBeTruthy();
|
|
|
|
|
rm('-rf', publishDir, destDir);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('copy assets from publish_dir to root, delete nothing', async () => {
|
|
|
|
|
const publishDir = await createTestDir('src');
|
|
|
|
|
const destDir = await createTestDir('dst');
|
|
|
|
|
cp('-Rf', path.resolve(testRoot, 'fixtures/publish_dir_root'), publishDir);
|
|
|
|
|
cp('-Rf', gitTempDir, destDir);
|
|
|
|
|
|
|
|
|
|
await copyAssets(publishDir, destDir, '');
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, '.github'))).toBeTruthy();
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, 'index.html'))).toBeTruthy();
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, 'main.js'))).toBeTruthy();
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, 'assets/lib.css'))).toBeTruthy();
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, 'assets/lib.js'))).toBeTruthy();
|
|
|
|
|
rm('-rf', publishDir, destDir);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('copy assets from root to root, delete .github', async () => {
|
|
|
|
|
const publishDir = await createTestDir('src');
|
|
|
|
|
const destDir = await createTestDir('dst');
|
|
|
|
|
cp('-Rf', path.resolve(testRoot, 'fixtures/publish_dir_root'), publishDir);
|
|
|
|
|
cp('-Rf', gitTempDir, destDir);
|
|
|
|
|
cp('-Rf', gitTempDir, publishDir);
|
|
|
|
|
|
|
|
|
|
await copyAssets(publishDir, destDir, '.github');
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, '.github'))).toBeFalsy();
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, 'index.html'))).toBeTruthy();
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, 'assets/lib.css'))).toBeTruthy();
|
|
|
|
|
rm('-rf', publishDir, destDir);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('copy assets from root to root, delete nothing', async () => {
|
|
|
|
|
const publishDir = await createTestDir('src');
|
|
|
|
|
const destDir = await createTestDir('dst');
|
|
|
|
|
cp('-Rf', path.resolve(testRoot, 'fixtures/publish_dir_root'), publishDir);
|
|
|
|
|
cp('-Rf', gitTempDir, destDir);
|
|
|
|
|
cp('-Rf', gitTempDir, publishDir);
|
|
|
|
|
|
|
|
|
|
await copyAssets(publishDir, destDir, '');
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, '.github'))).toBeTruthy();
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, 'index.html'))).toBeTruthy();
|
|
|
|
|
expect(fs.existsSync(path.resolve(destDir, 'assets/lib.css'))).toBeTruthy();
|
|
|
|
|
rm('-rf', publishDir, destDir);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.todo('copy assets from root to subdir, delete .github');
|
|
|
|
|
test.todo('copy assets from root to subdir, delete .github,main.js');
|
|
|
|
|
test.todo('copy assets from root to subdir, delete nothing');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('setRepo()', () => {
|
|
|
|
|
test('throw error destination_dir should be a relative path', async () => {
|
|
|
|
|
process.env['INPUT_GITHUB_TOKEN'] = 'test_github_token';
|
|
|
|
|