Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbdfb20061 | ||
|
|
7fd2e42a05 | ||
|
|
e93eed3ba7 | ||
|
|
cf805b9457 | ||
|
|
c4241b26fb | ||
|
|
4f6b15a24f |
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -73,7 +73,7 @@ jobs:
|
|||||||
name: coverage-${{ matrix.os }}
|
name: coverage-${{ matrix.os }}
|
||||||
path: coverage
|
path: coverage
|
||||||
|
|
||||||
- uses: codecov/codecov-action@v1.0.13
|
- uses: codecov/codecov-action@v1.0.14
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
|
||||||
|
|||||||
17
CHANGELOG.md
17
CHANGELOG.md
@@ -2,6 +2,23 @@
|
|||||||
|
|
||||||
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.7.3](https://github.com/peaceiris/actions-gh-pages/compare/v3.7.2...v3.7.3) (2020-10-20)
|
||||||
|
|
||||||
|
|
||||||
|
### ci
|
||||||
|
|
||||||
|
* bump codecov/codecov-action from v1.0.13 to v1.0.14 (#526) ([c4241b2](https://github.com/peaceiris/actions-gh-pages/commit/c4241b26fb90917901c95fabafc9907f71f44508)), closes [#526](https://github.com/peaceiris/actions-gh-pages/issues/526)
|
||||||
|
|
||||||
|
### docs
|
||||||
|
|
||||||
|
* Add link to create-react-app (#525) ([cf805b9](https://github.com/peaceiris/actions-gh-pages/commit/cf805b9457df587d349ee1684a4801cf9bbaac7d)), closes [#525](https://github.com/peaceiris/actions-gh-pages/issues/525)
|
||||||
|
|
||||||
|
### fix
|
||||||
|
|
||||||
|
* copyAssets and deleteExcludedAssets (#528) ([e93eed3](https://github.com/peaceiris/actions-gh-pages/commit/e93eed3ba7edf10f461bc4a7bd14cd2a12f44935)), closes [#528](https://github.com/peaceiris/actions-gh-pages/issues/528)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [3.7.2](https://github.com/peaceiris/actions-gh-pages/compare/v3.7.1...v3.7.2) (2020-10-15)
|
## [3.7.2](https://github.com/peaceiris/actions-gh-pages/compare/v3.7.1...v3.7.2) (2020-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -596,12 +596,15 @@ jobs:
|
|||||||
|
|
||||||
### ⭐️ Static Site Generators with Node.js
|
### ⭐️ Static Site Generators with Node.js
|
||||||
|
|
||||||
[hexo], [vuepress], [react-static], [gridsome], and so on.
|
[hexo], [vuepress], [react-static], [gridsome], [create-react-app] and so on.
|
||||||
|
Please check where your output directory is before pushing your workflow.
|
||||||
|
e.g. `create-react-app` requires `publish_dir` to be set to `./build`
|
||||||
|
|
||||||
[hexo]: https://github.com/hexojs/hexo
|
[hexo]: https://github.com/hexojs/hexo
|
||||||
[vuepress]: https://github.com/vuejs/vuepress
|
[vuepress]: https://github.com/vuejs/vuepress
|
||||||
[react-static]: https://github.com/react-static/react-static
|
[react-static]: https://github.com/react-static/react-static
|
||||||
[gridsome]: https://github.com/gridsome/gridsome
|
[gridsome]: https://github.com/gridsome/gridsome
|
||||||
|
[create-react-app]: https://github.com/facebook/create-react-app
|
||||||
|
|
||||||
Premise: Dependencies are managed by `package.json` and `package-lock.json`
|
Premise: Dependencies are managed by `package.json` and `package-lock.json`
|
||||||
|
|
||||||
|
|||||||
1
__tests__/fixtures/publish_dir_1/assets/lib.css
Normal file
1
__tests__/fixtures/publish_dir_1/assets/lib.css
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/* CSS */
|
||||||
1
__tests__/fixtures/publish_dir_1/assets/lib.js
Normal file
1
__tests__/fixtures/publish_dir_1/assets/lib.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
// JavaScript
|
||||||
11
__tests__/fixtures/publish_dir_1/index.html
Normal file
11
__tests__/fixtures/publish_dir_1/index.html
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
1
__tests__/fixtures/publish_dir_1/main.css
Normal file
1
__tests__/fixtures/publish_dir_1/main.css
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/* CSS */
|
||||||
1
__tests__/fixtures/publish_dir_1/main.js
Normal file
1
__tests__/fixtures/publish_dir_1/main.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
// JavaScript
|
||||||
1
__tests__/fixtures/publish_dir_root/.github/CODEOWNERS
vendored
Normal file
1
__tests__/fixtures/publish_dir_root/.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners
|
||||||
1
__tests__/fixtures/publish_dir_root/.github/ISSUE_TEMPLATE/template.md
vendored
Normal file
1
__tests__/fixtures/publish_dir_root/.github/ISSUE_TEMPLATE/template.md
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<!-- issue template -->
|
||||||
7
__tests__/fixtures/publish_dir_root/.github/dependabot.yml
vendored
Normal file
7
__tests__/fixtures/publish_dir_root/.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# dependabot config
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: npm
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: daily
|
||||||
1
__tests__/fixtures/publish_dir_root/.github/workflows/test.yml
vendored
Normal file
1
__tests__/fixtures/publish_dir_root/.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
name: 'Test'
|
||||||
1
__tests__/fixtures/publish_dir_root/assets/lib.css
Normal file
1
__tests__/fixtures/publish_dir_root/assets/lib.css
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/* CSS */
|
||||||
1
__tests__/fixtures/publish_dir_root/assets/lib.js
Normal file
1
__tests__/fixtures/publish_dir_root/assets/lib.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
// JavaScript
|
||||||
11
__tests__/fixtures/publish_dir_root/index.html
Normal file
11
__tests__/fixtures/publish_dir_root/index.html
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
1
__tests__/fixtures/publish_dir_root/main.css
Normal file
1
__tests__/fixtures/publish_dir_root/main.css
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/* CSS */
|
||||||
1
__tests__/fixtures/publish_dir_root/main.js
Normal file
1
__tests__/fixtures/publish_dir_root/main.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
// JavaScript
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
copyAssets,
|
||||||
setRepo,
|
setRepo,
|
||||||
getUserName,
|
getUserName,
|
||||||
getUserEmail,
|
getUserEmail,
|
||||||
@@ -10,6 +11,17 @@ import {Inputs} from '../src/interfaces';
|
|||||||
import {getWorkDirName, createDir} from '../src/utils';
|
import {getWorkDirName, createDir} from '../src/utils';
|
||||||
import {CmdResult} from '../src/interfaces';
|
import {CmdResult} from '../src/interfaces';
|
||||||
import * as exec from '@actions/exec';
|
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(() => {
|
beforeEach(() => {
|
||||||
jest.resetModules();
|
jest.resetModules();
|
||||||
@@ -22,6 +34,96 @@ afterEach(() => {
|
|||||||
delete process.env['GITHUB_REPOSITORY'];
|
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()', () => {
|
describe('setRepo()', () => {
|
||||||
test('throw error destination_dir should be a relative path', async () => {
|
test('throw error destination_dir should be a relative path', async () => {
|
||||||
process.env['INPUT_GITHUB_TOKEN'] = 'test_github_token';
|
process.env['INPUT_GITHUB_TOKEN'] = 'test_github_token';
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "actions-github-pages",
|
"name": "actions-github-pages",
|
||||||
"version": "3.7.2",
|
"version": "3.7.3",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "actions-github-pages",
|
"name": "actions-github-pages",
|
||||||
"version": "3.7.2",
|
"version": "3.7.3",
|
||||||
"description": "GitHub Actions for GitHub Pages",
|
"description": "GitHub Actions for GitHub Pages",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import * as io from '@actions/io';
|
|
||||||
import * as glob from '@actions/glob';
|
import * as glob from '@actions/glob';
|
||||||
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 {createDir} from './utils';
|
import {createDir} from './utils';
|
||||||
import {cp} from 'shelljs';
|
import {cp, rm} from 'shelljs';
|
||||||
|
|
||||||
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']);
|
||||||
@@ -15,6 +14,7 @@ export async function createBranchForce(branch: string): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteExcludedAssets(destDir: string, excludeAssets: string): Promise<void> {
|
export async function deleteExcludedAssets(destDir: string, excludeAssets: string): Promise<void> {
|
||||||
|
if (excludeAssets === '') return;
|
||||||
core.info(`[INFO] delete excluded assets`);
|
core.info(`[INFO] delete excluded assets`);
|
||||||
const excludedAssetNames: Array<string> = excludeAssets.split(',');
|
const excludedAssetNames: Array<string> = excludeAssets.split(',');
|
||||||
const excludedAssetPaths = ((): Array<string> => {
|
const excludedAssetPaths = ((): Array<string> => {
|
||||||
@@ -25,10 +25,11 @@ export async function deleteExcludedAssets(destDir: string, excludeAssets: strin
|
|||||||
return paths;
|
return paths;
|
||||||
})();
|
})();
|
||||||
const globber = await glob.create(excludedAssetPaths.join('\n'));
|
const globber = await glob.create(excludedAssetPaths.join('\n'));
|
||||||
for await (const asset of globber.globGenerator()) {
|
const files = await globber.glob();
|
||||||
core.info(`[INFO] delete ${asset}`);
|
for await (const file of globber.globGenerator()) {
|
||||||
io.rmRF(asset);
|
core.info(`[INFO] delete ${file}`);
|
||||||
}
|
}
|
||||||
|
rm('-rf', files);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,15 +40,15 @@ export async function copyAssets(
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
core.info(`[INFO] prepare publishing assets`);
|
core.info(`[INFO] prepare publishing assets`);
|
||||||
|
|
||||||
if (fs.existsSync(destDir) === false) {
|
if (!fs.existsSync(destDir)) {
|
||||||
core.info(`[INFO] create ${destDir}`);
|
core.info(`[INFO] create ${destDir}`);
|
||||||
await createDir(destDir);
|
await createDir(destDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
const dotGitPath = path.join(publishDir, '.git');
|
const dotGitPath = path.join(publishDir, '.git');
|
||||||
if (fs.existsSync(dotGitPath)) {
|
if (fs.existsSync(dotGitPath)) {
|
||||||
core.info(`[INFO] delete .git`);
|
core.info(`[INFO] delete ${dotGitPath}`);
|
||||||
io.rmRF(dotGitPath);
|
rm('-rf', dotGitPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info(`[INFO] copy ${publishDir} to ${destDir}`);
|
core.info(`[INFO] copy ${publishDir} to ${destDir}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user