Skip to content

Commit

Permalink
docs: Updated docs to remove workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesIves committed Aug 17, 2022
1 parent b7b8bb2 commit 09a5452
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 21 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -132,7 +132,6 @@ By default, the action does not need any token configuration and uses the provid
| `single-commit` | This option can be toggled to `true` if you'd prefer to have a single commit on the deployment branch instead of maintaining the full history. **Using this option will also cause any existing history to be wiped from the deployment branch**. | `with` | **No** |
| `force` | Force-push new deployments to overwrite the previous version; otherwise, attempt to rebase new deployments onto any existing ones. This option is turned on by default and can be toggled off by setting it to `false`, which may be useful if there are multiple deployments in a single branch. | `with` | **No** |
| `silent` | Silences the action output preventing it from displaying git messages. | `with` | **No** |
| `workspace` | This should point to where your project lives on the virtual machine. The GitHub Actions environment will set this for you. It is only necessary to set this variable if you're using the node module. | `with` | **No** |
| `tag` | Add a tag to the commit. Only works when `dry-run` is not used. | `with` | **No** |

With the action correctly configured you should see the workflow trigger the deployment under the configured conditions.
Expand Down
8 changes: 2 additions & 6 deletions action.yml
Expand Up @@ -24,7 +24,7 @@ inputs:
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 recommend using a service account with the least permissions neccersary
We recommend using a service account with the least permissions necessary
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)
Expand Down Expand Up @@ -58,7 +58,7 @@ inputs:
required: false

dry-run:
description: 'Do not actually push back, but use `--dry-run` on `git push` invocations insead.'
description: 'Do not actually push back, but use `--dry-run` on `git push` invocations instead.'
required: false

force:
Expand All @@ -78,10 +78,6 @@ inputs:
description: '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'
required: false

workspace:
description: "This should point to where your project lives on the virtual machine. The GitHub Actions environment will set this for you. It is only neccersary to set this variable if you're using the node module."
required: false

tag:
description: "Add a tag to the commit, this can be used like so: 'v0.1'. Only works when 'dry-run' is not used."
required: false
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Expand Up @@ -42,7 +42,7 @@ export interface ActionInterface {
name?: string
/** The repository path, for example JamesIves/github-pages-deploy-action. */
repositoryName?: string
/** The fully qualified repositpory path, this gets auto generated if repositoryName is provided. */
/** The fully qualified repository path, this gets auto generated if repositoryName is provided. */
repositoryPath?: string
/** Wipes the commit history from the deployment branch in favor of a single commit. */
singleCommit?: boolean | null
Expand Down
8 changes: 6 additions & 2 deletions src/git.ts
Expand Up @@ -15,7 +15,9 @@ import {
suppressSensitiveInformation
} from './util'

/* Initializes git in the workspace. */
/**
* Initializes git in the workspace.
*/
export async function init(action: ActionInterface): Promise<void | Error> {
try {
info(`Deploying using ${action.tokenType}… 🔑`)
Expand Down Expand Up @@ -96,7 +98,9 @@ export async function init(action: ActionInterface): Promise<void | Error> {
}
}

/* Runs the necessary steps to make the deployment. */
/**
* Runs the necessary steps to make the deployment.
*/
export async function deploy(action: ActionInterface): Promise<Status> {
const temporaryDeploymentDirectory =
'github-pages-deploy-action-temp-deployment-folder'
Expand Down
3 changes: 3 additions & 0 deletions src/ssh.ts
Expand Up @@ -5,6 +5,9 @@ import {appendFileSync} from 'fs'
import {ActionInterface} from './constants'
import {extractErrorMessage, suppressSensitiveInformation} from './util'

/**
* Configures SSH for the workflow.
*/
export async function configureSSH(action: ActionInterface): Promise<void> {
try {
if (typeof action.sshKey === 'string') {
Expand Down
41 changes: 31 additions & 10 deletions src/util.ts
Expand Up @@ -8,30 +8,40 @@ import {
SupportedOperatingSystems
} from './constants'

/* Replaces all instances of a match in a string. */
/**
* Replaces all instances of a match in a string.
*/
const replaceAll = (input: string, find: string, replace: string): string =>
input.split(find).join(replace)

/* Utility function that checks to see if a value is undefined or not.
If allowEmptyString is passed the parameter is allowed to contain an empty string as a valid parameter. */
/**
* Utility function that checks to see if a value is undefined or not.
* If allowEmptyString is passed the parameter is allowed to contain an empty string as a valid parameter.
*/
export const isNullOrUndefined = (
value: unknown
): value is undefined | null | '' =>
typeof value === 'undefined' || value === null || value === ''

/* Generates a token type used for the action. */
/**
* Generates a token type used for the action.
*/
export const generateTokenType = (action: ActionInterface): string =>
action.sshKey ? 'SSH Deploy Key' : action.token ? 'Deploy 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 =>
action.sshKey
? `git@${action.hostname}:${action.repositoryName}`
: `https://${`x-access-token:${action.token}`}@${action.hostname}/${
action.repositoryName
}.git`

/* Genetate absolute folder path by the provided folder name */
/**
* Generate absolute folder path by the provided folder name
*/
export const generateFolderPath = (action: ActionInterface): string => {
const folderName = action['folder']
return path.isAbsolute(folderName)
Expand All @@ -41,7 +51,9 @@ export const generateFolderPath = (action: ActionInterface): string => {
: path.join(action.workspace, folderName)
}

/* Checks for the required tokens and formatting. Throws an error if any case is matched. */
/**
* Checks for the required tokens and formatting. Throws an error if any case is matched.
*/
const hasRequiredParameters = <K extends keyof RequiredActionParameters>(
action: ActionInterface,
params: K[]
Expand All @@ -53,7 +65,9 @@ const hasRequiredParameters = <K extends keyof RequiredActionParameters>(
return Boolean(nonNullParams.length)
}

/* 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 => {
if (!hasRequiredParameters(action, ['token', 'sshKey'])) {
throw new Error(
Expand Down Expand Up @@ -86,7 +100,9 @@ export const checkParameters = (action: ActionInterface): void => {
}
}

/* Suppresses sensitive information from being exposed in error messages. */
/**
* Suppresses sensitive information from being exposed in error messages.
*/
export const suppressSensitiveInformation = (
str: string,
action: ActionInterface
Expand All @@ -109,13 +125,18 @@ export const suppressSensitiveInformation = (
return value
}

/**
* Extracts message from an error object.
*/
export const extractErrorMessage = (error: unknown): string =>
error instanceof Error
? error.message
: typeof error == 'string'
? error
: JSON.stringify(error)

/** Strips the protocol from a provided URL. */
/**
* Strips the protocol from a provided URL.
*/
export const stripProtocolFromUrl = (url: string): string =>
url.replace(/^(?:https?:\/\/)?(?:www\.)?/i, '').split('/')[0]
4 changes: 3 additions & 1 deletion src/worktree.ts
Expand Up @@ -21,7 +21,9 @@ export class GitCheckout {
}
}

/* Generate the worktree and set initial content if it exists */
/**
* Generate the worktree and set initial content if it exists
*/
export async function generateWorktree(
action: ActionInterface,
worktreedir: string,
Expand Down

0 comments on commit 09a5452

Please sign in to comment.