mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
3.2.0 (#142)
* Additional Integration tests (#123) * Update integration-beta.yml * git fetch again * git fetch * Tests * Failing Build (#124) * Bump @types/node from 13.1.6 to 13.1.7 (#126) Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 13.1.6 to 13.1.7. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> * Bump @types/jest from 24.0.25 to 24.9.0 (#127) Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 24.0.25 to 24.9.0. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> * js > ts * License Upgrades * Bump typescript from 3.7.4 to 3.7.5 (#132) Bumps [typescript](https://github.com/Microsoft/TypeScript) from 3.7.4 to 3.7.5. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/compare/v3.7.4...v3.7.5) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> * [Issue-133] Customizable Commit Messages (#134) * Customizable Commit Messages * Removes lodash * Update package.json * README * Changes * Check for null * Adds a dash * Support action/checkout@v2 (#136) * Create CODEOWNERS * Update integration.yml * Adds automatic issue labels (#139) * [Issue-130] SSH Support (#140) * First pass at deploy key support * Needed * More ssh * Adds keyscan * Another look at this * More things.... * w * Path to home * w * k * Update git.ts * ff * dd * test * File Sync maybe * Adds SSH Examples * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * x * c * Update README.md * Integration tests * Update integration-beta.yml * More Changes * Update README.md * README Reorg * Update README.md * Update README.md * Update README.md * Adds correct metadata * Update action.yml * Formatting * Update build.yml * Adds CodeCov report * Update README.md * Test Coverage Improvements (#141) * Test Coverage Improvements * Update env.js * More Test Coverage / Imps * Update README.md * Formatting * Update git.js * Test Names... * Update action.yml Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
This commit is contained in:
parent
2a824df84f
commit
204e85b9d1
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
@ -0,0 +1 @@
|
||||
* @JamesIves
|
2
.github/ISSUE_TEMPLATE/BUG_REPORT.md
vendored
2
.github/ISSUE_TEMPLATE/BUG_REPORT.md
vendored
@ -1,6 +1,8 @@
|
||||
---
|
||||
name: Bug Report
|
||||
about: Create a bug report to help us improve the action.
|
||||
labels:
|
||||
- bug 🐝
|
||||
|
||||
---
|
||||
|
||||
|
2
.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md
vendored
2
.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md
vendored
@ -1,6 +1,8 @@
|
||||
---
|
||||
name: Feature Request
|
||||
about: If you'd like to make a suggestion please fill out the form below.
|
||||
labels:
|
||||
- feature request 🏭
|
||||
|
||||
---
|
||||
|
||||
|
2
.github/ISSUE_TEMPLATE/SUPPORT.md
vendored
2
.github/ISSUE_TEMPLATE/SUPPORT.md
vendored
@ -1,6 +1,8 @@
|
||||
---
|
||||
name: Support
|
||||
about: If you're having problems setting up the action you can make a request for support here.
|
||||
labels:
|
||||
- support 📞
|
||||
|
||||
---
|
||||
|
||||
|
5
.github/workflows/build.yml
vendored
5
.github/workflows/build.yml
vendored
@ -18,3 +18,8 @@ jobs:
|
||||
run: |
|
||||
npm install
|
||||
npm run-script test
|
||||
|
||||
- name: Uploade CodeCov Report
|
||||
uses: codecov/codecov-action@v1
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }} #required
|
||||
|
71
.github/workflows/integration-beta.yml
vendored
71
.github/workflows/integration-beta.yml
vendored
@ -32,6 +32,8 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Build and Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3-test
|
||||
@ -54,6 +56,8 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install rsync
|
||||
run: |
|
||||
@ -68,13 +72,67 @@ jobs:
|
||||
BASE_BRANCH: dev
|
||||
TARGET_FOLDER: montezuma2
|
||||
|
||||
# Deploys using the CLEAN option.
|
||||
integration-clean:
|
||||
needs: [integration-checkout-v1, integration-checkout-v2, integration-container]
|
||||
# Deploys using an SSH key
|
||||
integration-ssh:
|
||||
needs: integration-container
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install SSH Client
|
||||
uses: webfactory/ssh-agent@v0.2.0
|
||||
with:
|
||||
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
|
||||
|
||||
- name: Build and Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3-test
|
||||
with:
|
||||
SSH: true
|
||||
BRANCH: gh-pages-beta
|
||||
FOLDER: integration
|
||||
BASE_BRANCH: dev
|
||||
TARGET_FOLDER: montezuma3
|
||||
|
||||
# Deploys using a custom env.
|
||||
integration-env:
|
||||
needs: integration-ssh
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '10.x'
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install SSH Client
|
||||
uses: webfactory/ssh-agent@v0.2.0
|
||||
with:
|
||||
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
|
||||
|
||||
- name: Build and Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3-test
|
||||
with:
|
||||
SSH: true
|
||||
BRANCH: gh-pages-beta
|
||||
FOLDER: integration
|
||||
BASE_BRANCH: dev
|
||||
TARGET_FOLDER: montezuma4
|
||||
|
||||
# Deploys using the CLEAN option.
|
||||
integration-clean:
|
||||
needs: [integration-checkout-v1, integration-checkout-v2, integration-container, integration-ssh, integration-env]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Build and Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3-test
|
||||
@ -87,11 +145,12 @@ jobs:
|
||||
|
||||
# Deploys to a branch that doesn't exist.
|
||||
integration-branch-creation:
|
||||
needs: [integration-checkout-v1, integration-checkout-v2]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Build and Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3-test
|
||||
|
71
.github/workflows/integration.yml
vendored
71
.github/workflows/integration.yml
vendored
@ -53,6 +53,8 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install rsync
|
||||
run: |
|
||||
@ -67,13 +69,67 @@ jobs:
|
||||
BASE_BRANCH: dev
|
||||
TARGET_FOLDER: montezuma2
|
||||
|
||||
# Deploys using the CLEAN option.
|
||||
integration-clean:
|
||||
needs: [integration-checkout-v1, integration-checkout-v2, integration-container]
|
||||
# Deploys using an SSH key.
|
||||
integration-ssh:
|
||||
needs: integration-container
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install SSH Client
|
||||
uses: webfactory/ssh-agent@v0.2.0
|
||||
with:
|
||||
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
|
||||
|
||||
- name: Build and Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3
|
||||
with:
|
||||
SSH: true
|
||||
BRANCH: gh-pages-beta
|
||||
FOLDER: integration
|
||||
BASE_BRANCH: dev
|
||||
TARGET_FOLDER: montezuma3
|
||||
|
||||
# Deploys using a custom env.
|
||||
integration-env:
|
||||
needs: integration-ssh
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '10.x'
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install SSH Client
|
||||
uses: webfactory/ssh-agent@v0.2.0
|
||||
with:
|
||||
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
|
||||
|
||||
- name: Build and Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3
|
||||
with:
|
||||
SSH: true
|
||||
BRANCH: gh-pages-beta
|
||||
FOLDER: integration
|
||||
BASE_BRANCH: dev
|
||||
TARGET_FOLDER: montezuma4
|
||||
|
||||
# Deploys using the CLEAN option.
|
||||
integration-clean:
|
||||
needs: [integration-checkout-v1, integration-checkout-v2, integration-container, integration-ssh, integration-env]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Build and Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3
|
||||
@ -86,11 +142,12 @@ jobs:
|
||||
|
||||
# Deploys to a branch that doesn't exist.
|
||||
integration-branch-creation:
|
||||
needs: [integration-checkout-v1, integration-checkout-v2]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Build and Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3
|
||||
@ -105,4 +162,4 @@ jobs:
|
||||
uses: dawidd6/action-delete-branch@v2.0.1
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
branches: integration-test-delete-prod
|
||||
branches: integration-test-delete-prod
|
||||
|
11
.gitignore
vendored
11
.gitignore
vendored
@ -6,3 +6,14 @@ npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
node_modules
|
||||
|
||||
## Registry
|
||||
package-lock.json
|
||||
yarn-error.log
|
||||
|
||||
## SSH
|
||||
.ssh
|
||||
*.pub
|
||||
|
||||
## CodeCov
|
||||
coverage
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 James Ives
|
||||
Copyright (c) 2020 James Ives
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
159
README.md
159
README.md
@ -1,13 +1,13 @@
|
||||
# GitHub Pages Deploy Action :rocket:
|
||||
|
||||
[](https://github.com/JamesIves/github-pages-deploy-action/actions) [](https://github.com/JamesIves/github-pages-deploy-action/actions) [](https://github.com/marketplace/actions/deploy-to-github-pages) [](https://github.com/JamesIves/github-pages-deploy-action/releases)
|
||||
[](https://github.com/JamesIves/github-pages-deploy-action/actions) [](https://github.com/JamesIves/github-pages-deploy-action/actions) [](https://codecov.io/gh/JamesIves/github-pages-deploy-action/) [](https://github.com/marketplace/actions/deploy-to-github-pages) [](https://github.com/JamesIves/github-pages-deploy-action/releases)
|
||||
|
||||
This [GitHub action](https://github.com/features/actions) will handle the deploy process of your project to [GitHub Pages](https://pages.github.com/). It can be configured to upload your production-ready code into any branch you'd like, including `gh-pages` and `docs`.
|
||||
|
||||

|
||||
|
||||
## Getting Started :airplane:
|
||||
You can include the action in your workflow to trigger on any event that [GitHub actions supports](https://help.github.com/en/articles/events-that-trigger-workflows). If the remote branch that you wish to deploy to doesn't already exist the action will create it for you. Your workflow will also need to include the `actions/checkout@v1` step before this workflow runs in order for the deployment to work.
|
||||
You can include the action in your workflow to trigger on any event that [GitHub actions supports](https://help.github.com/en/articles/events-that-trigger-workflows). If the remote branch that you wish to deploy to doesn't already exist the action will create it for you. Your workflow will also need to include the `actions/checkout` step before this workflow runs in order for the deployment to work.
|
||||
|
||||
You can view an example of this below.
|
||||
|
||||
@ -19,7 +19,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Build and Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3
|
||||
@ -38,9 +40,119 @@ on:
|
||||
- master
|
||||
```
|
||||
|
||||
#### Operating System Support 💿
|
||||
## Configuration 📁
|
||||
|
||||
This action is primarily developed using [Ubuntu](https://ubuntu.com/). [In your workflow job configuration](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idruns-on) it's reccomended to set the `runs-on` property to `ubuntu-latest`.
|
||||
The `with` portion of the workflow **must** be configured before the action will work. You can add these in the `with` section found in the examples above. Any `secrets` must be referenced using the bracket syntax and stored in the GitHub repositories `Settings/Secrets` menu. You can learn more about setting environment variables with GitHub actions [here](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepsenv).
|
||||
|
||||
#### Required Setup
|
||||
|
||||
One of the following deployment options must be configured.
|
||||
|
||||
| Key | Value Information | Type | Required |
|
||||
| ------------- | ------------- | ------------- | ------------- |
|
||||
| `SSH` | You can configure the action to deploy using SSH by setting this option to `true`. More more information on how to add your ssh key pair please refer to the [Using a Deploy Key section of this README](https://github.com/JamesIves/github-pages-deploy-action/tree/dev#using-an-ssh-deploy-key-). | `with` | **Yes** |
|
||||
| `ACCESS_TOKEN` | Depending on the repository permissions you may need to provide the action with a GitHub personal access token instead of the provided GitHub token in order to deploy. You can [learn more about how to generate one here](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line). **This should be stored as a secret**. | `secrets / with` | **Yes** |
|
||||
| `GITHUB_TOKEN` | In order for GitHub to trigger the rebuild of your page you must provide the action with the repositories provided GitHub token. This can be referenced in the workflow `yml` file by using `${{ secrets.GITHUB_TOKEN }}`. **Please note there is currently an issue affecting the use of this token which makes it so it only works with private repositories, [you can learn more here](https://github.com/JamesIves/github-pages-deploy-action/issues/5)**. | `secrets / with` | **Yes** |
|
||||
|
||||
In addition to the deployment options you must also configure the following.
|
||||
|
||||
| Key | Value Information | Type | Required |
|
||||
| ------------- | ------------- | ------------- | ------------- |
|
||||
| `BRANCH` | This is the branch you wish to deploy to, for example `gh-pages` or `docs`. | `with` | **Yes** |
|
||||
| `FOLDER` | The folder in your repository that you want to deploy. If your build script compiles into a directory named `build` you'd put it here. **Folder paths cannot have a leading `/` or `./`**. If you wish to deploy the root directory you can place a `.` here. | `with` | **Yes** |
|
||||
|
||||
#### Optional Choices
|
||||
|
||||
| Key | Value Information | Type | Required |
|
||||
| ------------- | ------------- | ------------- | ------------- |
|
||||
| `TARGET_FOLDER` | If you'd like to push the contents of the deployment folder into a specific directory on the deployment branch you can specify it here. | `with` | **No** |
|
||||
| `BASE_BRANCH` | The base branch of your repository which you'd like to checkout prior to deploying. This defaults to the current commit [SHA](http://en.wikipedia.org/wiki/SHA-1) that triggered the build followed by `master` if it doesn't exist. This is useful for making deployments from another branch, and also may be necessary when using a scheduled job. | `with` | **No** |
|
||||
| `COMMIT_MESSAGE` | If you need to customize the commit message for an integration you can do so. | `with` | **No** |
|
||||
| `CLEAN` | If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option can be toggled on by setting it to `true`. | `with` | **No** |
|
||||
| `CLEAN_EXCLUDE` | If you need to use `CLEAN` but you'd like to preserve certain files or folders you can use this option. This should be formatted as an array but stored as a string. For example: `'["filename.js", "folder"]'` | `with` | **No** |
|
||||
|
||||
With the action correctly configured you should see the workflow trigger the deployment under the configured conditions.
|
||||
|
||||
---
|
||||
|
||||
### Additional Build Files 📁
|
||||
|
||||
This action maintains the full Git history of the deployment branch. Therefore if you're using a custom domain and require a `CNAME` file, or if you require the use of a `.nojekyll` file, you can safely commit these files directly into deployment branch without them being overridden after each deployment.
|
||||
|
||||
---
|
||||
|
||||
### Using an SSH Deploy Key 🔑
|
||||
|
||||
If you'd prefer to use an SSH deploy key as opposed to a token you must first generate a new SSH key by running the following terminal command, replacing the email with one connected to your GitHub account.
|
||||
|
||||
```bash
|
||||
ssh-keygen -t rsa -b 4096 -C "youremailhere@example.com" -N ""
|
||||
```
|
||||
|
||||
Once you've generated the key pair you must add the contents of the public key within your repositories [deploy keys menu](https://developer.github.com/v3/guides/managing-deploy-keys/). You can find this option by going to `Settings > Deploy Keys`, you can name the public key whatever you want, but you **do** need to give it write access. Afterwards add the contents of the private key to the `Settings > Secrets` menu as `DEPLOY_KEY`.
|
||||
|
||||
With this configured you must add the `ssh-agent` step to your workflow and set `SSH` to `true` within the deploy action.
|
||||
|
||||
```yml
|
||||
- name: Install SSH Client
|
||||
uses: webfactory/ssh-agent@v0.2.0
|
||||
with:
|
||||
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
|
||||
|
||||
- name: Build and Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3
|
||||
with:
|
||||
SSH: true
|
||||
BRANCH: gh-pages
|
||||
FOLDER: 'site'
|
||||
```
|
||||
|
||||
<details><summary>You can view a full example of this here.</summary>
|
||||
<p>
|
||||
|
||||
```yml
|
||||
name: Build and Deploy
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install
|
||||
run: |
|
||||
npm install
|
||||
npm run-script build
|
||||
|
||||
- name: Install SSH Client
|
||||
- uses: webfactory/ssh-agent@v0.2.0 # This step installs the ssh client into the workflow run. There's many options available for this on the action marketplace.
|
||||
with:
|
||||
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
|
||||
|
||||
- name: Build and Deploy Repo
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3-test
|
||||
with:
|
||||
BASE_BRANCH: master
|
||||
BRANCH: gh-pages
|
||||
FOLDER: 'build'
|
||||
CLEAN: true
|
||||
SSH: true # SSH must be set to true so the deploy action knows which protocol to deploy with.
|
||||
```
|
||||
</p>
|
||||
</details>
|
||||
|
||||
------
|
||||
|
||||
### Operating System Support 💿
|
||||
|
||||
This action is primarily developed using [Ubuntu](https://ubuntu.com/). [In your workflow job configuration](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idruns-on) it's recommended to set the `runs-on` property to `ubuntu-latest`.
|
||||
|
||||
```yml
|
||||
jobs:
|
||||
@ -48,7 +160,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
```
|
||||
|
||||
Operating systems such as [Windows](https://www.microsoft.com/en-us/windows/) are not currently supported, however you can workaround this using [artifacts](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/persisting-workflow-data-using-artifacts). In your workflow configuration you can utilize the `actions/upload-artifact` and `actions/download-artifact` actions to move your project built on a Windows job to a secondary job that will handle the deployment.
|
||||
If you're using an operating system such as [Windows](https://www.microsoft.com/en-us/windows/) you can workaround this using [artifacts](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/persisting-workflow-data-using-artifacts). In your workflow configuration you can utilize the `actions/upload-artifact` and `actions/download-artifact` actions to move your project built on a Windows job to a secondary job that will handle the deployment.
|
||||
|
||||
<details><summary>You can view an example of this pattern here.</summary>
|
||||
<p>
|
||||
@ -61,7 +173,9 @@ jobs:
|
||||
runs-on: windows-latest # The first job utilizes windows-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install # The project is built using npm and placed in the 'build' folder.
|
||||
run: |
|
||||
@ -79,7 +193,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Download Artifacts # The built project is downloaded into the 'site' folder.
|
||||
uses: actions/download-artifact@v1
|
||||
@ -96,7 +212,9 @@ jobs:
|
||||
</p>
|
||||
</details>
|
||||
|
||||
#### Using a Container 📦
|
||||
---
|
||||
|
||||
### Using a Container 📦
|
||||
|
||||
If you use a [container](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idcontainer) in your workflow you may need to run an additional step to install `rsync` as this action depends on it. You can view an example of this below.
|
||||
|
||||
@ -108,26 +226,3 @@ If you use a [container](https://help.github.com/en/actions/automating-your-work
|
||||
- name: Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3
|
||||
```
|
||||
|
||||
## Configuration 📁
|
||||
|
||||
The `with` portion of the workflow **must** be configured before the action will work. You can add these in the `with` section found in the examples above. Any `secrets` must be referenced using the bracket syntax and stored in the GitHub repositories `Settings/Secrets` menu. You can learn more about setting environment variables with GitHub actions [here](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepsenv).
|
||||
|
||||
Below you'll find a description of what each option does.
|
||||
|
||||
| Key | Value Information | Type | Required |
|
||||
| ------------- | ------------- | ------------- | ------------- |
|
||||
| `ACCESS_TOKEN` | Depending on the repository permissions you may need to provide the action with a GitHub personal access token instead of the provided GitHub token in order to deploy. You can [learn more about how to generate one here](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line). **This should be stored as a secret**. | `secrets / with` | **Yes** |
|
||||
| `GITHUB_TOKEN` | In order for GitHub to trigger the rebuild of your page you must provide the action with the repositories provided GitHub token. This can be referenced in the workflow `yml` file by using `${{ secrets.GITHUB_TOKEN }}`. Only required if an access token is **not** provided. **Please note there is currently an issue affecting the use of this token, [you can learn more here](https://github.com/JamesIves/github-pages-deploy-action/issues/5)**. | `secrets / with` | **Yes** |
|
||||
| `BRANCH` | This is the branch you wish to deploy to, for example `gh-pages` or `docs`. | `with` | **Yes** |
|
||||
| `FOLDER` | The folder in your repository that you want to deploy. If your build script compiles into a directory named `build` you'd put it here. **Folder paths cannot have a leading `/` or `./`**. If you wish to deploy the root directory you can place a `.` here. | `with` | **Yes** |
|
||||
| `TARGET_FOLDER` | If you'd like to push the contents of the deployment folder into a specific directory on the deployment branch you can specify it here. | `with` | **No** |
|
||||
| `BASE_BRANCH` | The base branch of your repository which you'd like to checkout prior to deploying. This defaults to the current commit [SHA](http://en.wikipedia.org/wiki/SHA-1) that triggered the build followed by `master` if it doesn't exist. This is useful for making deployments from another branch, and also may be neccersary when using a scheduled job. | `with` | **No** |
|
||||
| `CLEAN` | If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option can be toggled on by setting it to `true`. | `with` | **No** |
|
||||
| `CLEAN_EXCLUDE` | If you need to use `CLEAN` but you'd like to preserve certain files or folders you can use this option. This should be formatted as an array but stored as a string. For example: `'["filename.js", "folder"]'` | `with` | **No** |
|
||||
|
||||
With the action correctly configured you should see the workflow trigger the deployment under the configured conditions.
|
||||
|
||||
### Additional Build Files
|
||||
|
||||
This action maintains the full Git history of the deployment branch. Therefore if you're using a custom domain and require a `CNAME` file, or if you require the use of a `.nojekyll` file, you can safely commit these files directly into deployment branch without them being overridden after each deployment.
|
||||
|
@ -1 +1 @@
|
||||
process.env.UNIT_TEST = true
|
||||
process.env.UNIT_TEST = "true"
|
@ -1,23 +1,20 @@
|
||||
import {execute} from '../src/execute';
|
||||
import {exec} from '@actions/exec';
|
||||
import { execute, stdout } from "../src/execute";
|
||||
import { exec } from "@actions/exec";
|
||||
|
||||
jest.mock('@actions/exec', () => ({
|
||||
jest.mock("@actions/exec", () => ({
|
||||
exec: jest.fn()
|
||||
}))
|
||||
}));
|
||||
|
||||
describe('execute', () => {
|
||||
describe('execute', () => {
|
||||
it('should be called with the correct arguments', async() => {
|
||||
await execute('echo Montezuma', './')
|
||||
|
||||
expect(exec).toBeCalledWith(
|
||||
"echo Montezuma", [], {
|
||||
cwd: "./",
|
||||
listeners: {
|
||||
stdout: expect.any(Function)
|
||||
}
|
||||
}
|
||||
)
|
||||
describe("execute", () => {
|
||||
it("should be called with the correct arguments", async () => {
|
||||
await stdout("hello");
|
||||
await execute("echo Montezuma", "./");
|
||||
|
||||
expect(exec).toBeCalledWith("echo Montezuma", [], {
|
||||
cwd: "./",
|
||||
listeners: {
|
||||
stdout: expect.any(Function)
|
||||
}
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
@ -2,12 +2,17 @@
|
||||
process.env["INPUT_FOLDER"] = "build";
|
||||
process.env["GITHUB_SHA"] = "123";
|
||||
|
||||
import _ from "lodash";
|
||||
import { action } from "../src/constants";
|
||||
import { deploy, generateBranch, init, switchToBaseBranch } from "../src/git";
|
||||
import { execute } from "../src/execute";
|
||||
import { setFailed } from "@actions/core";
|
||||
|
||||
const originalAction = _.cloneDeep(action);
|
||||
const originalAction = JSON.stringify(action);
|
||||
|
||||
jest.mock("@actions/core", () => ({
|
||||
setFailed: jest.fn(),
|
||||
getInput: jest.fn()
|
||||
}));
|
||||
|
||||
jest.mock("../src/execute", () => ({
|
||||
execute: jest.fn()
|
||||
@ -15,13 +20,14 @@ jest.mock("../src/execute", () => ({
|
||||
|
||||
describe("git", () => {
|
||||
afterEach(() => {
|
||||
_.assignIn(action, originalAction);
|
||||
Object.assign(action, JSON.parse(originalAction));
|
||||
});
|
||||
|
||||
describe("init", () => {
|
||||
it("should execute three commands if a GitHub token is provided", async () => {
|
||||
it("should execute commands if a GitHub token is provided", async () => {
|
||||
Object.assign(action, {
|
||||
build: "build",
|
||||
branch: "branch",
|
||||
gitHubToken: "123",
|
||||
pusher: {
|
||||
name: "asd",
|
||||
@ -34,9 +40,10 @@ describe("git", () => {
|
||||
expect(call).toBe("Initialization step complete...");
|
||||
});
|
||||
|
||||
it("should execute three commands if a Access token is provided", async () => {
|
||||
it("should execute commands if an Access Token is provided", async () => {
|
||||
Object.assign(action, {
|
||||
build: "build",
|
||||
branch: "branch",
|
||||
accessToken: "123",
|
||||
pusher: {
|
||||
name: "asd",
|
||||
@ -50,9 +57,11 @@ describe("git", () => {
|
||||
expect(call).toBe("Initialization step complete...");
|
||||
});
|
||||
|
||||
it("should fail if there is no provided GitHub Token or Access Token", async () => {
|
||||
it("should execute commands if SSH is true", async () => {
|
||||
Object.assign(action, {
|
||||
build: "build",
|
||||
branch: "branch",
|
||||
ssh: true,
|
||||
pusher: {
|
||||
name: "asd",
|
||||
email: "as@cat"
|
||||
@ -61,6 +70,25 @@ describe("git", () => {
|
||||
|
||||
const call = await init();
|
||||
|
||||
expect(execute).toBeCalledTimes(6);
|
||||
expect(call).toBe("Initialization step complete...");
|
||||
});
|
||||
|
||||
it("should fail if there is no provided GitHub Token, Access Token or SSH bool", async () => {
|
||||
Object.assign(action, {
|
||||
build: "build",
|
||||
branch: "branch",
|
||||
pusher: {
|
||||
name: "asd",
|
||||
email: "as@cat"
|
||||
},
|
||||
gitHubToken: null,
|
||||
accessToken: null,
|
||||
ssh: null
|
||||
});
|
||||
|
||||
const call = await init();
|
||||
expect(setFailed).toBeCalledTimes(1);
|
||||
expect(execute).toBeCalledTimes(0);
|
||||
expect(call).toBe("Initialization step complete...");
|
||||
});
|
||||
@ -68,6 +96,7 @@ describe("git", () => {
|
||||
it("should fail if the build folder begins with a /", async () => {
|
||||
Object.assign(action, {
|
||||
accessToken: "123",
|
||||
branch: "branch",
|
||||
build: "/",
|
||||
pusher: {
|
||||
name: "asd",
|
||||
@ -77,6 +106,7 @@ describe("git", () => {
|
||||
|
||||
const call = await init();
|
||||
|
||||
expect(setFailed).toBeCalledTimes(1);
|
||||
expect(execute).toBeCalledTimes(0);
|
||||
expect(call).toBe("Initialization step complete...");
|
||||
});
|
||||
@ -84,6 +114,7 @@ describe("git", () => {
|
||||
it("should fail if the build folder begins with a ./", async () => {
|
||||
Object.assign(action, {
|
||||
accessToken: "123",
|
||||
branch: "branch",
|
||||
build: "./",
|
||||
pusher: {
|
||||
name: "asd",
|
||||
@ -92,7 +123,7 @@ describe("git", () => {
|
||||
});
|
||||
|
||||
const call = await init();
|
||||
|
||||
expect(setFailed).toBeCalledTimes(1);
|
||||
expect(execute).toBeCalledTimes(0);
|
||||
expect(call).toBe("Initialization step complete...");
|
||||
});
|
||||
@ -100,6 +131,7 @@ describe("git", () => {
|
||||
it("should not fail if root is used", async () => {
|
||||
Object.assign(action, {
|
||||
accessToken: "123",
|
||||
branch: "branch",
|
||||
build: ".",
|
||||
pusher: {
|
||||
name: "asd",
|
||||
@ -115,15 +147,52 @@ describe("git", () => {
|
||||
});
|
||||
|
||||
describe("generateBranch", () => {
|
||||
it("should execute five commands", async () => {
|
||||
it("should execute six commands", async () => {
|
||||
Object.assign(action, {
|
||||
accessToken: "123",
|
||||
branch: "branch",
|
||||
build: ".",
|
||||
pusher: {
|
||||
name: "asd",
|
||||
email: "as@cat"
|
||||
}
|
||||
});
|
||||
|
||||
const call = await generateBranch();
|
||||
expect(execute).toBeCalledTimes(6);
|
||||
expect(call).toBe("Deployment branch creation step complete... ✅");
|
||||
});
|
||||
|
||||
it("should fail if there is no branch", async () => {
|
||||
Object.assign(action, {
|
||||
accessToken: "123",
|
||||
branch: null,
|
||||
build: ".",
|
||||
pusher: {
|
||||
name: "asd",
|
||||
email: "as@cat"
|
||||
}
|
||||
});
|
||||
|
||||
const call = await generateBranch();
|
||||
expect(execute).toBeCalledTimes(0);
|
||||
expect(setFailed).toBeCalledTimes(1);
|
||||
expect(call).toBe("Deployment branch creation step complete... ✅");
|
||||
});
|
||||
});
|
||||
|
||||
describe("switchToBaseBranch", () => {
|
||||
it("should execute one command", async () => {
|
||||
Object.assign(action, {
|
||||
accessToken: "123",
|
||||
branch: "branch",
|
||||
build: ".",
|
||||
pusher: {
|
||||
name: "asd",
|
||||
email: "as@cat"
|
||||
}
|
||||
});
|
||||
|
||||
const call = await switchToBaseBranch();
|
||||
expect(execute).toBeCalledTimes(1);
|
||||
expect(call).toBe("Switched to the base branch...");
|
||||
@ -131,9 +200,10 @@ describe("git", () => {
|
||||
});
|
||||
|
||||
describe("deploy", () => {
|
||||
it("should execute five commands", async () => {
|
||||
it("should execute commands", async () => {
|
||||
Object.assign(action, {
|
||||
build: "build",
|
||||
branch: "branch",
|
||||
gitHubToken: "123",
|
||||
pusher: {
|
||||
name: "asd",
|
||||
@ -144,8 +214,63 @@ describe("git", () => {
|
||||
const call = await deploy();
|
||||
|
||||
// Includes the call to generateBranch
|
||||
expect(execute).toBeCalledTimes(18);
|
||||
expect(execute).toBeCalledTimes(12);
|
||||
expect(call).toBe("Commit step complete...");
|
||||
});
|
||||
|
||||
it("should execute commands with clean options", async () => {
|
||||
Object.assign(action, {
|
||||
build: "build",
|
||||
branch: "branch",
|
||||
gitHubToken: "123",
|
||||
pusher: {
|
||||
name: "asd",
|
||||
email: "as@cat"
|
||||
},
|
||||
clean: true,
|
||||
cleanExclude: '["cat", "montezuma"]'
|
||||
});
|
||||
|
||||
const call = await deploy();
|
||||
|
||||
// Includes the call to generateBranch
|
||||
expect(execute).toBeCalledTimes(12);
|
||||
expect(call).toBe("Commit step complete...");
|
||||
});
|
||||
|
||||
it("should gracefully handle incorrectly formatted clean exclude items", async () => {
|
||||
Object.assign(action, {
|
||||
build: ".",
|
||||
branch: "branch",
|
||||
gitHubToken: "123",
|
||||
pusher: {},
|
||||
clean: true,
|
||||
targetFolder: "new_folder",
|
||||
commitMessage: "Hello!",
|
||||
isTest: true,
|
||||
cleanExclude: '["cat, "montezuma"]' // There is a syntax errror in the string.
|
||||
});
|
||||
|
||||
const call = await deploy();
|
||||
|
||||
expect(execute).toBeCalledTimes(12);
|
||||
expect(call).toBe("Commit step complete...");
|
||||
});
|
||||
|
||||
it("should stop early if there is nothing to commit", async () => {
|
||||
Object.assign(action, {
|
||||
build: "build",
|
||||
branch: "branch",
|
||||
gitHubToken: "123",
|
||||
pusher: {
|
||||
name: "asd",
|
||||
email: "as@cat"
|
||||
},
|
||||
isTest: false // Setting this env variable to false means there will never be anything to commit and the action will exit early.
|
||||
});
|
||||
|
||||
await deploy();
|
||||
expect(execute).toBeCalledTimes(12);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
59
__tests__/main.test.ts
Normal file
59
__tests__/main.test.ts
Normal file
@ -0,0 +1,59 @@
|
||||
// Initial env variable setup for tests.
|
||||
process.env["INPUT_FOLDER"] = "build";
|
||||
process.env["GITHUB_SHA"] = "123";
|
||||
|
||||
import { action } from "../src/constants";
|
||||
import main from "../src/main";
|
||||
import { execute } from "../src/execute";
|
||||
import { setFailed } from "@actions/core";
|
||||
|
||||
const originalAction = JSON.stringify(action);
|
||||
|
||||
jest.mock("../src/execute", () => ({
|
||||
execute: jest.fn()
|
||||
}));
|
||||
|
||||
jest.mock("@actions/core", () => ({
|
||||
setFailed: jest.fn(),
|
||||
getInput: jest.fn()
|
||||
}));
|
||||
|
||||
describe("main", () => {
|
||||
afterEach(() => {
|
||||
Object.assign(action, JSON.parse(originalAction));
|
||||
});
|
||||
|
||||
it("should run through the commands", async () => {
|
||||
Object.assign(action, {
|
||||
build: "build",
|
||||
branch: "branch",
|
||||
gitHubToken: "123",
|
||||
pusher: {
|
||||
name: "asd",
|
||||
email: "as@cat"
|
||||
},
|
||||
isTest: true
|
||||
});
|
||||
await main();
|
||||
expect(execute).toBeCalledTimes(30);
|
||||
});
|
||||
|
||||
it("should throw if an error is encountered", async () => {
|
||||
Object.assign(action, {
|
||||
build: "build",
|
||||
branch: "branch",
|
||||
baseBranch: "master",
|
||||
gitHubToken: null,
|
||||
ssh: null,
|
||||
accessToken: null,
|
||||
pusher: {
|
||||
name: "asd",
|
||||
email: "as@cat"
|
||||
},
|
||||
isTest: true
|
||||
});
|
||||
await main();
|
||||
expect(execute).toBeCalledTimes(12);
|
||||
expect(setFailed).toBeCalledTimes(1);
|
||||
});
|
||||
});
|
@ -1,21 +1,20 @@
|
||||
import {isNullOrUndefined} from '../src/util';
|
||||
import { isNullOrUndefined } from "../src/util";
|
||||
|
||||
|
||||
describe('util', () => {
|
||||
describe('isNullOrUndefined', () => {
|
||||
it('should return true if the value is null', async() => {
|
||||
describe("util", () => {
|
||||
describe("isNullOrUndefined", () => {
|
||||
it("should return true if the value is null", async () => {
|
||||
const value = null;
|
||||
expect(isNullOrUndefined(value)).toBeTruthy()
|
||||
expect(isNullOrUndefined(value)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should return true if the value is undefined', async() => {
|
||||
it("should return true if the value is undefined", async () => {
|
||||
const value = undefined;
|
||||
expect(isNullOrUndefined(value)).toBeTruthy()
|
||||
expect(isNullOrUndefined(value)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should return false if the value is defined', async() => {
|
||||
const value = 'montezuma';
|
||||
expect(isNullOrUndefined(value)).toBeFalsy()
|
||||
it("should return false if the value is defined", async () => {
|
||||
const value = "montezuma";
|
||||
expect(isNullOrUndefined(value)).toBeFalsy();
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
42
action.yml
42
action.yml
@ -6,4 +6,44 @@ runs:
|
||||
main: 'lib/main.js'
|
||||
branding:
|
||||
icon: 'git-commit'
|
||||
color: 'orange'
|
||||
color: 'orange'
|
||||
inputs:
|
||||
SSH:
|
||||
description: 'You can configure the action to deploy using SSH by setting this option to true. More more information on how to add your ssh key pair please refer to the Using a Deploy Key section of this README.'
|
||||
required: false
|
||||
|
||||
ACCESS_TOKEN:
|
||||
description: 'Depending on the repository permissions you may need to provide the action with a GitHub personal access token instead of the provided GitHub token in order to deploy. This should be stored as a secret.'
|
||||
required: false
|
||||
|
||||
GITHUB_TOKEN:
|
||||
description: 'In order for GitHub to trigger the rebuild of your page you must provide the action with the repositories provided GitHub token.'
|
||||
required: false
|
||||
|
||||
BRANCH:
|
||||
description: 'This is the branch you wish to deploy to, for example gh-pages or docs.'
|
||||
required: true
|
||||
|
||||
FOLDER:
|
||||
description: 'The folder in your repository that you want to deploy. If your build script compiles into a directory named build you would put it here. Folder paths cannot have a leading / or ./. If you wish to deploy the root directory you can place a . here.'
|
||||
required: true
|
||||
|
||||
TARGET_FOLDER:
|
||||
description: 'If you would like to push the contents of the deployment folder into a specific directory on the deployment branch you can specify it here.'
|
||||
required: false
|
||||
|
||||
BASE_BRANCH:
|
||||
description: 'The base branch of your repository which you would like to checkout prior to deploying. This defaults to the current commit SHA that triggered the build followed by master if it does not exist. This is useful for making deployments from another branch, and also may be necessary when using a scheduled job.'
|
||||
required: false
|
||||
|
||||
COMMIT_MESSAGE:
|
||||
description: 'If you need to customize the commit message for an integration you can do so.'
|
||||
required: false
|
||||
|
||||
CLEAN:
|
||||
description: 'If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option can be toggled on by setting it to true.'
|
||||
required: false
|
||||
|
||||
CLEAN_EXCLUDE:
|
||||
description: "If you need to use CLEAN but you would like to preserve certain files or folders you can use this option. This should be formatted as an array but stored as a string."
|
||||
required: false
|
||||
|
@ -8,5 +8,7 @@ module.exports = {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: true,
|
||||
setupFiles: ["<rootDir>/__tests__/env.js"]
|
||||
setupFiles: ["<rootDir>/__tests__/env.js"],
|
||||
collectCoverage: true,
|
||||
collectCoverageFrom: ['src/*.ts','!src/constants.ts']
|
||||
}
|
2
lib/__tests__/env.js
Normal file
2
lib/__tests__/env.js
Normal file
@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
process.env.UNIT_TEST = "true";
|
@ -7,37 +7,49 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const core_1 = require("@actions/core");
|
||||
const github = __importStar(require("@actions/github"));
|
||||
const { pusher, repository } = github.context.payload;
|
||||
exports.workspace = process.env.GITHUB_WORKSPACE;
|
||||
exports.folder = core.getInput("FOLDER", { required: true });
|
||||
exports.folder = core_1.getInput("FOLDER", { required: true });
|
||||
exports.root = ".";
|
||||
exports.isTest = process.env.UNIT_TEST;
|
||||
// Required action data.
|
||||
exports.action = {
|
||||
accessToken: core_1.getInput("ACCESS_TOKEN"),
|
||||
baseBranch: core_1.getInput("BASE_BRANCH"),
|
||||
build: exports.folder,
|
||||
branch: core_1.getInput("BRANCH"),
|
||||
commitMessage: core_1.getInput("COMMIT_MESSAGE"),
|
||||
clean: core_1.getInput("CLEAN"),
|
||||
cleanExclude: core_1.getInput("CLEAN_EXCLUDE"),
|
||||
defaultBranch: process.env.GITHUB_SHA ? process.env.GITHUB_SHA : "master",
|
||||
isTest: process.env.UNIT_TEST,
|
||||
ssh: core_1.getInput("SSH"),
|
||||
email: pusher && pusher.email
|
||||
? pusher.email
|
||||
: `${process.env.GITHUB_ACTOR ||
|
||||
"github-pages-deploy-action"}@users.noreply.github.com`,
|
||||
gitHubRepository: repository && repository.full_name
|
||||
? repository.full_name
|
||||
: process.env.GITHUB_REPOSITORY,
|
||||
gitHubToken: core.getInput("GITHUB_TOKEN"),
|
||||
accessToken: core.getInput("ACCESS_TOKEN"),
|
||||
branch: core.getInput("BRANCH"),
|
||||
targetFolder: core.getInput("TARGET_FOLDER"),
|
||||
baseBranch: core.getInput("BASE_BRANCH"),
|
||||
defaultBranch: process.env.GITHUB_SHA ? process.env.GITHUB_SHA : "master",
|
||||
gitHubToken: core_1.getInput("GITHUB_TOKEN"),
|
||||
name: pusher && pusher.name
|
||||
? pusher.name
|
||||
: process.env.GITHUB_ACTOR
|
||||
? process.env.GITHUB_ACTOR
|
||||
: "GitHub Pages Deploy Action",
|
||||
email: pusher && pusher.email
|
||||
? pusher.email
|
||||
: `${process.env.GITHUB_ACTOR ||
|
||||
"github-pages-deploy-action"}@users.noreply.github.com`,
|
||||
clean: core.getInput("CLEAN"),
|
||||
cleanExclude: core.getInput("CLEAN_EXCLUDE")
|
||||
targetFolder: core_1.getInput("TARGET_FOLDER")
|
||||
};
|
||||
// Token Types
|
||||
exports.tokenType = exports.action.ssh
|
||||
? "SSH Deploy Key"
|
||||
: exports.action.accessToken
|
||||
? "Access Token"
|
||||
: exports.action.gitHubToken
|
||||
? "GitHub Token"
|
||||
: "...";
|
||||
// Repository path used for commits/pushes.
|
||||
exports.repositoryPath = `https://${exports.action.accessToken ||
|
||||
`x-access-token:${exports.action.gitHubToken}`}@github.com/${exports.action.gitHubRepository}.git`;
|
||||
exports.repositoryPath = exports.action.ssh
|
||||
? `git@github.com:${exports.action.gitHubRepository}`
|
||||
: `https://${exports.action.accessToken ||
|
||||
`x-access-token:${exports.action.gitHubToken}`}@github.com/${exports.action.gitHubRepository}.git`;
|
||||
|
@ -10,6 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const exec_1 = require("@actions/exec");
|
||||
// Stores the output from execute.
|
||||
let output;
|
||||
/** Wrapper around the GitHub toolkit exec command which returns the output.
|
||||
* Also allows you to easily toggle the current working directory.
|
||||
* @param {String} cmd = The command to execute.
|
||||
@ -18,16 +20,18 @@ const exec_1 = require("@actions/exec");
|
||||
*/
|
||||
function execute(cmd, cwd) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let output = "";
|
||||
output = "";
|
||||
yield exec_1.exec(cmd, [], {
|
||||
cwd,
|
||||
listeners: {
|
||||
stdout: (data) => {
|
||||
output += data.toString().trim();
|
||||
}
|
||||
stdout
|
||||
}
|
||||
});
|
||||
return Promise.resolve(output);
|
||||
});
|
||||
}
|
||||
exports.execute = execute;
|
||||
function stdout(data) {
|
||||
output += data.toString().trim();
|
||||
}
|
||||
exports.stdout = stdout;
|
||||
|
38
lib/git.js
38
lib/git.js
@ -8,18 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const core_1 = require("@actions/core");
|
||||
const constants_1 = require("./constants");
|
||||
const execute_1 = require("./execute");
|
||||
const util_1 = require("./util");
|
||||
const constants_1 = require("./constants");
|
||||
/** Generates the branch if it doesn't exist on the remote.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
@ -27,12 +20,16 @@ function init() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
if (util_1.isNullOrUndefined(constants_1.action.accessToken) &&
|
||||
util_1.isNullOrUndefined(constants_1.action.gitHubToken)) {
|
||||
return core.setFailed("You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy.");
|
||||
util_1.isNullOrUndefined(constants_1.action.gitHubToken) &&
|
||||
util_1.isNullOrUndefined(constants_1.action.ssh)) {
|
||||
core_1.setFailed("You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true.");
|
||||
throw Error("No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true.");
|
||||
}
|
||||
if (constants_1.action.build.startsWith("/") || constants_1.action.build.startsWith("./")) {
|
||||
return core.setFailed(`The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.`);
|
||||
core_1.setFailed(`The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.`);
|
||||
throw Error("Incorrectly formatted build folder. The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.");
|
||||
}
|
||||
console.log(`Deploying using ${constants_1.tokenType}... 🔑`);
|
||||
yield execute_1.execute(`git init`, constants_1.workspace);
|
||||
yield execute_1.execute(`git config user.name ${constants_1.action.name}`, constants_1.workspace);
|
||||
yield execute_1.execute(`git config user.email ${constants_1.action.email}`, constants_1.workspace);
|
||||
@ -41,7 +38,7 @@ function init() {
|
||||
yield execute_1.execute(`git fetch`, constants_1.workspace);
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(`There was an error initializing the repository: ${error}`);
|
||||
console.log(`There was an error initializing the repository: ${error}`);
|
||||
}
|
||||
finally {
|
||||
return Promise.resolve("Initialization step complete...");
|
||||
@ -65,6 +62,9 @@ exports.switchToBaseBranch = switchToBaseBranch;
|
||||
function generateBranch() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
if (util_1.isNullOrUndefined(constants_1.action.branch)) {
|
||||
throw Error("Branch is required.");
|
||||
}
|
||||
console.log(`Creating ${constants_1.action.branch} branch... 🔧`);
|
||||
yield switchToBaseBranch();
|
||||
yield execute_1.execute(`git checkout --orphan ${constants_1.action.branch}`, constants_1.workspace);
|
||||
@ -74,7 +74,7 @@ function generateBranch() {
|
||||
yield execute_1.execute(`git fetch`, constants_1.workspace);
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(`There was an error creating the deployment branch: ${error} ❌`);
|
||||
core_1.setFailed(`There was an error creating the deployment branch: ${error} ❌`);
|
||||
}
|
||||
finally {
|
||||
return Promise.resolve("Deployment branch creation step complete... ✅");
|
||||
@ -94,7 +94,7 @@ function deploy() {
|
||||
If the branch doesn't exist it gets created here as an orphan.
|
||||
*/
|
||||
const branchExists = yield execute_1.execute(`git ls-remote --heads ${constants_1.repositoryPath} ${constants_1.action.branch} | wc -l`, constants_1.workspace);
|
||||
if (!branchExists) {
|
||||
if (!branchExists && !constants_1.action.isTest) {
|
||||
console.log("Deployment branch does not exist. Creating....");
|
||||
yield generateBranch();
|
||||
}
|
||||
@ -121,16 +121,18 @@ function deploy() {
|
||||
? `${temporaryDeploymentDirectory}/${constants_1.action.targetFolder}`
|
||||
: temporaryDeploymentDirectory} ${constants_1.action.clean
|
||||
? `--delete ${excludes} --exclude CNAME --exclude .nojekyll`
|
||||
: ""} --exclude .git --exclude .github ${constants_1.action.build === constants_1.root ? `--exclude ${temporaryDeploymentDirectory}` : ""}`, constants_1.workspace);
|
||||
: ""} --exclude .ssh --exclude .git --exclude .github ${constants_1.action.build === constants_1.root ? `--exclude ${temporaryDeploymentDirectory}` : ""}`, constants_1.workspace);
|
||||
const hasFilesToCommit = yield execute_1.execute(`git status --porcelain`, temporaryDeploymentDirectory);
|
||||
if (!hasFilesToCommit && !constants_1.isTest) {
|
||||
if (!hasFilesToCommit && !constants_1.action.isTest) {
|
||||
console.log("There is nothing to commit. Exiting... ✅");
|
||||
return Promise.resolve();
|
||||
}
|
||||
// Commits to GitHub.
|
||||
yield execute_1.execute(`git add --all .`, temporaryDeploymentDirectory);
|
||||
yield execute_1.execute(`git checkout -b ${temporaryDeploymentBranch}`, temporaryDeploymentDirectory);
|
||||
yield execute_1.execute(`git commit -m "Deploying to ${constants_1.action.branch} from ${constants_1.action.baseBranch} ${process.env.GITHUB_SHA}" --quiet`, temporaryDeploymentDirectory);
|
||||
yield execute_1.execute(`git commit -m "${!util_1.isNullOrUndefined(constants_1.action.commitMessage)
|
||||
? constants_1.action.commitMessage
|
||||
: `Deploying to ${constants_1.action.branch} from ${constants_1.action.baseBranch}`} - ${process.env.GITHUB_SHA} 🚀" --quiet`, temporaryDeploymentDirectory);
|
||||
yield execute_1.execute(`git push --force ${constants_1.repositoryPath} ${temporaryDeploymentBranch}:${constants_1.action.branch}`, temporaryDeploymentDirectory);
|
||||
// Cleans up temporary files/folders and restores the git state.
|
||||
console.log("Running post deployment cleanup jobs... 🔧");
|
||||
|
20
lib/main.js
20
lib/main.js
@ -8,29 +8,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const core_1 = require("@actions/core");
|
||||
const git_1 = require("./git");
|
||||
/** Initializes and runs the action. */
|
||||
(function () {
|
||||
function main() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
yield git_1.init();
|
||||
yield git_1.deploy();
|
||||
}
|
||||
catch (error) {
|
||||
/* istanbul ignore next */
|
||||
console.log("The deployment encountered an error. ❌");
|
||||
core.setFailed(error.message);
|
||||
/* istanbul ignore next */
|
||||
core_1.setFailed(error);
|
||||
}
|
||||
finally {
|
||||
console.log("Completed Deployment ✅");
|
||||
}
|
||||
});
|
||||
})();
|
||||
}
|
||||
exports.default = main;
|
||||
// Init
|
||||
main();
|
||||
|
@ -16,27 +16,28 @@ exports.root = ".";
|
||||
exports.isTest = process.env.UNIT_TEST;
|
||||
// Required action data.
|
||||
exports.action = {
|
||||
accessToken: core.getInput("ACCESS_TOKEN"),
|
||||
baseBranch: core.getInput("BASE_BRANCH"),
|
||||
build: exports.folder,
|
||||
branch: core.getInput("BRANCH"),
|
||||
commitMessage: core.getInput("COMMIT_MESSAGE"),
|
||||
clean: core.getInput("CLEAN"),
|
||||
cleanExclude: core.getInput("CLEAN_EXCLUDE"),
|
||||
defaultBranch: process.env.GITHUB_SHA ? process.env.GITHUB_SHA : "master",
|
||||
email: pusher && pusher.email
|
||||
? pusher.email
|
||||
: `${process.env.GITHUB_ACTOR ||
|
||||
"github-pages-deploy-action"}@users.noreply.github.com`,
|
||||
gitHubRepository: repository && repository.full_name
|
||||
? repository.full_name
|
||||
: process.env.GITHUB_REPOSITORY,
|
||||
gitHubToken: core.getInput("GITHUB_TOKEN"),
|
||||
accessToken: core.getInput("ACCESS_TOKEN"),
|
||||
branch: core.getInput("BRANCH"),
|
||||
targetFolder: core.getInput("TARGET_FOLDER"),
|
||||
baseBranch: core.getInput("BASE_BRANCH"),
|
||||
defaultBranch: process.env.GITHUB_SHA ? process.env.GITHUB_SHA : "master",
|
||||
name: pusher && pusher.name
|
||||
? pusher.name
|
||||
: process.env.GITHUB_ACTOR
|
||||
? process.env.GITHUB_ACTOR
|
||||
: "GitHub Pages Deploy Action",
|
||||
email: pusher && pusher.email
|
||||
? pusher.email
|
||||
: `${process.env.GITHUB_ACTOR ||
|
||||
"github-pages-deploy-action"}@users.noreply.github.com`,
|
||||
clean: core.getInput("CLEAN"),
|
||||
cleanExclude: core.getInput("CLEAN_EXCLUDE")
|
||||
targetFolder: core.getInput("TARGET_FOLDER")
|
||||
};
|
||||
// Repository path used for commits/pushes.
|
||||
exports.repositoryPath = `https://${exports.action.accessToken ||
|
||||
|
@ -31,12 +31,13 @@ function init() {
|
||||
return core.setFailed("You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy.");
|
||||
}
|
||||
if (constants_1.action.build.startsWith("/") || constants_1.action.build.startsWith("./")) {
|
||||
console.log("2");
|
||||
return core.setFailed(`The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.`);
|
||||
}
|
||||
yield execute_1.execute(`git init`, constants_1.workspace);
|
||||
yield execute_1.execute(`git config user.name ${constants_1.action.name}`, constants_1.workspace);
|
||||
yield execute_1.execute(`git config user.email ${constants_1.action.email}`, constants_1.workspace);
|
||||
yield execute_1.execute(`git remote rm origin`, constants_1.workspace);
|
||||
yield execute_1.execute(`git remote add origin ${constants_1.repositoryPath}`, constants_1.workspace);
|
||||
yield execute_1.execute(`git fetch`, constants_1.workspace);
|
||||
}
|
||||
catch (error) {
|
||||
@ -53,9 +54,7 @@ exports.init = init;
|
||||
*/
|
||||
function switchToBaseBranch() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield execute_1.execute(constants_1.action.baseBranch
|
||||
? `git switch ${constants_1.action.baseBranch}`
|
||||
: `git checkout --progress --force ${constants_1.action.defaultBranch}`, constants_1.workspace);
|
||||
yield execute_1.execute(`git checkout --progress --force ${constants_1.action.baseBranch ? constants_1.action.baseBranch : constants_1.action.defaultBranch}`, constants_1.workspace);
|
||||
return Promise.resolve("Switched to the base branch...");
|
||||
});
|
||||
}
|
||||
@ -68,7 +67,7 @@ function generateBranch() {
|
||||
try {
|
||||
console.log(`Creating ${constants_1.action.branch} branch... 🔧`);
|
||||
yield switchToBaseBranch();
|
||||
yield execute_1.execute(`git switch --orphan ${constants_1.action.branch}`, constants_1.workspace);
|
||||
yield execute_1.execute(`git checkout --orphan ${constants_1.action.branch}`, constants_1.workspace);
|
||||
yield execute_1.execute(`git reset --hard`, constants_1.workspace);
|
||||
yield execute_1.execute(`git commit --allow-empty -m "Initial ${constants_1.action.branch} commit."`, constants_1.workspace);
|
||||
yield execute_1.execute(`git push ${constants_1.repositoryPath} ${constants_1.action.branch}`, constants_1.workspace);
|
||||
@ -130,8 +129,10 @@ function deploy() {
|
||||
}
|
||||
// Commits to GitHub.
|
||||
yield execute_1.execute(`git add --all .`, temporaryDeploymentDirectory);
|
||||
yield execute_1.execute(`git switch -c ${temporaryDeploymentBranch}`, temporaryDeploymentDirectory);
|
||||
yield execute_1.execute(`git commit -m "Deploying to ${constants_1.action.branch} from ${constants_1.action.baseBranch} ${process.env.GITHUB_SHA}" --quiet`, temporaryDeploymentDirectory);
|
||||
yield execute_1.execute(`git checkout -b ${temporaryDeploymentBranch}`, temporaryDeploymentDirectory);
|
||||
yield execute_1.execute(`git commit -m "${constants_1.action.commitMessage
|
||||
? constants_1.action.commitMessage
|
||||
: `Deploying to ${constants_1.action.branch} from ${constants_1.action.baseBranch}`} ${process.env.GITHUB_SHA} 🚀" --quiet`, temporaryDeploymentDirectory);
|
||||
yield execute_1.execute(`git push --force ${constants_1.repositoryPath} ${temporaryDeploymentBranch}:${constants_1.action.branch}`, temporaryDeploymentDirectory);
|
||||
// Cleans up temporary files/folders and restores the git state.
|
||||
console.log("Running post deployment cleanup jobs... 🔧");
|
||||
|
@ -7,7 +7,7 @@
|
||||
"build": "tsc",
|
||||
"test": "jest",
|
||||
"lint": "tslint -p tsconfig.json --project '.' || (echo Project needs formatting)",
|
||||
"format": "prettier --write './src/*.ts'"
|
||||
"format": "prettier --write './**/*.ts'"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -29,7 +29,7 @@
|
||||
"deploy",
|
||||
"deployment"
|
||||
],
|
||||
"author": "James Ives",
|
||||
"author": "James Ives <iam@jamesiv.es>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.0",
|
||||
@ -41,7 +41,6 @@
|
||||
"@types/node": "^13.1.2",
|
||||
"jest": "^24.8.0",
|
||||
"jest-circus": "^24.7.1",
|
||||
"lodash": "^4.17.15",
|
||||
"prettier": "^1.19.1",
|
||||
"ts-jest": "^24.2.0",
|
||||
"tslint": "^5.20.0",
|
||||
|
@ -1,43 +1,56 @@
|
||||
import * as core from "@actions/core";
|
||||
import { getInput } from "@actions/core";
|
||||
import * as github from "@actions/github";
|
||||
|
||||
const { pusher, repository } = github.context.payload;
|
||||
|
||||
export const workspace: any = process.env.GITHUB_WORKSPACE;
|
||||
export const folder = core.getInput("FOLDER", { required: true });
|
||||
export const folder = getInput("FOLDER", { required: true });
|
||||
export const root = ".";
|
||||
export const isTest = process.env.UNIT_TEST;
|
||||
|
||||
// Required action data.
|
||||
export const action = {
|
||||
accessToken: getInput("ACCESS_TOKEN"),
|
||||
baseBranch: getInput("BASE_BRANCH"),
|
||||
build: folder,
|
||||
branch: getInput("BRANCH"),
|
||||
commitMessage: getInput("COMMIT_MESSAGE"),
|
||||
clean: getInput("CLEAN"),
|
||||
cleanExclude: getInput("CLEAN_EXCLUDE"),
|
||||
defaultBranch: process.env.GITHUB_SHA ? process.env.GITHUB_SHA : "master",
|
||||
isTest: process.env.UNIT_TEST,
|
||||
ssh: getInput("SSH"),
|
||||
email:
|
||||
pusher && pusher.email
|
||||
? pusher.email
|
||||
: `${process.env.GITHUB_ACTOR ||
|
||||
"github-pages-deploy-action"}@users.noreply.github.com`,
|
||||
gitHubRepository:
|
||||
repository && repository.full_name
|
||||
? repository.full_name
|
||||
: process.env.GITHUB_REPOSITORY,
|
||||
gitHubToken: core.getInput("GITHUB_TOKEN"),
|
||||
accessToken: core.getInput("ACCESS_TOKEN"),
|
||||
branch: core.getInput("BRANCH"),
|
||||
targetFolder: core.getInput("TARGET_FOLDER"),
|
||||
baseBranch: core.getInput("BASE_BRANCH"),
|
||||
defaultBranch: process.env.GITHUB_SHA ? process.env.GITHUB_SHA : "master",
|
||||
gitHubToken: getInput("GITHUB_TOKEN"),
|
||||
name:
|
||||
pusher && pusher.name
|
||||
? pusher.name
|
||||
: process.env.GITHUB_ACTOR
|
||||
? process.env.GITHUB_ACTOR
|
||||
: "GitHub Pages Deploy Action",
|
||||
email:
|
||||
pusher && pusher.email
|
||||
? pusher.email
|
||||
: `${process.env.GITHUB_ACTOR ||
|
||||
"github-pages-deploy-action"}@users.noreply.github.com`,
|
||||
clean: core.getInput("CLEAN"),
|
||||
cleanExclude: core.getInput("CLEAN_EXCLUDE")
|
||||
targetFolder: getInput("TARGET_FOLDER")
|
||||
};
|
||||
|
||||
// Token Types
|
||||
export const tokenType = action.ssh
|
||||
? "SSH Deploy Key"
|
||||
: action.accessToken
|
||||
? "Access Token"
|
||||
: action.gitHubToken
|
||||
? "GitHub Token"
|
||||
: "...";
|
||||
|
||||
// Repository path used for commits/pushes.
|
||||
export const repositoryPath = `https://${action.accessToken ||
|
||||
`x-access-token:${action.gitHubToken}`}@github.com/${
|
||||
action.gitHubRepository
|
||||
}.git`;
|
||||
export const repositoryPath = action.ssh
|
||||
? `git@github.com:${action.gitHubRepository}`
|
||||
: `https://${action.accessToken ||
|
||||
`x-access-token:${action.gitHubToken}`}@github.com/${
|
||||
action.gitHubRepository
|
||||
}.git`;
|
||||
|
@ -1,5 +1,8 @@
|
||||
import { exec } from "@actions/exec";
|
||||
|
||||
// Stores the output from execute.
|
||||
let output: string;
|
||||
|
||||
/** Wrapper around the GitHub toolkit exec command which returns the output.
|
||||
* Also allows you to easily toggle the current working directory.
|
||||
* @param {String} cmd = The command to execute.
|
||||
@ -7,16 +10,18 @@ import { exec } from "@actions/exec";
|
||||
* @returns {Promise} - The output from the command.
|
||||
*/
|
||||
export async function execute(cmd: string, cwd: string): Promise<any> {
|
||||
let output = "";
|
||||
output = "";
|
||||
|
||||
await exec(cmd, [], {
|
||||
cwd,
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => {
|
||||
output += data.toString().trim();
|
||||
}
|
||||
stdout
|
||||
}
|
||||
});
|
||||
|
||||
return Promise.resolve(output);
|
||||
}
|
||||
|
||||
export function stdout(data: any) {
|
||||
output += data.toString().trim();
|
||||
}
|
||||
|
50
src/git.ts
50
src/git.ts
@ -1,7 +1,13 @@
|
||||
import * as core from "@actions/core";
|
||||
import { setFailed } from "@actions/core";
|
||||
import {
|
||||
action,
|
||||
repositoryPath,
|
||||
root,
|
||||
tokenType,
|
||||
workspace
|
||||
} from "./constants";
|
||||
import { execute } from "./execute";
|
||||
import { isNullOrUndefined } from "./util";
|
||||
import { workspace, action, root, repositoryPath, isTest } from "./constants";
|
||||
|
||||
/** Generates the branch if it doesn't exist on the remote.
|
||||
* @returns {Promise}
|
||||
@ -10,19 +16,29 @@ export async function init(): Promise<any> {
|
||||
try {
|
||||
if (
|
||||
isNullOrUndefined(action.accessToken) &&
|
||||
isNullOrUndefined(action.gitHubToken)
|
||||
isNullOrUndefined(action.gitHubToken) &&
|
||||
isNullOrUndefined(action.ssh)
|
||||
) {
|
||||
return core.setFailed(
|
||||
"You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy."
|
||||
setFailed(
|
||||
"You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true."
|
||||
);
|
||||
|
||||
throw Error(
|
||||
"No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true."
|
||||
);
|
||||
}
|
||||
|
||||
if (action.build.startsWith("/") || action.build.startsWith("./")) {
|
||||
return core.setFailed(
|
||||
setFailed(
|
||||
`The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.`
|
||||
);
|
||||
|
||||
throw Error(
|
||||
"Incorrectly formatted build folder. The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly."
|
||||
);
|
||||
}
|
||||
|
||||
console.log(`Deploying using ${tokenType}... 🔑`);
|
||||
await execute(`git init`, workspace);
|
||||
await execute(`git config user.name ${action.name}`, workspace);
|
||||
await execute(`git config user.email ${action.email}`, workspace);
|
||||
@ -30,7 +46,7 @@ export async function init(): Promise<any> {
|
||||
await execute(`git remote add origin ${repositoryPath}`, workspace);
|
||||
await execute(`git fetch`, workspace);
|
||||
} catch (error) {
|
||||
core.setFailed(`There was an error initializing the repository: ${error}`);
|
||||
console.log(`There was an error initializing the repository: ${error}`);
|
||||
} finally {
|
||||
return Promise.resolve("Initialization step complete...");
|
||||
}
|
||||
@ -55,6 +71,10 @@ export async function switchToBaseBranch(): Promise<any> {
|
||||
*/
|
||||
export async function generateBranch(): Promise<any> {
|
||||
try {
|
||||
if (isNullOrUndefined(action.branch)) {
|
||||
throw Error("Branch is required.");
|
||||
}
|
||||
|
||||
console.log(`Creating ${action.branch} branch... 🔧`);
|
||||
await switchToBaseBranch();
|
||||
await execute(`git checkout --orphan ${action.branch}`, workspace);
|
||||
@ -66,9 +86,7 @@ export async function generateBranch(): Promise<any> {
|
||||
await execute(`git push ${repositoryPath} ${action.branch}`, workspace);
|
||||
await execute(`git fetch`, workspace);
|
||||
} catch (error) {
|
||||
core.setFailed(
|
||||
`There was an error creating the deployment branch: ${error} ❌`
|
||||
);
|
||||
setFailed(`There was an error creating the deployment branch: ${error} ❌`);
|
||||
} finally {
|
||||
return Promise.resolve("Deployment branch creation step complete... ✅");
|
||||
}
|
||||
@ -88,7 +106,7 @@ export async function deploy(): Promise<any> {
|
||||
`git ls-remote --heads ${repositoryPath} ${action.branch} | wc -l`,
|
||||
workspace
|
||||
);
|
||||
if (!branchExists) {
|
||||
if (!branchExists && !action.isTest) {
|
||||
console.log("Deployment branch does not exist. Creating....");
|
||||
await generateBranch();
|
||||
}
|
||||
@ -129,7 +147,7 @@ export async function deploy(): Promise<any> {
|
||||
action.clean
|
||||
? `--delete ${excludes} --exclude CNAME --exclude .nojekyll`
|
||||
: ""
|
||||
} --exclude .git --exclude .github ${
|
||||
} --exclude .ssh --exclude .git --exclude .github ${
|
||||
action.build === root ? `--exclude ${temporaryDeploymentDirectory}` : ""
|
||||
}`,
|
||||
workspace
|
||||
@ -140,7 +158,7 @@ export async function deploy(): Promise<any> {
|
||||
temporaryDeploymentDirectory
|
||||
);
|
||||
|
||||
if (!hasFilesToCommit && !isTest) {
|
||||
if (!hasFilesToCommit && !action.isTest) {
|
||||
console.log("There is nothing to commit. Exiting... ✅");
|
||||
return Promise.resolve();
|
||||
}
|
||||
@ -152,7 +170,11 @@ export async function deploy(): Promise<any> {
|
||||
temporaryDeploymentDirectory
|
||||
);
|
||||
await execute(
|
||||
`git commit -m "Deploying to ${action.branch} from ${action.baseBranch} ${process.env.GITHUB_SHA}" --quiet`,
|
||||
`git commit -m "${
|
||||
!isNullOrUndefined(action.commitMessage)
|
||||
? action.commitMessage
|
||||
: `Deploying to ${action.branch} from ${action.baseBranch}`
|
||||
} - ${process.env.GITHUB_SHA} 🚀" --quiet`,
|
||||
temporaryDeploymentDirectory
|
||||
);
|
||||
await execute(
|
||||
|
13
src/main.ts
13
src/main.ts
@ -1,15 +1,20 @@
|
||||
import * as core from "@actions/core";
|
||||
import { setFailed } from "@actions/core";
|
||||
import { init, deploy } from "./git";
|
||||
|
||||
/** Initializes and runs the action. */
|
||||
(async function() {
|
||||
export default async function main() {
|
||||
try {
|
||||
await init();
|
||||
await deploy();
|
||||
} catch (error) {
|
||||
/* istanbul ignore next */
|
||||
console.log("The deployment encountered an error. ❌");
|
||||
core.setFailed(error.message);
|
||||
/* istanbul ignore next */
|
||||
setFailed(error);
|
||||
} finally {
|
||||
console.log("Completed Deployment ✅");
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
// Init
|
||||
main();
|
||||
|
12
yarn.lock
12
yarn.lock
@ -389,14 +389,14 @@
|
||||
"@types/istanbul-lib-report" "*"
|
||||
|
||||
"@types/jest@^24.0.25":
|
||||
version "24.0.25"
|
||||
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.0.25.tgz#2aba377824ce040114aa906ad2cac2c85351360f"
|
||||
version "24.9.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-24.9.0.tgz#78c6991cd1734cf0d390be24875e310bb0a9fb74"
|
||||
dependencies:
|
||||
jest-diff "^24.3.0"
|
||||
|
||||
"@types/node@>= 8", "@types/node@^13.1.2":
|
||||
version "13.1.6"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.1.6.tgz#076028d0b0400be8105b89a0a55550c86684ffec"
|
||||
version "13.1.7"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.1.7.tgz#db51d28b8dfacfe4fb2d0da88f5eb0a2eca00675"
|
||||
|
||||
"@types/stack-utils@^1.0.1":
|
||||
version "1.0.1"
|
||||
@ -3141,8 +3141,8 @@ type-check@~0.3.2:
|
||||
prelude-ls "~1.1.2"
|
||||
|
||||
typescript@^3.7.4:
|
||||
version "3.7.4"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.4.tgz#1743a5ec5fef6a1fa9f3e4708e33c81c73876c19"
|
||||
version "3.7.5"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.5.tgz#0692e21f65fd4108b9330238aac11dd2e177a1ae"
|
||||
|
||||
uglify-js@^3.1.4:
|
||||
version "3.6.8"
|
||||
|
Loading…
Reference in New Issue
Block a user