Simplifies Token Setup (#530)

* Token simplification

* Access Token / Github Token -> Token

* Oops

* Typos

* Update README.md

* Update README.md

* Update action.yml

Co-authored-by: Axel Hecht <axel@pike.org>

* Update README.md

Co-authored-by: Axel Hecht <axel@pike.org>

* Update README.md

Co-authored-by: Axel Hecht <axel@pike.org>
This commit is contained in:
James Ives 2020-12-10 11:49:37 -05:00 committed by GitHub
parent 951989533a
commit 7a94841600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 125 deletions

View File

@ -64,10 +64,8 @@ jobs:
- name: Deploy 🚀 - name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@3.7.1 uses: JamesIves/github-pages-deploy-action@3.7.1
with: with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages # The branch the action should deploy to. BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: build # The folder the action should deploy. FOLDER: build # The folder the action should deploy.
CLEAN: true # Automatically remove deleted files from the deploy branch
``` ```
If you'd like to make it so the workflow only triggers on push events to specific branches then you can modify the `on` section. If you'd like to make it so the workflow only triggers on push events to specific branches then you can modify the `on` section.
@ -105,7 +103,7 @@ Calling the functions directly will require you to pass in an object containing
import run from "github-pages-deploy-action"; import run from "github-pages-deploy-action";
run({ run({
accessToken: process.env["ACCESS_TOKEN"], token: process.env["ACCESS_TOKEN"],
branch: "gh-pages", branch: "gh-pages",
folder: "build", folder: "build",
repositoryName: "JamesIves/github-pages-deploy-action", repositoryName: "JamesIves/github-pages-deploy-action",
@ -122,28 +120,27 @@ The `with` portion of the workflow **must** be configured before the action will
#### Required Setup #### Required Setup
One of the following deployment options must be configured. The following options must be configured in order to make a deployment.
| 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'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.
| Key | Value Information | Type | Required | | Key | Value Information | Type | Required |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- | | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| `BRANCH` | This is the branch you wish to deploy to, for example `gh-pages` or `docs`. | `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. If you wish to deploy the root directory you can place a `.` here. You can also utilize absolute file paths by appending `~` to your folder path. | `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. If you wish to deploy the root directory you can place a `.` here. You can also utilize absolute file paths by appending `~` to your folder path. | `with` | **Yes** |
By default the action does not need any token configuration and uses the provided repository scoped GitHub token to make the deployment. If you require most customization you can modify the deployment type using the following options.
| Key | Value Information | Type | Required |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- | -------- |
| `TOKEN` | This option defaults to the repository scoped GitHub Token. However if you need more permissions for things such as deploying to another repository, you can add a Personal Access Token (PAT) here. This should be stored in the `secrets / with` menu **as a secret**. We reccomend using a service account with the least permissions neccersary and recommend when generating a new PAT that you select the least permission scopes neccersary. [Learn more about creating and using encrypted secrets here.](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets) | **No** |
| `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` | **No** |
#### Optional Choices #### Optional Choices
| Key | Value Information | Type | Required | | Key | Value Information | Type | Required |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- | | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| `GIT_CONFIG_NAME` | Allows you to customize the name that is attached to the git config which is used when pushing the deployment commits. If this is not included it will use the name in the GitHub context, followed by the name of the action. | `with` | **No** | | `GIT_CONFIG_NAME` | Allows you to customize the name that is attached to the git config which is used when pushing the deployment commits. If this is not included it will use the name in the GitHub context, followed by the name of the action. | `with` | **No** |
| `GIT_CONFIG_EMAIL` | Allows you to customize the email that is attached to the git config which is used when pushing the deployment commits. If this is not included it will use the email in the GitHub context, followed by a generic noreply GitHub email. | `with` | **No** | | `GIT_CONFIG_EMAIL` | Allows you to customize the email that is attached to the git config which is used when pushing the deployment commits. If this is not included it will use the email in the GitHub context, followed by a generic noreply GitHub email. | `with` | **No** |
| `REPOSITORY_NAME` | Allows you to specify a different repository path so long as you have permissions to push to it. This should be formatted like so: `JamesIves/github-pages-deploy-action`. You'll need to use an `ACCESS_TOKEN` for this configuration option to work properly. | `with` | **No** | | `REPOSITORY_NAME` | Allows you to specify a different repository path so long as you have permissions to push to it. This should be formatted like so: `JamesIves/github-pages-deploy-action`. You'll need to use a PAT in the `TOKEN` input for this configuration option to work properly. | `with` | **No** |
| `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** | | `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** |
| `COMMIT_MESSAGE` | If you need to customize the commit message for an integration you can do so. | `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 is turned on by default, and can be toggled off by setting it to `false`. | `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 is turned on by default, and can be toggled off by setting it to `false`. | `with` | **No** |

View File

@ -43,7 +43,7 @@ describe('git', () => {
Object.assign(action, { Object.assign(action, {
silent: false, silent: false,
repositoryPath: 'JamesIves/github-pages-deploy-action', repositoryPath: 'JamesIves/github-pages-deploy-action',
accessToken: '123', token: '123',
branch: 'branch', branch: 'branch',
folder: '.', folder: '.',
isTest: true, isTest: true,
@ -67,7 +67,7 @@ describe('git', () => {
it('should execute five commands', async () => { it('should execute five commands', async () => {
Object.assign(action, { Object.assign(action, {
silent: false, silent: false,
accessToken: '123', token: '123',
branch: 'branch', branch: 'branch',
folder: '.', folder: '.',
pusher: { pusher: {
@ -87,7 +87,7 @@ describe('git', () => {
Object.assign(action, { Object.assign(action, {
silent: false, silent: false,
accessToken: '123', token: '123',
branch: 'branch', branch: 'branch',
folder: '.', folder: '.',
pusher: { pusher: {
@ -112,7 +112,7 @@ describe('git', () => {
silent: false, silent: false,
folder: 'assets', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', token: '123',
pusher: { pusher: {
name: 'asd', name: 'asd',
email: 'as@cat' email: 'as@cat'
@ -139,7 +139,7 @@ describe('git', () => {
dryRun: true, dryRun: true,
folder: 'assets', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', token: '123',
pusher: { pusher: {
name: 'asd', name: 'asd',
email: 'as@cat' email: 'as@cat'
@ -166,7 +166,7 @@ describe('git', () => {
folder: 'other', folder: 'other',
folderPath: 'other', folderPath: 'other',
branch: 'branch', branch: 'branch',
gitHubToken: '123', token: '123',
singleCommit: true, singleCommit: true,
pusher: { pusher: {
name: 'asd', name: 'asd',
@ -188,7 +188,7 @@ describe('git', () => {
folder: 'assets', folder: 'assets',
folderPath: 'assets', folderPath: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', token: '123',
pusher: { pusher: {
name: 'asd', name: 'asd',
email: 'as@cat' email: 'as@cat'
@ -214,7 +214,7 @@ describe('git', () => {
folder: 'other', folder: 'other',
folderPath: 'other', folderPath: 'other',
branch: 'branch', branch: 'branch',
gitHubToken: '123', token: '123',
pusher: { pusher: {
name: 'asd', name: 'asd',
email: 'as@cat' email: 'as@cat'
@ -237,7 +237,7 @@ describe('git', () => {
folder: 'assets', folder: 'assets',
folderPath: 'assets', folderPath: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', token: '123',
pusher: { pusher: {
name: 'asd', name: 'asd',
email: 'as@cat' email: 'as@cat'
@ -258,7 +258,7 @@ describe('git', () => {
silent: false, silent: false,
folder: '.', folder: '.',
branch: 'branch', branch: 'branch',
gitHubToken: '123', token: '123',
pusher: {}, pusher: {},
clean: true, clean: true,
targetFolder: 'new_folder', targetFolder: 'new_folder',
@ -279,7 +279,7 @@ describe('git', () => {
silent: false, silent: false,
folder: 'assets', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', token: '123',
pusher: { pusher: {
name: 'asd', name: 'asd',
email: 'as@cat' email: 'as@cat'
@ -302,7 +302,7 @@ describe('git', () => {
silent: false, silent: false,
folder: 'assets', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', token: '123',
pusher: { pusher: {
name: 'asd', name: 'asd',
email: 'as@cat' email: 'as@cat'

View File

@ -39,7 +39,7 @@ describe('main', () => {
repositoryPath: 'JamesIves/github-pages-deploy-action', repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: 'assets', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', token: '123',
pusher: { pusher: {
name: 'asd', name: 'asd',
email: 'as@cat' email: 'as@cat'
@ -58,7 +58,7 @@ describe('main', () => {
repositoryPath: 'JamesIves/github-pages-deploy-action', repositoryPath: 'JamesIves/github-pages-deploy-action',
folder: 'assets', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: '123', token: '123',
pusher: { pusher: {
name: 'asd', name: 'asd',
email: 'as@cat' email: 'as@cat'
@ -74,9 +74,8 @@ describe('main', () => {
Object.assign(action, { Object.assign(action, {
folder: 'assets', folder: 'assets',
branch: 'branch', branch: 'branch',
gitHubToken: null, token: null,
ssh: null, ssh: null,
accessToken: null,
pusher: { pusher: {
name: 'asd', name: 'asd',
email: 'as@cat' email: 'as@cat'

View File

@ -37,38 +37,23 @@ describe('util', () => {
branch: '123', branch: '123',
workspace: 'src/', workspace: 'src/',
folder: 'build', folder: 'build',
gitHubToken: null, token: null,
accessToken: null,
ssh: true, ssh: true,
silent: false silent: false
} }
expect(generateTokenType(action)).toEqual('SSH Deploy Key') expect(generateTokenType(action)).toEqual('SSH Deploy Key')
}) })
it('should return access token if access token is provided', async () => { it('should return deploy token if token is provided', async () => {
const action = { const action = {
branch: '123', branch: '123',
workspace: 'src/', workspace: 'src/',
folder: 'build', folder: 'build',
gitHubToken: null, token: '123',
accessToken: '123',
ssh: null, ssh: null,
silent: false silent: false
} }
expect(generateTokenType(action)).toEqual('Access Token') expect(generateTokenType(action)).toEqual('Deploy Token')
})
it('should return github token if github token is provided', async () => {
const action = {
branch: '123',
workspace: 'src/',
folder: 'build',
gitHubToken: '123',
accessToken: null,
ssh: null,
silent: false
}
expect(generateTokenType(action)).toEqual('GitHub Token')
}) })
it('should return ... if no token is provided', async () => { it('should return ... if no token is provided', async () => {
@ -76,8 +61,7 @@ describe('util', () => {
branch: '123', branch: '123',
workspace: 'src/', workspace: 'src/',
folder: 'build', folder: 'build',
gitHubToken: null, token: null,
accessToken: null,
ssh: null, ssh: null,
silent: false silent: false
} }
@ -92,8 +76,7 @@ describe('util', () => {
branch: '123', branch: '123',
workspace: 'src/', workspace: 'src/',
folder: 'build', folder: 'build',
gitHubToken: null, token: null,
accessToken: null,
ssh: true, ssh: true,
silent: false silent: false
} }
@ -102,30 +85,13 @@ describe('util', () => {
) )
}) })
it('should return https if access token is provided', async () => { it('should return https with x-access-token if deploy token is provided', async () => {
const action = { const action = {
repositoryName: 'JamesIves/github-pages-deploy-action', repositoryName: 'JamesIves/github-pages-deploy-action',
branch: '123', branch: '123',
workspace: 'src/', workspace: 'src/',
folder: 'build', folder: 'build',
gitHubToken: null, token: '123',
accessToken: '123',
ssh: null,
silent: false
}
expect(generateRepositoryPath(action)).toEqual(
'https://123@github.com/JamesIves/github-pages-deploy-action.git'
)
})
it('should return https with x-access-token if github token is provided', async () => {
const action = {
repositoryName: 'JamesIves/github-pages-deploy-action',
branch: '123',
workspace: 'src/',
folder: 'build',
gitHubToken: '123',
accessToken: null,
ssh: null, ssh: null,
silent: false silent: false
} }
@ -143,14 +109,13 @@ describe('util', () => {
branch: '123', branch: '123',
workspace: 'src/', workspace: 'src/',
folder: 'build', folder: 'build',
accessToken: 'supersecret999%%%', token: 'anothersecret123333',
gitHubToken: 'anothersecret123333',
silent: false silent: false
} }
const string = `This is an error message! It contains ${action.accessToken} and ${action.gitHubToken} and ${action.repositoryPath} and ${action.accessToken} again!` const string = `This is an error message! It contains ${action.token} and ${action.repositoryPath} and ${action.token} again!`
expect(suppressSensitiveInformation(string, action)).toBe( expect(suppressSensitiveInformation(string, action)).toBe(
'This is an error message! It contains *** and *** and *** and *** again!' 'This is an error message! It contains *** and *** and *** again!'
) )
}) })
@ -162,16 +127,15 @@ describe('util', () => {
branch: '123', branch: '123',
workspace: 'src/', workspace: 'src/',
folder: 'build', folder: 'build',
accessToken: 'supersecret999%%%', token: 'anothersecret123333',
gitHubToken: 'anothersecret123333',
silent: false silent: false
} }
process.env['RUNNER_DEBUG'] = '1' process.env['RUNNER_DEBUG'] = '1'
const string = `This is an error message! It contains ${action.accessToken} and ${action.gitHubToken} and ${action.repositoryPath}` const string = `This is an error message! It contains ${action.token} and ${action.repositoryPath}`
expect(suppressSensitiveInformation(string, action)).toBe( expect(suppressSensitiveInformation(string, action)).toBe(
'This is an error message! It contains supersecret999%%% and anothersecret123333 and https://x-access-token:supersecret999%%%@github.com/anothersecret123333' 'This is an error message! It contains anothersecret123333 and https://x-access-token:supersecret999%%%@github.com/anothersecret123333'
) )
}) })
}) })
@ -183,8 +147,7 @@ describe('util', () => {
branch: '123', branch: '123',
workspace: 'src/', workspace: 'src/',
folder: 'build', folder: 'build',
gitHubToken: null, token: null,
accessToken: null,
ssh: null, ssh: null,
silent: false silent: false
} }
@ -196,8 +159,7 @@ describe('util', () => {
branch: '123', branch: '123',
workspace: 'src/', workspace: 'src/',
folder: '/home/user/repo/build', folder: '/home/user/repo/build',
gitHubToken: null, token: null,
accessToken: null,
ssh: null, ssh: null,
silent: false silent: false
} }
@ -209,8 +171,7 @@ describe('util', () => {
branch: '123', branch: '123',
workspace: 'src/', workspace: 'src/',
folder: './build', folder: './build',
gitHubToken: null, token: null,
accessToken: null,
ssh: null, ssh: null,
silent: false silent: false
} }
@ -222,8 +183,7 @@ describe('util', () => {
branch: '123', branch: '123',
workspace: 'src/', workspace: 'src/',
folder: '~/repo/build', folder: '~/repo/build',
gitHubToken: null, token: null,
accessToken: null,
ssh: null, ssh: null,
silent: false silent: false
} }
@ -251,11 +211,11 @@ describe('util', () => {
} }
}) })
it('should fail if access token is defined but it is an empty string', () => { it('should fail if token is defined but it is an empty string', () => {
const action = { const action = {
silent: false, silent: false,
repositoryPath: undefined, repositoryPath: undefined,
accessToken: '', token: '',
branch: 'branch', branch: 'branch',
folder: 'build', folder: 'build',
workspace: 'src/' workspace: 'src/'
@ -274,7 +234,7 @@ describe('util', () => {
const action = { const action = {
silent: false, silent: false,
repositoryPath: undefined, repositoryPath: undefined,
accessToken: '123', token: '123',
branch: '', branch: '',
folder: 'build', folder: 'build',
workspace: 'src/' workspace: 'src/'
@ -291,7 +251,7 @@ describe('util', () => {
const action = { const action = {
silent: false, silent: false,
repositoryPath: undefined, repositoryPath: undefined,
gitHubToken: '123', token: '123',
branch: 'branch', branch: 'branch',
folder: '', folder: '',
workspace: 'src/' workspace: 'src/'
@ -310,7 +270,7 @@ describe('util', () => {
const action: ActionInterface = { const action: ActionInterface = {
silent: false, silent: false,
repositoryPath: undefined, repositoryPath: undefined,
gitHubToken: '123', token: '123',
branch: 'branch', branch: 'branch',
folder: 'notARealFolder', folder: 'notARealFolder',
workspace: '.' workspace: '.'

View File

@ -12,13 +12,18 @@ inputs:
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.' 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 required: false
ACCESS_TOKEN: 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.' description: >
required: false This option defaults to the repository scoped GitHub Token.
However if you need more permissions for things such as deploying to another repository, you can add a Personal Access Token (PAT) here.
This should be stored in the `secrets / with` menu **as a secret**.
GITHUB_TOKEN: We recommend using a service account with the least permissions neccersary
description: 'In order for GitHub to trigger the rebuild of your page you must provide the action with the repositories provided GitHub token.' and when generating a new PAT that you select the least permission scopes required.
[Learn more about creating and using encrypted secrets here.](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
required: false required: false
default: ${{ github.token }}
BRANCH: BRANCH:
description: 'This is the branch you wish to deploy to, for example gh-pages or docs.' description: 'This is the branch you wish to deploy to, for example gh-pages or docs.'

View File

@ -6,8 +6,6 @@ const {pusher, repository} = github.context.payload
/* For more information please refer to the README: https://github.com/JamesIves/github-pages-deploy-action */ /* For more information please refer to the README: https://github.com/JamesIves/github-pages-deploy-action */
export interface ActionInterface { export interface ActionInterface {
/** Deployment access token. */
accessToken?: string | null
/** The branch that the action should deploy to. */ /** The branch that the action should deploy to. */
branch: string branch: string
/** git push with --dry-run */ /** git push with --dry-run */
@ -24,8 +22,6 @@ export interface ActionInterface {
folder: string folder: string
/** The auto generated folder path. */ /** The auto generated folder path. */
folderPath?: string folderPath?: string
/** GitHub deployment token. */
gitHubToken?: string | null
/** Determines if the action is running in test mode or not. */ /** Determines if the action is running in test mode or not. */
isTest?: boolean | null isTest?: boolean | null
/** The git config name. */ /** The git config name. */
@ -42,7 +38,9 @@ export interface ActionInterface {
ssh?: boolean | null ssh?: boolean | null
/** 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. */ /** 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. */
targetFolder?: string targetFolder?: string
/** The token type, ie ssh/github token/access token, this gets automatically generated. */ /** Deployment token. */
token?: string | null
/** The token type, ie ssh/token, this gets automatically generated. */
tokenType?: string tokenType?: string
/** The folder where your deployment project lives. */ /** The folder where your deployment project lives. */
workspace: string workspace: string
@ -50,16 +48,14 @@ export interface ActionInterface {
/** The minimum required values to run the action as a node module. */ /** The minimum required values to run the action as a node module. */
export interface NodeActionInterface { export interface NodeActionInterface {
/** Deployment access token. */
accessToken?: string | null
/** The branch that the action should deploy to. */ /** The branch that the action should deploy to. */
branch: string branch: string
/** The folder to deploy. */ /** The folder to deploy. */
folder: string folder: string
/** GitHub deployment token. */
gitHubToken?: string | null
/** The repository path, for example JamesIves/github-pages-deploy-action. */ /** The repository path, for example JamesIves/github-pages-deploy-action. */
repositoryName: string repositoryName: string
/** GitHub deployment token. */
token?: string | null
/** Determines if the action should run in silent mode or not. */ /** Determines if the action should run in silent mode or not. */
silent: boolean silent: boolean
/** Set to true if you're using an ssh client in your build step. */ /** Set to true if you're using an ssh client in your build step. */
@ -70,7 +66,6 @@ export interface NodeActionInterface {
/* Required action data that gets initialized when running within the GitHub Actions environment. */ /* Required action data that gets initialized when running within the GitHub Actions environment. */
export const action: ActionInterface = { export const action: ActionInterface = {
accessToken: getInput('ACCESS_TOKEN'),
folder: getInput('FOLDER'), folder: getInput('FOLDER'),
branch: getInput('BRANCH'), branch: getInput('BRANCH'),
commitMessage: getInput('COMMIT_MESSAGE'), commitMessage: getInput('COMMIT_MESSAGE'),
@ -91,7 +86,6 @@ export const action: ActionInterface = {
: `${ : `${
process.env.GITHUB_ACTOR || 'github-pages-deploy-action' process.env.GITHUB_ACTOR || 'github-pages-deploy-action'
}@users.noreply.github.com`, }@users.noreply.github.com`,
gitHubToken: getInput('GITHUB_TOKEN'),
name: !isNullOrUndefined(getInput('GIT_CONFIG_NAME')) name: !isNullOrUndefined(getInput('GIT_CONFIG_NAME'))
? getInput('GIT_CONFIG_NAME') ? getInput('GIT_CONFIG_NAME')
: pusher && pusher.name : pusher && pusher.name
@ -104,6 +98,7 @@ export const action: ActionInterface = {
: repository && repository.full_name : repository && repository.full_name
? repository.full_name ? repository.full_name
: process.env.GITHUB_REPOSITORY, : process.env.GITHUB_REPOSITORY,
token: getInput('TOKEN'),
singleCommit: !isNullOrUndefined(getInput('SINGLE_COMMIT')) singleCommit: !isNullOrUndefined(getInput('SINGLE_COMMIT'))
? getInput('SINGLE_COMMIT').toLowerCase() === 'true' ? getInput('SINGLE_COMMIT').toLowerCase() === 'true'
: false, : false,
@ -120,7 +115,7 @@ export const action: ActionInterface = {
/** Types for the required action parameters. */ /** Types for the required action parameters. */
export type RequiredActionParameters = Pick< export type RequiredActionParameters = Pick<
ActionInterface, ActionInterface,
'accessToken' | 'gitHubToken' | 'ssh' | 'branch' | 'folder' 'token' | 'ssh' | 'branch' | 'folder'
> >
/** Status codes for the action. */ /** Status codes for the action. */

View File

@ -13,21 +13,15 @@ export const isNullOrUndefined = (value: any): boolean =>
/* Generates a token type used for the action. */ /* Generates a token type used for the action. */
export const generateTokenType = (action: ActionInterface): string => export const generateTokenType = (action: ActionInterface): string =>
action.ssh action.ssh ? 'SSH Deploy Key' : action.token ? 'Deploy Token' : '…'
? 'SSH Deploy Key'
: action.accessToken
? 'Access Token'
: action.gitHubToken
? 'GitHub Token'
: '…'
/* Generates a the repository path used to make the commits. */ /* Generates a the repository path used to make the commits. */
export const generateRepositoryPath = (action: ActionInterface): string => export const generateRepositoryPath = (action: ActionInterface): string =>
action.ssh action.ssh
? `git@github.com:${action.repositoryName}` ? `git@github.com:${action.repositoryName}`
: `https://${ : `https://${`x-access-token:${action.token}`}@github.com/${
action.accessToken || `x-access-token:${action.gitHubToken}` action.repositoryName
}@github.com/${action.repositoryName}.git` }.git`
/* Genetate absolute folder path by the provided folder name */ /* Genetate absolute folder path by the provided folder name */
export const generateFolderPath = (action: ActionInterface): string => { export const generateFolderPath = (action: ActionInterface): string => {
@ -52,7 +46,7 @@ const hasRequiredParameters = <K extends keyof RequiredActionParameters>(
/* Verifies the action has the required parameters to run, otherwise throw an error. */ /* Verifies the action has the required parameters to run, otherwise throw an error. */
export const checkParameters = (action: ActionInterface): void => { export const checkParameters = (action: ActionInterface): void => {
if (!hasRequiredParameters(action, ['accessToken', 'gitHubToken', 'ssh'])) { if (!hasRequiredParameters(action, ['token', 'ssh'])) {
throw new Error( 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.' '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.'
) )
@ -85,11 +79,9 @@ export const suppressSensitiveInformation = (
return value return value
} }
const orderedByLength = ([ const orderedByLength = ([action.token, action.repositoryPath].filter(
action.accessToken, Boolean
action.gitHubToken, ) as string[]).sort((a, b) => b.length - a.length)
action.repositoryPath
].filter(Boolean) as string[]).sort((a, b) => b.length - a.length)
for (const find of orderedByLength) { for (const find of orderedByLength) {
value = replaceAll(value, find, '***') value = replaceAll(value, find, '***')