Compare commits

...

14 Commits

Author SHA1 Message Date
peaceiris
afee929f89 chore(release): 3.7.0-1
Some checks failed
Release / release (push) Has been cancelled
2020-07-21 12:53:50 +09:00
peaceiris
4b17904d54 chore(release): Add build assets 2020-07-21 12:53:48 +09:00
Shohei Ueda
ce4e3beff1 fix: KeepFiles behaviour when DestinationDir has dir (#405)
Related to #324
2020-07-21 12:53:14 +09:00
peaceiris
3874723ac6 docs: Enhance section name 2020-07-21 11:42:39 +09:00
peaceiris
f0c76f03b6 chore(release): Remove build assets [skip ci] 2020-07-21 11:17:05 +09:00
peaceiris
b7f7b0dddb chore(release): 3.7.0-0
Some checks failed
Release / release (push) Has been cancelled
2020-07-21 11:17:04 +09:00
peaceiris
14e12e8e74 chore(release): Add build assets 2020-07-21 11:17:03 +09:00
Shohei Ueda
f30118c78e feat: Add destination_dir option (#403)
Related to #324 #390
2020-07-21 11:15:53 +09:00
dependabot[bot]
0cb61e91a5 deps: bump @types/node from 12.12.50 to 12.12.51 (#404)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 12.12.50 to 12.12.51.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-07-21 11:14:49 +09:00
dependabot[bot]
42a6cdde0c deps: bump @types/jest from 26.0.4 to 26.0.5 (#402)
Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 26.0.4 to 26.0.5.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-07-20 11:12:36 +09:00
Shohei Ueda
250469649c docs: update dependabot label 2020-07-18 16:25:09 +09:00
dependabot[bot]
a5a8912d3e ci: bump codecov/codecov-action from v1.0.10 to v1.0.11 (#401)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from v1.0.10 to v1.0.11.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Commits](https://github.com/codecov/codecov-action/compare/v1.0.10...6d208f5b527841fb050f92f778e86cb808dacdcb)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-07-18 16:18:20 +09:00
Shohei Ueda
5980f05de8 ci: update label 2020-07-18 16:18:08 +09:00
peaceiris
106f76b593 chore(release): Remove build assets [skip ci] 2020-07-18 13:02:37 +09:00
15 changed files with 183 additions and 60 deletions

View File

@@ -21,6 +21,6 @@ updates:
schedule:
interval: "daily"
labels:
- "dependencies:ci"
- "CI/CD"
commit-message:
prefix: ci

View File

@@ -64,7 +64,7 @@ jobs:
name: coverage-${{ matrix.os }}
path: coverage
- uses: codecov/codecov-action@v1.0.10
- uses: codecov/codecov-action@v1.0.11
with:
token: ${{ secrets.CODECOV_TOKEN }}

View File

@@ -2,6 +2,42 @@
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.0-1](https://github.com/peaceiris/actions-gh-pages/compare/v3.7.0-0...v3.7.0-1) (2020-07-21)
### docs
* Enhance section name ([3874723](https://github.com/peaceiris/actions-gh-pages/commit/3874723ac6158d13e3f1e3c8fd34e1ce96d9edf7))
### fix
* KeepFiles behaviour when DestinationDir has dir (#405) ([ce4e3be](https://github.com/peaceiris/actions-gh-pages/commit/ce4e3beff1ed33658f3160b0f45b688c6ea09932)), closes [#405](https://github.com/peaceiris/actions-gh-pages/issues/405) [#324](https://github.com/peaceiris/actions-gh-pages/issues/324)
# [3.7.0-0](https://github.com/peaceiris/actions-gh-pages/compare/v3.6.4...v3.7.0-0) (2020-07-21)
### ci
* bump codecov/codecov-action from v1.0.10 to v1.0.11 (#401) ([a5a8912](https://github.com/peaceiris/actions-gh-pages/commit/a5a8912d3e47a3ba8785d356ebed0fd02e2eeb46)), closes [#401](https://github.com/peaceiris/actions-gh-pages/issues/401)
* update label ([5980f05](https://github.com/peaceiris/actions-gh-pages/commit/5980f05de835c05638459c3c7a80d76edd0c7969))
### deps
* bump @types/jest from 26.0.4 to 26.0.5 (#402) ([42a6cdd](https://github.com/peaceiris/actions-gh-pages/commit/42a6cdde0c0d499af05cd22020132f6240d578a8)), closes [#402](https://github.com/peaceiris/actions-gh-pages/issues/402)
* bump @types/node from 12.12.50 to 12.12.51 (#404) ([0cb61e9](https://github.com/peaceiris/actions-gh-pages/commit/0cb61e91a5487c04cb202e13a8d2bc25c09c80e1)), closes [#404](https://github.com/peaceiris/actions-gh-pages/issues/404)
### docs
* update dependabot label ([2504696](https://github.com/peaceiris/actions-gh-pages/commit/250469649c036a88f547b96f94867900a1f19163))
### feat
* Add destination_dir option (#403) ([f30118c](https://github.com/peaceiris/actions-gh-pages/commit/f30118c78eebbbe6cf66009b80a7414a4047de43)), closes [#403](https://github.com/peaceiris/actions-gh-pages/issues/403) [#324](https://github.com/peaceiris/actions-gh-pages/issues/324) [#390](https://github.com/peaceiris/actions-gh-pages/issues/390)
## [3.6.4](https://github.com/peaceiris/actions-gh-pages/compare/v3.6.3...v3.6.4) (2020-07-18)

View File

@@ -69,17 +69,18 @@ All Actions runners: Linux (Ubuntu), macOS, and Windows are supported.
- [⭐️ Repository type - Project](#%EF%B8%8F-repository-type---project)
- [⭐️ Repository type - User and Organization](#%EF%B8%8F-repository-type---user-and-organization)
- [Options](#options)
- [⭐️ `github_token`](#%EF%B8%8F-github_token)
- [⭐️ `deploy_key`](#%EF%B8%8F-deploy_key)
- [⭐️ `personal_token`](#%EF%B8%8F-personal_token)
- [⭐️ `publish_branch`](#%EF%B8%8F-publish_branch)
- [⭐️ `publish_dir`](#%EF%B8%8F-publish_dir)
- [⭐️ CNAME](#%EF%B8%8F-cname)
- [⭐️ Enable Built-in Jekyll](#%EF%B8%8F-enable-built-in-jekyll)
- [⭐️ Allow empty commits](#%EF%B8%8F-allow-empty-commits)
- [⭐️ Keeping existing files](#%EF%B8%8F-keeping-existing-files)
- [⭐️ Deploy to external repository](#%EF%B8%8F-deploy-to-external-repository)
- [⭐️ Force orphan](#%EF%B8%8F-force-orphan)
- [⭐️ Set Runner's Access Token `github_token`](#%EF%B8%8F-set-runners-access-token-github_token)
- [⭐️ Set SSH Private Key `deploy_key`](#%EF%B8%8F-set-ssh-private-key-deploy_key)
- [⭐️ Set Personal Access Token `personal_token`](#%EF%B8%8F-set-personal-access-token-personal_token)
- [⭐️ Target Branch `publish_branch`](#%EF%B8%8F-target-branch-publish_branch)
- [⭐️ Source Directory `publish_dir`](#%EF%B8%8F-source-directory-publish_dir)
- [⭐️ Deploy to Subdirectory `destination_dir`](#%EF%B8%8F-deploy-to-subdirectory-destination_dir)
- [⭐️ Add CNAME file `cname`](#%EF%B8%8F-add-cname-file-cname)
- [⭐️ Enable Built-in Jekyll `enable_jekyll`](#%EF%B8%8F-enable-built-in-jekyll-enable_jekyll)
- [⭐️ Allow empty commits `allow_empty_commit`](#%EF%B8%8F-allow-empty-commits-allow_empty_commit)
- [⭐️ Keeping existing files `keep_files`](#%EF%B8%8F-keeping-existing-files-keep_files)
- [⭐️ Deploy to external repository `external_repository`](#%EF%B8%8F-deploy-to-external-repository-external_repository)
- [⭐️ Force orphan `force_orphan`](#%EF%B8%8F-force-orphan-force_orphan)
- [⭐️ Set Git username and email](#%EF%B8%8F-set-git-username-and-email)
- [⭐️ Set custom commit message](#%EF%B8%8F-set-custom-commit-message)
- [⭐️ Create Git tag](#%EF%B8%8F-create-git-tag)
@@ -200,7 +201,7 @@ jobs:
## Options
### ⭐️ `github_token`
### ⭐️ Set Runner's Access Token `github_token`
**This option is for `GITHUB_TOKEN`, not a personal access token.**
@@ -216,7 +217,7 @@ GitHub Actions runner automatically creates a `GITHUB_TOKEN` secret to use in yo
For more details about `GITHUB_TOKEN`: [Authenticating with the GITHUB_TOKEN - GitHub Help](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token)
### ⭐️ `deploy_key`
### ⭐️ Set SSH Private Key `deploy_key`
Read [Create SSH Deploy Key](#%EF%B8%8F-create-ssh-deploy-key), create your SSH deploy key, and set the `deploy_key` option like the following.
@@ -228,11 +229,10 @@ Read [Create SSH Deploy Key](#%EF%B8%8F-create-ssh-deploy-key), create your SSH
publish_dir: ./public
```
### ⭐️ `personal_token`
### ⭐️ Set Personal Access Token `personal_token`
[Generate a personal access token (`repo`)](https://github.com/settings/tokens) and add it to Secrets as `PERSONAL_TOKEN`, it works as well as `ACTIONS_DEPLOY_KEY`.
```yaml
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
@@ -241,7 +241,7 @@ Read [Create SSH Deploy Key](#%EF%B8%8F-create-ssh-deploy-key), create your SSH
publish_dir: ./public
```
### ⭐️ `publish_branch`
### ⭐️ Target Branch `publish_branch`
A target branch to deploy to GitHub Pages. The default is `gh-pages`.
@@ -253,9 +253,9 @@ A target branch to deploy to GitHub Pages. The default is `gh-pages`.
publish_branch: master # default: gh-pages
```
### ⭐️ `publish_dir`
### ⭐️ Source Directory `publish_dir`
A target directory to deploy to GitHub Pages. The default is `public`.
A source directory to deploy to GitHub Pages. The default is `public`.
```yaml
- name: Deploy
@@ -265,7 +265,22 @@ A target directory to deploy to GitHub Pages. The default is `public`.
publish_dir: ./out # default: public
```
### ⭐️ CNAME
### ⭐️ Deploy to Subdirectory `destination_dir`
*This feature is on beta.*
*Any feedback is welcome at [Issue #324](https://github.com/peaceiris/actions-gh-pages/issues/324)*
A destination subdirectory on a publishing branch. The default is empty.
```yaml
- name: Deploy
uses: peaceiris/actions-gh-pages@v3.7.0-0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
destination_dir: subdir
```
### ⭐️ Add CNAME file `cname`
To add `CNAME` file, we can set the `cname` option.
@@ -280,7 +295,7 @@ For more details about `CNAME`, read the official documentation: [Managing a cus
cname: github.com
```
### ⭐️ Enable Built-in Jekyll
### ⭐️ Enable Built-in Jekyll `enable_jekyll`
If you want GitHub Pages to process your site with the static site generator Jekyll, set `enable_jekyll` to true.
@@ -302,7 +317,7 @@ Bypassing Jekyll makes the deployment faster and is necessary if you are deployi
For more details about `.nojekyll`: [Bypassing Jekyll on GitHub Pages - The GitHub Blog](https://github.blog/2009-12-29-bypassing-jekyll-on-github-pages/)
### ⭐️ Allow empty commits
### ⭐️ Allow empty commits `allow_empty_commit`
By default, a commit will not be generated when no file changes. If you want to allow an empty commit, set the optional parameter `allow_empty_commit` to `true`.
@@ -317,7 +332,7 @@ For example:
allow_empty_commit: true
```
### ⭐️ Keeping existing files
### ⭐️ Keeping existing files `keep_files`
By default, existing files in the publish branch are removed before adding the ones from publish dir. If you want the action to add new files but leave existing ones untouched, set the optional parameter `keep_files` to `true`.
@@ -332,7 +347,7 @@ For example:
keep_files: true
```
### ⭐️ Deploy to external repository
### ⭐️ Deploy to external repository `external_repository`
By default, your files are published to the repository which is running this action.
If you want to publish to another repository on GitHub, set the environment variable `external_repository` to `<username>/<external-repository>`.
@@ -361,7 +376,7 @@ A GitHub Free Plan account cannot use the GitHub Pages in a private repository.
- `peaceiris/homepage`: A private repository running this action with `external_repository: peaceiris/peaceiris.github.io`
- `peaceiris/peaceiris.github.io`: A public repository using GitHub Pages
### ⭐️ Force orphan
### ⭐️ Force orphan `force_orphan`
We can set the `force_orphan: true` option.
This allows you to make your publish branch with only the latest commit.
@@ -535,7 +550,7 @@ updates:
schedule:
interval: "daily"
labels:
- "dependencies:ci"
- "CI/CD"
commit-message:
prefix: ci
```

View File

@@ -40,6 +40,7 @@ function getInputsLog(authMethod: string, inps: Inputs): string {
[INFO] ${authMethod}: true
[INFO] PublishBranch: ${inps.PublishBranch}
[INFO] PublishDir: ${inps.PublishDir}
[INFO] DestinationDir: ${inps.DestinationDir}
[INFO] ExternalRepository: ${inps.ExternalRepository}
[INFO] AllowEmptyCommit: ${inps.AllowEmptyCommit}
[INFO] KeepFiles: ${inps.KeepFiles}
@@ -107,6 +108,7 @@ describe('getInputs()', () => {
expect(inps.PersonalToken).toMatch('');
expect(inps.PublishBranch).toMatch('gh-pages');
expect(inps.PublishDir).toMatch('public');
expect(inps.DestinationDir).toMatch('');
expect(inps.ExternalRepository).toMatch('');
expect(inps.AllowEmptyCommit).toBe(false);
expect(inps.KeepFiles).toBe(false);
@@ -127,6 +129,7 @@ describe('getInputs()', () => {
process.env['INPUT_PERSONAL_TOKEN'] = 'test_personal_token';
process.env['INPUT_PUBLISH_BRANCH'] = 'master';
process.env['INPUT_PUBLISH_DIR'] = 'out';
process.env['INPUT_DESTINATION_DIR'] = 'subdir';
process.env['INPUT_EXTERNAL_REPOSITORY'] = 'user/repo';
process.env['INPUT_ALLOW_EMPTY_COMMIT'] = 'true';
process.env['INPUT_KEEP_FILES'] = 'true';
@@ -147,6 +150,7 @@ describe('getInputs()', () => {
expect(inps.PersonalToken).toMatch('test_personal_token');
expect(inps.PublishBranch).toMatch('master');
expect(inps.PublishDir).toMatch('out');
expect(inps.DestinationDir).toMatch('subdir');
expect(inps.ExternalRepository).toMatch('user/repo');
expect(inps.AllowEmptyCommit).toBe(true);
expect(inps.KeepFiles).toBe(true);

View File

@@ -1,5 +1,13 @@
import {getUserName, getUserEmail, setCommitAuthor, getCommitMessage} from '../src/git-utils';
import {getWorkDirName, createWorkDir} from '../src/utils';
import {
setRepo,
getUserName,
getUserEmail,
setCommitAuthor,
getCommitMessage
} from '../src/git-utils';
import {getInputs} from '../src/get-inputs';
import {Inputs} from '../src/interfaces';
import {getWorkDirName, createDir} from '../src/utils';
import {CmdResult} from '../src/interfaces';
import * as exec from '@actions/exec';
@@ -14,6 +22,35 @@ afterEach(() => {
delete process.env['GITHUB_REPOSITORY'];
});
describe('setRepo()', () => {
test('throw error destination_dir should be a relative path', async () => {
process.env['INPUT_GITHUB_TOKEN'] = 'test_github_token';
process.env['INPUT_PUBLISH_BRANCH'] = 'gh-pages';
process.env['INPUT_PUBLISH_DIR'] = 'public';
process.env['INPUT_DESTINATION_DIR'] = '/subdir';
// 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_FULL_COMMIT_MESSAGE'] = 'feat: Add new feature';
// process.env['INPUT_TAG_NAME'] = 'deploy-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 remoteURL = 'https://x-access-token:pat@github.com/actions/pages.git';
const date = new Date();
const unixTime = date.getTime();
const workDir = await getWorkDirName(`${unixTime}`);
await expect(setRepo(inps, remoteURL, workDir)).rejects.toThrowError(
'destination_dir should be a relative path'
);
});
});
describe('getUserName()', () => {
test('get default git user name', () => {
const userName = '';
@@ -51,7 +88,7 @@ describe('setCommitAuthor()', () => {
})();
beforeEach(async () => {
await createWorkDir(workDirName);
await createDir(workDirName);
process.chdir(workDirName);
await exec.exec('git', ['init']);
});

View File

@@ -3,7 +3,7 @@ import fs from 'fs';
import {
getHomeDir,
getWorkDirName,
createWorkDir,
createDir,
addNoJekyll,
addCNAME,
skipOnFork
@@ -51,11 +51,11 @@ describe('getWorkDirName()', () => {
});
});
describe('createWorkDir()', () => {
test('create work directory', async () => {
describe('createDir()', () => {
test('create a directory', async () => {
const unixTime = await getTime();
const workDirName = await getWorkDirName(`${unixTime}`);
await createWorkDir(workDirName);
await createDir(workDirName);
const test = fs.existsSync(workDirName);
expect(test).toBe(true);
});
@@ -65,7 +65,7 @@ async function getWorkDir(): Promise<string> {
const unixTime = await getTime();
let workDir = '';
workDir = await getWorkDirName(`${unixTime}`);
await createWorkDir(workDir);
await createDir(workDir);
return workDir;
}

View File

@@ -25,6 +25,10 @@ inputs:
description: 'Set an input directory for deployment.'
required: false
default: 'public'
destination_dir:
description: 'Set an destination subdirectory for deployment.'
required: false
default: ''
external_repository:
description: 'Set an external repository (owner/repo).'
required: false

File diff suppressed because one or more lines are too long

14
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "actions-github-pages",
"version": "3.6.4",
"version": "3.7.0-1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -997,9 +997,9 @@
}
},
"@types/jest": {
"version": "26.0.4",
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.4.tgz",
"integrity": "sha512-4fQNItvelbNA9+sFgU+fhJo8ZFF+AS4Egk3GWwCW2jFtViukXbnztccafAdLhzE/0EiCogljtQQXP8aQ9J7sFg==",
"version": "26.0.5",
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.5.tgz",
"integrity": "sha512-heU+7w8snfwfjtcj2H458aTx3m5unIToOJhx75ebHilBiiQ39OIdA18WkG4LP08YKeAoWAGvWg8s+22w/PeJ6w==",
"dev": true,
"requires": {
"jest-diff": "^25.2.1",
@@ -1025,9 +1025,9 @@
"dev": true
},
"@types/node": {
"version": "12.12.50",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.50.tgz",
"integrity": "sha512-5ImO01Fb8YsEOYpV+aeyGYztcYcjGsBvN4D7G5r1ef2cuQOpymjWNQi5V0rKHE6PC2ru3HkoUr/Br2/8GUA84w=="
"version": "12.12.51",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.51.tgz",
"integrity": "sha512-6ILqt8iNThALrxDv2Q4LyYFQxULQz96HKNIFd4s9QRQaiHINYeUpLqeU/2IU7YMtvipG1fQVAy//vY8/fX1Y9w=="
},
"@types/normalize-package-data": {
"version": "2.4.0",

View File

@@ -1,6 +1,6 @@
{
"name": "actions-github-pages",
"version": "3.6.4",
"version": "3.7.0-1",
"description": "GitHub Actions for GitHub Pages",
"main": "lib/index.js",
"engines": {
@@ -60,7 +60,7 @@
"@actions/io": "^1.0.2"
},
"devDependencies": {
"@types/jest": "^26.0.4",
"@types/jest": "^26.0.5",
"@types/js-yaml": "^3.12.4",
"@types/node": "~12",
"@typescript-eslint/eslint-plugin": "^2.34.0",

View File

@@ -15,6 +15,7 @@ export function showInputs(inps: Inputs): void {
[INFO] ${authMethod}: true
[INFO] PublishBranch: ${inps.PublishBranch}
[INFO] PublishDir: ${inps.PublishDir}
[INFO] DestinationDir: ${inps.DestinationDir}
[INFO] ExternalRepository: ${inps.ExternalRepository}
[INFO] AllowEmptyCommit: ${inps.AllowEmptyCommit}
[INFO] KeepFiles: ${inps.KeepFiles}
@@ -52,6 +53,7 @@ export function getInputs(): Inputs {
PersonalToken: core.getInput('personal_token'),
PublishBranch: core.getInput('publish_branch'),
PublishDir: core.getInput('publish_dir'),
DestinationDir: core.getInput('destination_dir'),
ExternalRepository: core.getInput('external_repository'),
AllowEmptyCommit: (core.getInput('allow_empty_commit') || 'false').toUpperCase() === 'TRUE',
KeepFiles: (core.getInput('keep_files') || 'false').toUpperCase() === 'TRUE',

View File

@@ -4,7 +4,7 @@ import * as io from '@actions/io';
import path from 'path';
import fs from 'fs';
import {Inputs, CmdResult} from './interfaces';
import {createWorkDir} from './utils';
import {createDir} from './utils';
export async function createBranchForce(branch: string): Promise<void> {
await exec.exec('git', ['init']);
@@ -12,7 +12,7 @@ export async function createBranchForce(branch: string): Promise<void> {
return;
}
export async function copyAssets(publishDir: string, workDir: string): Promise<void> {
export async function copyAssets(publishDir: string, destDir: string): Promise<void> {
const copyOpts = {recursive: true, force: true};
const files = fs.readdirSync(publishDir);
core.debug(`${files}`);
@@ -21,7 +21,7 @@ export async function copyAssets(publishDir: string, workDir: string): Promise<v
continue;
}
const filePath = path.join(publishDir, file);
await io.cp(filePath, `${workDir}/`, copyOpts);
await io.cp(filePath, `${destDir}/`, copyOpts);
core.info(`[INFO] copy ${file}`);
}
@@ -33,12 +33,24 @@ export async function setRepo(inps: Inputs, remoteURL: string, workDir: string):
? inps.PublishDir
: path.join(`${process.env.GITHUB_WORKSPACE}`, inps.PublishDir);
if (path.isAbsolute(inps.DestinationDir)) {
throw new Error('destination_dir should be a relative path');
}
const destDir = ((): string => {
if (inps.DestinationDir === '') {
return workDir;
} else {
return path.join(workDir, inps.DestinationDir);
}
})();
core.info(`[INFO] ForceOrphan: ${inps.ForceOrphan}`);
if (inps.ForceOrphan) {
await createWorkDir(workDir);
await createDir(destDir);
process.chdir(workDir);
await createBranchForce(inps.PublishBranch);
await copyAssets(publishDir, workDir);
process.chdir(destDir);
await copyAssets(publishDir, destDir);
return;
}
@@ -61,14 +73,26 @@ export async function setRepo(inps: Inputs, remoteURL: string, workDir: string):
options
);
if (result.exitcode === 0) {
process.chdir(workDir);
if (inps.KeepFiles) {
core.info('[INFO] Keep existing files');
await createDir(destDir);
process.chdir(destDir);
if (inps.DestinationDir !== '') {
if (inps.KeepFiles) {
core.info('[INFO] Keep existing files');
} else {
core.info(`[INFO] clean up ${destDir}`);
await exec.exec('git', ['rm', '-r', '--ignore-unmatch', '*']);
}
} else {
await exec.exec('git', ['rm', '-r', '--ignore-unmatch', '*']);
if (inps.KeepFiles) {
core.info('[INFO] Keep existing files');
} else {
core.info(`[INFO] clean up ${destDir}`);
await exec.exec('git', ['rm', '-r', '--ignore-unmatch', '*']);
}
}
await copyAssets(publishDir, workDir);
await copyAssets(publishDir, destDir);
return;
} else {
throw new Error(`Failed to clone remote branch ${inps.PublishBranch}`);
@@ -76,10 +100,10 @@ export async function setRepo(inps: Inputs, remoteURL: string, workDir: string):
} catch (e) {
core.info(`[INFO] first deployment, create new branch ${inps.PublishBranch}`);
core.info(e.message);
await createWorkDir(workDir);
await createDir(destDir);
process.chdir(workDir);
await createBranchForce(inps.PublishBranch);
await copyAssets(publishDir, workDir);
await copyAssets(publishDir, destDir);
return;
}
}

View File

@@ -4,6 +4,7 @@ export interface Inputs {
readonly PersonalToken: string;
readonly PublishBranch: string;
readonly PublishDir: string;
readonly DestinationDir: string;
readonly ExternalRepository: string;
readonly AllowEmptyCommit: boolean;
readonly KeepFiles: boolean;

View File

@@ -23,9 +23,9 @@ export async function getWorkDirName(unixTime: string): Promise<string> {
return workDirName;
}
export async function createWorkDir(workDirName: string): Promise<void> {
await io.mkdirP(workDirName);
core.debug(`Created: ${workDirName}`);
export async function createDir(dirPath: string): Promise<void> {
await io.mkdirP(dirPath);
core.debug(`Created directory ${dirPath}`);
return;
}