Skip to content

Commit

Permalink
Set default branch to gh-pages (fix #1151) (#1155)
Browse files Browse the repository at this point in the history
* Set default branch to gh-pages (fix #1151)

* Fix documented requirement of branch
  • Loading branch information
nickserv authored Jun 26, 2022
1 parent f7f029d commit c0e8d73
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 28 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
git-config-email: montezuma@jamesiv.es
repository-name: MontezumaIves/lab
token: ${{ secrets.ACCESS_TOKEN }}
branch: gh-pages
folder: integration
single-commit: true
clean: true
Expand All @@ -52,7 +51,6 @@ jobs:
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
token: ${{ secrets.ACCESS_TOKEN }}
branch: gh-pages
folder: integration
target-folder: cat/montezuma
git-config-name: Montezuma
Expand All @@ -63,7 +61,6 @@ jobs:
uses: dawidd6/action-delete-branch@v3.1.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branches: gh-pages

# Deploys using checkout@v2 with a GITHUB_TOKEN.
integration-checkout-v2:
Expand All @@ -78,7 +75,6 @@ jobs:
- name: Build and Deploy
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
branch: gh-pages
folder: integration
target-folder: cat/montezuma2
silent: true
Expand All @@ -87,7 +83,6 @@ jobs:
uses: dawidd6/action-delete-branch@v3.1.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branches: gh-pages

# Deploys using a container that requires you to install rsync.
integration-container:
Expand All @@ -110,7 +105,6 @@ jobs:
- name: Build and Deploy
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
branch: gh-pages
folder: integration
target-folder: cat/montezuma2
silent: true
Expand All @@ -135,7 +129,6 @@ jobs:
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
ssh-key: ${{ secrets.DEPLOY_KEY }}
branch: gh-pages
folder: integration
target-folder: cat/montezuma3
silent: true
Expand Down Expand Up @@ -165,7 +158,6 @@ jobs:
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
ssh-key: true
branch: gh-pages
folder: integration
target-folder: cat/montezuma4
silent: true
Expand All @@ -174,7 +166,6 @@ jobs:
uses: dawidd6/action-delete-branch@v3.1.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branches: gh-pages

# Deploys using a custom env. (Includes subsequent commit)
integration-env:
Expand All @@ -194,7 +185,6 @@ jobs:
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
ssh-key: ${{ secrets.DEPLOY_KEY }}
branch: gh-pages
folder: integration
target-folder: cat/montezuma4
silent: true
Expand All @@ -203,7 +193,6 @@ jobs:
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
ssh-key: ${{ secrets.DEPLOY_KEY }}
branch: gh-pages
folder: integration
target-folder: cat/subsequent
silent: true
Expand Down Expand Up @@ -236,7 +225,6 @@ jobs:
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
token: ${{ secrets.ACCESS_TOKEN }}
branch: gh-pages
folder: integration
clean: true
silent: true
Expand Down
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ You can view an example of this below.
```yml
name: Build and Deploy
on: [push]
permissions:
permissions:
contents: write
jobs:
build-and-deploy:
Expand All @@ -77,7 +77,6 @@ jobs:
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
branch: gh-pages # The branch the action should deploy to.
folder: build # The folder the action should deploy.
```
Expand All @@ -97,7 +96,7 @@ It's recommended that you use [Dependabot](https://docs.github.com/en/code-secur
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.

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

Expand Down Expand Up @@ -126,7 +125,6 @@ import run from '@jamesives/github-pages-deploy-action'

run({
token: process.env['ACCESS_TOKEN'],
branch: 'gh-pages',
folder: 'build',
repositoryName: 'JamesIves/github-pages-deploy-action',
silent: true,
Expand All @@ -146,7 +144,6 @@ The following options must be configured in order to make a deployment.

| 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. 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 more customization you can modify the deployment type using the following options.
Expand All @@ -160,6 +157,7 @@ By default, the action does not need any token configuration and uses the provid

| Key | Value Information | Type | Required |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| `branch` | This is the branch you wish to deploy to, for example, `gh-pages` or `docs`. | `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. You can include `<>` for the value if you wish to omit this field altogether and push the commits without an 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 a PAT in the `token` input for this configuration option to work properly. | `with` | **No** |
Expand Down Expand Up @@ -205,7 +203,6 @@ With this configured, you can then set the `ssh-key` part of the action to your
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
branch: gh-pages
folder: site
ssh-key: ${{ secrets.DEPLOY_KEY }}
```
Expand Down Expand Up @@ -235,7 +232,6 @@ jobs:
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
branch: gh-pages
folder: build
clean: true
clean-exclude: |
Expand Down Expand Up @@ -269,7 +265,7 @@ If you're using an operating system such as [Windows](https://www.microsoft.com/
```yml
name: Build and Deploy
on: [push]
permissions:
permissions:
contents: write
jobs:
build:
Expand Down Expand Up @@ -305,7 +301,6 @@ jobs:
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
branch: gh-pages
folder: 'site' # The deployment folder should match the name of the artifact. Even though our project builds into the 'build' folder the artifact name of 'site' must be placed here.
```

Expand Down Expand Up @@ -338,7 +333,7 @@ If you're using a custom domain and require a `CNAME` file, or if you require th

```yml
name: Build and Deploy
permissions:
permissions:
contents: write
on:
push:
Expand All @@ -360,7 +355,6 @@ jobs:
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
branch: gh-pages
folder: build
clean: true
clean-exclude: |
Expand Down
3 changes: 2 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ inputs:

branch:
description: 'This is the branch you wish to deploy to, for example gh-pages or docs.'
required: true
required: false
default: gh-pages

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.'
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface ActionInterface {
/** The minimum required values to run the action as a node module. */
export interface NodeActionInterface {
/** The branch that the action should deploy to. */
branch: string
branch?: string
/** The folder to deploy. */
folder: string
/** The repository path, for example JamesIves/github-pages-deploy-action. */
Expand Down
9 changes: 7 additions & 2 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
extractErrorMessage,
generateFolderPath,
generateRepositoryPath,
generateTokenType
generateTokenType,
isNullOrUndefined
} from './util'

/** Initializes and runs the action.
Expand Down Expand Up @@ -50,7 +51,11 @@ export default async function run(
info('Checking configuration and starting deployment… 🚦')

const settings: ActionInterface = {
...configuration
...configuration,
// Set the default branch for Node configurations
branch: !isNullOrUndefined(configuration.branch)
? configuration.branch
: 'gh-pages'
}

// Defines the repository/folder paths and token types.
Expand Down
4 changes: 3 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const replaceAll = (input: string, find: string, replace: string): string =>

/* 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): boolean =>
export const isNullOrUndefined = (
value: unknown
): value is undefined | null | '' =>
typeof value === 'undefined' || value === null || value === ''

/* Generates a token type used for the action. */
Expand Down

0 comments on commit c0e8d73

Please sign in to comment.