Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afee929f89 | ||
|
|
4b17904d54 | ||
|
|
ce4e3beff1 | ||
|
|
3874723ac6 | ||
|
|
f0c76f03b6 | ||
|
|
b7f7b0dddb | ||
|
|
14e12e8e74 | ||
|
|
f30118c78e | ||
|
|
0cb61e91a5 | ||
|
|
42a6cdde0c | ||
|
|
250469649c | ||
|
|
a5a8912d3e | ||
|
|
5980f05de8 | ||
|
|
106f76b593 |
2
.github/dependabot.yml
vendored
2
.github/dependabot.yml
vendored
@@ -21,6 +21,6 @@ updates:
|
|||||||
schedule:
|
schedule:
|
||||||
interval: "daily"
|
interval: "daily"
|
||||||
labels:
|
labels:
|
||||||
- "dependencies:ci"
|
- "CI/CD"
|
||||||
commit-message:
|
commit-message:
|
||||||
prefix: ci
|
prefix: ci
|
||||||
|
|||||||
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -64,7 +64,7 @@ jobs:
|
|||||||
name: coverage-${{ matrix.os }}
|
name: coverage-${{ matrix.os }}
|
||||||
path: coverage
|
path: coverage
|
||||||
|
|
||||||
- uses: codecov/codecov-action@v1.0.10
|
- uses: codecov/codecov-action@v1.0.11
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
|
||||||
|
|||||||
36
CHANGELOG.md
36
CHANGELOG.md
@@ -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.
|
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)
|
## [3.6.4](https://github.com/peaceiris/actions-gh-pages/compare/v3.6.3...v3.6.4) (2020-07-18)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
65
README.md
65
README.md
@@ -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 - Project](#%EF%B8%8F-repository-type---project)
|
||||||
- [⭐️ Repository type - User and Organization](#%EF%B8%8F-repository-type---user-and-organization)
|
- [⭐️ Repository type - User and Organization](#%EF%B8%8F-repository-type---user-and-organization)
|
||||||
- [Options](#options)
|
- [Options](#options)
|
||||||
- [⭐️ `github_token`](#%EF%B8%8F-github_token)
|
- [⭐️ Set Runner's Access Token `github_token`](#%EF%B8%8F-set-runners-access-token-github_token)
|
||||||
- [⭐️ `deploy_key`](#%EF%B8%8F-deploy_key)
|
- [⭐️ Set SSH Private Key `deploy_key`](#%EF%B8%8F-set-ssh-private-key-deploy_key)
|
||||||
- [⭐️ `personal_token`](#%EF%B8%8F-personal_token)
|
- [⭐️ Set Personal Access Token `personal_token`](#%EF%B8%8F-set-personal-access-token-personal_token)
|
||||||
- [⭐️ `publish_branch`](#%EF%B8%8F-publish_branch)
|
- [⭐️ Target Branch `publish_branch`](#%EF%B8%8F-target-branch-publish_branch)
|
||||||
- [⭐️ `publish_dir`](#%EF%B8%8F-publish_dir)
|
- [⭐️ Source Directory `publish_dir`](#%EF%B8%8F-source-directory-publish_dir)
|
||||||
- [⭐️ CNAME](#%EF%B8%8F-cname)
|
- [⭐️ Deploy to Subdirectory `destination_dir`](#%EF%B8%8F-deploy-to-subdirectory-destination_dir)
|
||||||
- [⭐️ Enable Built-in Jekyll](#%EF%B8%8F-enable-built-in-jekyll)
|
- [⭐️ Add CNAME file `cname`](#%EF%B8%8F-add-cname-file-cname)
|
||||||
- [⭐️ Allow empty commits](#%EF%B8%8F-allow-empty-commits)
|
- [⭐️ Enable Built-in Jekyll `enable_jekyll`](#%EF%B8%8F-enable-built-in-jekyll-enable_jekyll)
|
||||||
- [⭐️ Keeping existing files](#%EF%B8%8F-keeping-existing-files)
|
- [⭐️ Allow empty commits `allow_empty_commit`](#%EF%B8%8F-allow-empty-commits-allow_empty_commit)
|
||||||
- [⭐️ Deploy to external repository](#%EF%B8%8F-deploy-to-external-repository)
|
- [⭐️ Keeping existing files `keep_files`](#%EF%B8%8F-keeping-existing-files-keep_files)
|
||||||
- [⭐️ Force orphan](#%EF%B8%8F-force-orphan)
|
- [⭐️ 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 Git username and email](#%EF%B8%8F-set-git-username-and-email)
|
||||||
- [⭐️ Set custom commit message](#%EF%B8%8F-set-custom-commit-message)
|
- [⭐️ Set custom commit message](#%EF%B8%8F-set-custom-commit-message)
|
||||||
- [⭐️ Create Git tag](#%EF%B8%8F-create-git-tag)
|
- [⭐️ Create Git tag](#%EF%B8%8F-create-git-tag)
|
||||||
@@ -200,7 +201,7 @@ jobs:
|
|||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
### ⭐️ `github_token`
|
### ⭐️ Set Runner's Access Token `github_token`
|
||||||
|
|
||||||
**This option is for `GITHUB_TOKEN`, not a personal access 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)
|
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.
|
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
|
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`.
|
[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
|
```yaml
|
||||||
- name: Deploy
|
- name: Deploy
|
||||||
uses: peaceiris/actions-gh-pages@v3
|
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_dir: ./public
|
||||||
```
|
```
|
||||||
|
|
||||||
### ⭐️ `publish_branch`
|
### ⭐️ Target Branch `publish_branch`
|
||||||
|
|
||||||
A target branch to deploy to GitHub Pages. The default is `gh-pages`.
|
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_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
|
```yaml
|
||||||
- name: Deploy
|
- name: Deploy
|
||||||
@@ -265,7 +265,22 @@ A target directory to deploy to GitHub Pages. The default is `public`.
|
|||||||
publish_dir: ./out # default: 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.
|
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
|
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.
|
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/)
|
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`.
|
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
|
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`.
|
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
|
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.
|
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>`.
|
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/homepage`: A private repository running this action with `external_repository: peaceiris/peaceiris.github.io`
|
||||||
- `peaceiris/peaceiris.github.io`: A public repository using GitHub Pages
|
- `peaceiris/peaceiris.github.io`: A public repository using GitHub Pages
|
||||||
|
|
||||||
### ⭐️ Force orphan
|
### ⭐️ Force orphan `force_orphan`
|
||||||
|
|
||||||
We can set the `force_orphan: true` option.
|
We can set the `force_orphan: true` option.
|
||||||
This allows you to make your publish branch with only the latest commit.
|
This allows you to make your publish branch with only the latest commit.
|
||||||
@@ -535,7 +550,7 @@ updates:
|
|||||||
schedule:
|
schedule:
|
||||||
interval: "daily"
|
interval: "daily"
|
||||||
labels:
|
labels:
|
||||||
- "dependencies:ci"
|
- "CI/CD"
|
||||||
commit-message:
|
commit-message:
|
||||||
prefix: ci
|
prefix: ci
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ function getInputsLog(authMethod: string, inps: Inputs): string {
|
|||||||
[INFO] ${authMethod}: true
|
[INFO] ${authMethod}: true
|
||||||
[INFO] PublishBranch: ${inps.PublishBranch}
|
[INFO] PublishBranch: ${inps.PublishBranch}
|
||||||
[INFO] PublishDir: ${inps.PublishDir}
|
[INFO] PublishDir: ${inps.PublishDir}
|
||||||
|
[INFO] DestinationDir: ${inps.DestinationDir}
|
||||||
[INFO] ExternalRepository: ${inps.ExternalRepository}
|
[INFO] ExternalRepository: ${inps.ExternalRepository}
|
||||||
[INFO] AllowEmptyCommit: ${inps.AllowEmptyCommit}
|
[INFO] AllowEmptyCommit: ${inps.AllowEmptyCommit}
|
||||||
[INFO] KeepFiles: ${inps.KeepFiles}
|
[INFO] KeepFiles: ${inps.KeepFiles}
|
||||||
@@ -107,6 +108,7 @@ describe('getInputs()', () => {
|
|||||||
expect(inps.PersonalToken).toMatch('');
|
expect(inps.PersonalToken).toMatch('');
|
||||||
expect(inps.PublishBranch).toMatch('gh-pages');
|
expect(inps.PublishBranch).toMatch('gh-pages');
|
||||||
expect(inps.PublishDir).toMatch('public');
|
expect(inps.PublishDir).toMatch('public');
|
||||||
|
expect(inps.DestinationDir).toMatch('');
|
||||||
expect(inps.ExternalRepository).toMatch('');
|
expect(inps.ExternalRepository).toMatch('');
|
||||||
expect(inps.AllowEmptyCommit).toBe(false);
|
expect(inps.AllowEmptyCommit).toBe(false);
|
||||||
expect(inps.KeepFiles).toBe(false);
|
expect(inps.KeepFiles).toBe(false);
|
||||||
@@ -127,6 +129,7 @@ describe('getInputs()', () => {
|
|||||||
process.env['INPUT_PERSONAL_TOKEN'] = 'test_personal_token';
|
process.env['INPUT_PERSONAL_TOKEN'] = 'test_personal_token';
|
||||||
process.env['INPUT_PUBLISH_BRANCH'] = 'master';
|
process.env['INPUT_PUBLISH_BRANCH'] = 'master';
|
||||||
process.env['INPUT_PUBLISH_DIR'] = 'out';
|
process.env['INPUT_PUBLISH_DIR'] = 'out';
|
||||||
|
process.env['INPUT_DESTINATION_DIR'] = 'subdir';
|
||||||
process.env['INPUT_EXTERNAL_REPOSITORY'] = 'user/repo';
|
process.env['INPUT_EXTERNAL_REPOSITORY'] = 'user/repo';
|
||||||
process.env['INPUT_ALLOW_EMPTY_COMMIT'] = 'true';
|
process.env['INPUT_ALLOW_EMPTY_COMMIT'] = 'true';
|
||||||
process.env['INPUT_KEEP_FILES'] = 'true';
|
process.env['INPUT_KEEP_FILES'] = 'true';
|
||||||
@@ -147,6 +150,7 @@ describe('getInputs()', () => {
|
|||||||
expect(inps.PersonalToken).toMatch('test_personal_token');
|
expect(inps.PersonalToken).toMatch('test_personal_token');
|
||||||
expect(inps.PublishBranch).toMatch('master');
|
expect(inps.PublishBranch).toMatch('master');
|
||||||
expect(inps.PublishDir).toMatch('out');
|
expect(inps.PublishDir).toMatch('out');
|
||||||
|
expect(inps.DestinationDir).toMatch('subdir');
|
||||||
expect(inps.ExternalRepository).toMatch('user/repo');
|
expect(inps.ExternalRepository).toMatch('user/repo');
|
||||||
expect(inps.AllowEmptyCommit).toBe(true);
|
expect(inps.AllowEmptyCommit).toBe(true);
|
||||||
expect(inps.KeepFiles).toBe(true);
|
expect(inps.KeepFiles).toBe(true);
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
import {getUserName, getUserEmail, setCommitAuthor, getCommitMessage} from '../src/git-utils';
|
import {
|
||||||
import {getWorkDirName, createWorkDir} from '../src/utils';
|
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 {CmdResult} from '../src/interfaces';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
@@ -14,6 +22,35 @@ afterEach(() => {
|
|||||||
delete process.env['GITHUB_REPOSITORY'];
|
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()', () => {
|
describe('getUserName()', () => {
|
||||||
test('get default git user name', () => {
|
test('get default git user name', () => {
|
||||||
const userName = '';
|
const userName = '';
|
||||||
@@ -51,7 +88,7 @@ describe('setCommitAuthor()', () => {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await createWorkDir(workDirName);
|
await createDir(workDirName);
|
||||||
process.chdir(workDirName);
|
process.chdir(workDirName);
|
||||||
await exec.exec('git', ['init']);
|
await exec.exec('git', ['init']);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import fs from 'fs';
|
|||||||
import {
|
import {
|
||||||
getHomeDir,
|
getHomeDir,
|
||||||
getWorkDirName,
|
getWorkDirName,
|
||||||
createWorkDir,
|
createDir,
|
||||||
addNoJekyll,
|
addNoJekyll,
|
||||||
addCNAME,
|
addCNAME,
|
||||||
skipOnFork
|
skipOnFork
|
||||||
@@ -51,11 +51,11 @@ describe('getWorkDirName()', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('createWorkDir()', () => {
|
describe('createDir()', () => {
|
||||||
test('create work directory', async () => {
|
test('create a directory', async () => {
|
||||||
const unixTime = await getTime();
|
const unixTime = await getTime();
|
||||||
const workDirName = await getWorkDirName(`${unixTime}`);
|
const workDirName = await getWorkDirName(`${unixTime}`);
|
||||||
await createWorkDir(workDirName);
|
await createDir(workDirName);
|
||||||
const test = fs.existsSync(workDirName);
|
const test = fs.existsSync(workDirName);
|
||||||
expect(test).toBe(true);
|
expect(test).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -65,7 +65,7 @@ async function getWorkDir(): Promise<string> {
|
|||||||
const unixTime = await getTime();
|
const unixTime = await getTime();
|
||||||
let workDir = '';
|
let workDir = '';
|
||||||
workDir = await getWorkDirName(`${unixTime}`);
|
workDir = await getWorkDirName(`${unixTime}`);
|
||||||
await createWorkDir(workDir);
|
await createDir(workDir);
|
||||||
return workDir;
|
return workDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ inputs:
|
|||||||
description: 'Set an input directory for deployment.'
|
description: 'Set an input directory for deployment.'
|
||||||
required: false
|
required: false
|
||||||
default: 'public'
|
default: 'public'
|
||||||
|
destination_dir:
|
||||||
|
description: 'Set an destination subdirectory for deployment.'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
external_repository:
|
external_repository:
|
||||||
description: 'Set an external repository (owner/repo).'
|
description: 'Set an external repository (owner/repo).'
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
14
package-lock.json
generated
14
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "actions-github-pages",
|
"name": "actions-github-pages",
|
||||||
"version": "3.6.4",
|
"version": "3.7.0-1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -997,9 +997,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@types/jest": {
|
"@types/jest": {
|
||||||
"version": "26.0.4",
|
"version": "26.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.5.tgz",
|
||||||
"integrity": "sha512-4fQNItvelbNA9+sFgU+fhJo8ZFF+AS4Egk3GWwCW2jFtViukXbnztccafAdLhzE/0EiCogljtQQXP8aQ9J7sFg==",
|
"integrity": "sha512-heU+7w8snfwfjtcj2H458aTx3m5unIToOJhx75ebHilBiiQ39OIdA18WkG4LP08YKeAoWAGvWg8s+22w/PeJ6w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"jest-diff": "^25.2.1",
|
"jest-diff": "^25.2.1",
|
||||||
@@ -1025,9 +1025,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "12.12.50",
|
"version": "12.12.51",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.50.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.51.tgz",
|
||||||
"integrity": "sha512-5ImO01Fb8YsEOYpV+aeyGYztcYcjGsBvN4D7G5r1ef2cuQOpymjWNQi5V0rKHE6PC2ru3HkoUr/Br2/8GUA84w=="
|
"integrity": "sha512-6ILqt8iNThALrxDv2Q4LyYFQxULQz96HKNIFd4s9QRQaiHINYeUpLqeU/2IU7YMtvipG1fQVAy//vY8/fX1Y9w=="
|
||||||
},
|
},
|
||||||
"@types/normalize-package-data": {
|
"@types/normalize-package-data": {
|
||||||
"version": "2.4.0",
|
"version": "2.4.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "actions-github-pages",
|
"name": "actions-github-pages",
|
||||||
"version": "3.6.4",
|
"version": "3.7.0-1",
|
||||||
"description": "GitHub Actions for GitHub Pages",
|
"description": "GitHub Actions for GitHub Pages",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
"@actions/io": "^1.0.2"
|
"@actions/io": "^1.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^26.0.4",
|
"@types/jest": "^26.0.5",
|
||||||
"@types/js-yaml": "^3.12.4",
|
"@types/js-yaml": "^3.12.4",
|
||||||
"@types/node": "~12",
|
"@types/node": "~12",
|
||||||
"@typescript-eslint/eslint-plugin": "^2.34.0",
|
"@typescript-eslint/eslint-plugin": "^2.34.0",
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export function showInputs(inps: Inputs): void {
|
|||||||
[INFO] ${authMethod}: true
|
[INFO] ${authMethod}: true
|
||||||
[INFO] PublishBranch: ${inps.PublishBranch}
|
[INFO] PublishBranch: ${inps.PublishBranch}
|
||||||
[INFO] PublishDir: ${inps.PublishDir}
|
[INFO] PublishDir: ${inps.PublishDir}
|
||||||
|
[INFO] DestinationDir: ${inps.DestinationDir}
|
||||||
[INFO] ExternalRepository: ${inps.ExternalRepository}
|
[INFO] ExternalRepository: ${inps.ExternalRepository}
|
||||||
[INFO] AllowEmptyCommit: ${inps.AllowEmptyCommit}
|
[INFO] AllowEmptyCommit: ${inps.AllowEmptyCommit}
|
||||||
[INFO] KeepFiles: ${inps.KeepFiles}
|
[INFO] KeepFiles: ${inps.KeepFiles}
|
||||||
@@ -52,6 +53,7 @@ export function getInputs(): Inputs {
|
|||||||
PersonalToken: core.getInput('personal_token'),
|
PersonalToken: core.getInput('personal_token'),
|
||||||
PublishBranch: core.getInput('publish_branch'),
|
PublishBranch: core.getInput('publish_branch'),
|
||||||
PublishDir: core.getInput('publish_dir'),
|
PublishDir: core.getInput('publish_dir'),
|
||||||
|
DestinationDir: core.getInput('destination_dir'),
|
||||||
ExternalRepository: core.getInput('external_repository'),
|
ExternalRepository: core.getInput('external_repository'),
|
||||||
AllowEmptyCommit: (core.getInput('allow_empty_commit') || 'false').toUpperCase() === 'TRUE',
|
AllowEmptyCommit: (core.getInput('allow_empty_commit') || 'false').toUpperCase() === 'TRUE',
|
||||||
KeepFiles: (core.getInput('keep_files') || 'false').toUpperCase() === 'TRUE',
|
KeepFiles: (core.getInput('keep_files') || 'false').toUpperCase() === 'TRUE',
|
||||||
|
|||||||
@@ -4,7 +4,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 {createWorkDir} from './utils';
|
import {createDir} from './utils';
|
||||||
|
|
||||||
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']);
|
||||||
@@ -12,7 +12,7 @@ export async function createBranchForce(branch: string): Promise<void> {
|
|||||||
return;
|
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 copyOpts = {recursive: true, force: true};
|
||||||
const files = fs.readdirSync(publishDir);
|
const files = fs.readdirSync(publishDir);
|
||||||
core.debug(`${files}`);
|
core.debug(`${files}`);
|
||||||
@@ -21,7 +21,7 @@ export async function copyAssets(publishDir: string, workDir: string): Promise<v
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const filePath = path.join(publishDir, file);
|
const filePath = path.join(publishDir, file);
|
||||||
await io.cp(filePath, `${workDir}/`, copyOpts);
|
await io.cp(filePath, `${destDir}/`, copyOpts);
|
||||||
core.info(`[INFO] copy ${file}`);
|
core.info(`[INFO] copy ${file}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,12 +33,24 @@ export async function setRepo(inps: Inputs, remoteURL: string, workDir: string):
|
|||||||
? inps.PublishDir
|
? inps.PublishDir
|
||||||
: path.join(`${process.env.GITHUB_WORKSPACE}`, 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}`);
|
core.info(`[INFO] ForceOrphan: ${inps.ForceOrphan}`);
|
||||||
if (inps.ForceOrphan) {
|
if (inps.ForceOrphan) {
|
||||||
await createWorkDir(workDir);
|
await createDir(destDir);
|
||||||
process.chdir(workDir);
|
process.chdir(workDir);
|
||||||
await createBranchForce(inps.PublishBranch);
|
await createBranchForce(inps.PublishBranch);
|
||||||
await copyAssets(publishDir, workDir);
|
process.chdir(destDir);
|
||||||
|
await copyAssets(publishDir, destDir);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,14 +73,26 @@ export async function setRepo(inps: Inputs, remoteURL: string, workDir: string):
|
|||||||
options
|
options
|
||||||
);
|
);
|
||||||
if (result.exitcode === 0) {
|
if (result.exitcode === 0) {
|
||||||
process.chdir(workDir);
|
await createDir(destDir);
|
||||||
if (inps.KeepFiles) {
|
process.chdir(destDir);
|
||||||
core.info('[INFO] Keep existing files');
|
|
||||||
|
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 {
|
} 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;
|
return;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Failed to clone remote branch ${inps.PublishBranch}`);
|
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) {
|
} 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.message);
|
core.info(e.message);
|
||||||
await createWorkDir(workDir);
|
await createDir(destDir);
|
||||||
process.chdir(workDir);
|
process.chdir(workDir);
|
||||||
await createBranchForce(inps.PublishBranch);
|
await createBranchForce(inps.PublishBranch);
|
||||||
await copyAssets(publishDir, workDir);
|
await copyAssets(publishDir, destDir);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export interface Inputs {
|
|||||||
readonly PersonalToken: string;
|
readonly PersonalToken: string;
|
||||||
readonly PublishBranch: string;
|
readonly PublishBranch: string;
|
||||||
readonly PublishDir: string;
|
readonly PublishDir: string;
|
||||||
|
readonly DestinationDir: string;
|
||||||
readonly ExternalRepository: string;
|
readonly ExternalRepository: string;
|
||||||
readonly AllowEmptyCommit: boolean;
|
readonly AllowEmptyCommit: boolean;
|
||||||
readonly KeepFiles: boolean;
|
readonly KeepFiles: boolean;
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ export async function getWorkDirName(unixTime: string): Promise<string> {
|
|||||||
return workDirName;
|
return workDirName;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createWorkDir(workDirName: string): Promise<void> {
|
export async function createDir(dirPath: string): Promise<void> {
|
||||||
await io.mkdirP(workDirName);
|
await io.mkdirP(dirPath);
|
||||||
core.debug(`Created: ${workDirName}`);
|
core.debug(`Created directory ${dirPath}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user