diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 434be135..fcf239e8 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -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 @@ -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 @@ -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: @@ -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 @@ -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: @@ -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 @@ -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 @@ -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 @@ -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: @@ -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 @@ -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 @@ -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 diff --git a/README.md b/README.md index fd146dae..63a3e97f 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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. ``` @@ -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 ``` @@ -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, @@ -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. @@ -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** | @@ -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 }} ``` @@ -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: | @@ -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: @@ -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. ``` @@ -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: @@ -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: | diff --git a/action.yml b/action.yml index 8f761b37..f508021d 100644 --- a/action.yml +++ b/action.yml @@ -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.' diff --git a/src/constants.ts b/src/constants.ts index 6505b778..e0ce8075 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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. */ diff --git a/src/lib.ts b/src/lib.ts index 7a8081ea..1a6ea0da 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -7,7 +7,8 @@ import { extractErrorMessage, generateFolderPath, generateRepositoryPath, - generateTokenType + generateTokenType, + isNullOrUndefined } from './util' /** Initializes and runs the action. @@ -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. diff --git a/src/util.ts b/src/util.ts index 59f7d982..54c13f42 100644 --- a/src/util.ts +++ b/src/util.ts @@ -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. */