Skip to content

Commit

Permalink
Merge branch 'dev' into releases/v4
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesIves committed Oct 13, 2022
2 parents 13046b6 + b3205d4 commit 432c473
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
yarn test
- name: Uploade CodeCov Report
uses: codecov/[email protected].0
uses: codecov/[email protected].1
with:
token: ${{ secrets.CODECOV_TOKEN }}

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
git-config-email: [email protected]
repository-name: MontezumaIves/lab
token: ${{ secrets.ACCESS_TOKEN }}
commit-message: 'Test commit'
folder: integration
single-commit: true
clean: true
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/sponsors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
file: 'README.md'
template: '<a href="https://github.com/{{{ login }}}"><img src="https://github.com/{{{ login }}}.png" width="50px" alt="{{{ login }}}" /></a>&nbsp;&nbsp;'
maximum: 9999
organization: true

- name: Generate Sponsors 💖
uses: JamesIves/github-sponsors-readme-action@v1
Expand All @@ -28,7 +27,6 @@ jobs:
minimum: 10000
template: '<a href="https://github.com/{{{ login }}}"><img src="https://github.com/{{{ login }}}.png" width="80px" alt="{{{ login }}}" /></a>&nbsp;&nbsp;'
marker: 'premium'
organization: true

- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
Expand Down
45 changes: 3 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</p>

<p align="center">
<!-- premium --><a href="https://github.com/github"><img src="https://github.com/github.png" width="80px" alt="github" /></a>&nbsp;&nbsp;<!-- premium -->
<!-- premium --><!-- premium -->
</p>

<p align="center">
Expand Down Expand Up @@ -89,52 +89,14 @@ on:
- main
```

It's recommended that you use [Dependabot](https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically) to keep your workflow up-to-date and [secure](https://github.com/features/security). You can find the latest tagged version on the [GitHub Marketplace](https://github.com/marketplace/actions/deploy-to-github-pages) or on the [releases page](https://github.com/JamesIves/github-pages-deploy-action/releases).

#### Permission Settings ⚠️

If you do not supply the action with an access token or an SSH key, you must access your repositories settings and provide `Read and Write Permissions` to the provided `GITHUB_TOKEN`, otherwise you'll potentailly run into permission issues. Alternatively you can set the following in your workflow file to grant the action the permissions it needs.
> **Warning**
> If you do not supply the action with an access token or an SSH key, you must access your repositories settings and provide `Read and Write Permissions` to the provided `GITHUB_TOKEN`, otherwise you'll potentially run into permission issues. Alternatively you can set the following in your workflow file to grant the action the permissions it needs.

```yml
permissions:
contents: write
```

#### Install as a Node Module 📦

If you'd like to use the functionality provided by this action in your own action you can either [create a composite action](https://docs.github.com/en/actions/creating-actions/creating-a-composite-action), or you can install it using [yarn](https://yarnpkg.com/) or [npm](https://www.npmjs.com/get-npm) by running the following commands. It's available on both the [npm](https://www.npmjs.com/package/@jamesives/github-pages-deploy-action) and [GitHub registry](https://github.com/JamesIves/github-pages-deploy-action/packages/229985).

```
yarn add @jamesives/github-pages-deploy-action
```
```
npm install @jamesives/github-pages-deploy-action
```
It can then be imported into your project like so.
```javascript
import run from '@jamesives/github-pages-deploy-action'
```

Calling the functions directly will require you to pass in an object containing the variables found in the configuration section, you'll also need to provide a `workspace` with a path to your project.

```javascript
import run from '@jamesives/github-pages-deploy-action'

run({
token: process.env['ACCESS_TOKEN'],
folder: 'build',
repositoryName: 'JamesIves/github-pages-deploy-action',
silent: true,
workspace: 'src/project/location',
tag: 'v0.1'
})
```

For more information regarding the [action interface please click here](https://github.com/JamesIves/github-pages-deploy-action/blob/dev/src/constants.ts#L7).

## 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 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).
Expand Down Expand Up @@ -170,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
10 changes: 3 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'Deploy to GitHub Pages'
description: 'This action will handle the deployment process of your project to GitHub Pages.'
author: 'James Ives <[email protected]>'
runs:
using: 'node12'
using: 'node16'
main: 'lib/main.js'
branding:
icon: 'git-commit'
Expand All @@ -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
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@jamesives/github-pages-deploy-action",
"description": "GitHub action for building a project and deploying it to GitHub pages.",
"author": "James Ives <[email protected]> (https://jamesiv.es)",
"version": "4.3.4",
"version": "4.4.0",
"license": "MIT",
"main": "lib/lib.js",
"types": "lib/lib.d.ts",
Expand Down Expand Up @@ -35,25 +35,25 @@
"deployment"
],
"dependencies": {
"@actions/core": "1.9.0",
"@actions/core": "1.10.0",
"@actions/exec": "1.1.1",
"@actions/github": "5.0.3",
"@actions/github": "5.1.1",
"@actions/io": "1.1.2"
},
"devDependencies": {
"@types/jest": "27.5.0",
"@types/node": "18.0.6",
"@types/node": "18.8.0",
"@typescript-eslint/eslint-plugin": "4.33.0",
"@typescript-eslint/parser": "4.33.0",
"eslint": "7.32.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-jest": "26.5.3",
"eslint-plugin-jest": "27.0.4",
"eslint-plugin-prettier": "4.2.1",
"jest": "26.6.3",
"jest-circus": "27.5.1",
"prettier": "2.7.1",
"rimraf": "3.0.2",
"ts-jest": "26.5.6",
"typescript": "4.7.4"
"typescript": "4.8.4"
}
}
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 432c473

Please sign in to comment.