From 2ec414d8d6ec1a2ba3f47cbaec37cbfa150f8457 Mon Sep 17 00:00:00 2001 From: James Ives Date: Sun, 10 May 2020 13:34:14 -0400 Subject: [PATCH] Fixes error handling and details in the readme. --- .github/ISSUE_TEMPLATE/BUG_REPORT.md | 2 +- .github/ISSUE_TEMPLATE/SUPPORT.md | 2 +- README.md | 10 +++++----- __tests__/git.test.ts | 25 ++++++++++++++++++++++--- __tests__/util.test.ts | 2 +- src/util.ts | 5 +++-- 6 files changed, 33 insertions(+), 13 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.md b/.github/ISSUE_TEMPLATE/BUG_REPORT.md index 8274238e..253703db 100644 --- a/.github/ISSUE_TEMPLATE/BUG_REPORT.md +++ b/.github/ISSUE_TEMPLATE/BUG_REPORT.md @@ -13,7 +13,7 @@ labels: **Logs** - + **Additional Comments** diff --git a/.github/ISSUE_TEMPLATE/SUPPORT.md b/.github/ISSUE_TEMPLATE/SUPPORT.md index 4fdea1ab..1af0b92a 100644 --- a/.github/ISSUE_TEMPLATE/SUPPORT.md +++ b/.github/ISSUE_TEMPLATE/SUPPORT.md @@ -10,7 +10,7 @@ labels: **Logs** - + **Additional Comments** diff --git a/README.md b/README.md index 0d6007aa..1dd771ca 100644 --- a/README.md +++ b/README.md @@ -115,17 +115,17 @@ For more information regarding the [action interface please click here](https:// ## 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/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets). +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 repository's `Settings/Secrets` menu. You can learn more about setting environment variables with GitHub actions [here](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets). #### Required Setup One of the following deployment options must be configured. | Key | Value Information | Type | Required | -| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- | -------- | +| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- | ---------------- | -------- | +| `GITHUB_TOKEN` | In order for GitHub to trigger the rebuild of your page you must provide the action with the repository's provided GitHub token. This can be referenced in the workflow `yml` file by using `${{ secrets.GITHUB_TOKEN }}`. If you experience any issues with your changes not being reflected after the deployment it may be neccersary to use either the `SSH` or `ACCESS_TOKEN` options. | `secrets / with` | **Yes** | | `SSH` | You can configure the action to deploy using SSH by setting this option to `true`. For 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** | +| `ACCESS_TOKEN` | Depending on the repository's 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** | In addition to the deployment options you must also configure the following. @@ -161,7 +161,7 @@ If you'd prefer to use an SSH deploy key as opposed to a token you must first ge 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`. +Once you've generated the key pair you must add the contents of the public key within your repository's [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. There are several SSH actions available on the [GitHub marketplace](https://github.com/marketplace?type=actions) for you to choose from. diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index dbfa8f58..5104cdd8 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -89,9 +89,28 @@ describe('git', () => { name: 'asd', email: 'as@cat' }, - gitHubToken: null, - accessToken: null, - ssh: null + }) + + try { + await init(action) + } catch (e) { + expect(execute).toBeCalledTimes(0) + expect(e.message).toMatch( + 'There was an error initializing the repository: 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. ❌' + ) + } + }) + + it('should fail if access token is defined but it is an empty string', async () => { + Object.assign(action, { + repositoryPath: null, + folder: 'build', + branch: 'branch', + pusher: { + name: 'asd', + email: 'as@cat' + }, + accessToken: '', }) try { diff --git a/__tests__/util.test.ts b/__tests__/util.test.ts index 5a9a490c..59986100 100644 --- a/__tests__/util.test.ts +++ b/__tests__/util.test.ts @@ -73,7 +73,7 @@ describe('util', () => { accessToken: null, ssh: null } - expect(generateTokenType(action)).toEqual('...') + expect(generateTokenType(action)).toEqual('…') }) }) diff --git a/src/util.ts b/src/util.ts index 7c2e28bb..735f6f5a 100644 --- a/src/util.ts +++ b/src/util.ts @@ -13,7 +13,7 @@ export const generateTokenType = (action: ActionInterface): string => ? 'Access Token' : action.gitHubToken ? 'GitHub Token' - : '...' + : '…' /* Generates a the repository path used to make the commits. */ export const generateRepositoryPath = (action: ActionInterface): string => @@ -29,7 +29,8 @@ export const hasRequiredParameters = (action: ActionInterface): void => { (isNullOrUndefined(action.accessToken) && isNullOrUndefined(action.gitHubToken) && isNullOrUndefined(action.ssh)) || - isNullOrUndefined(action.repositoryPath) + isNullOrUndefined(action.repositoryPath) || + (action.accessToken && action.accessToken === '') ) { throw new 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.'