From 6bb4f80090e30572944312cc70a56a2ab74d8ca7 Mon Sep 17 00:00:00 2001 From: Nick McCurdy Date: Sat, 25 Jun 2022 04:56:10 -0400 Subject: [PATCH 1/2] Set default branch to gh-pages (fix #1151) --- .github/workflows/integration.yml | 12 ------------ README.md | 8 +------- action.yml | 3 ++- src/constants.ts | 2 +- src/lib.ts | 9 +++++++-- src/util.ts | 4 +++- 6 files changed, 14 insertions(+), 24 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 434be135b..fcf239e87 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 f22dfc077..57bef676d 100644 --- a/README.md +++ b/README.md @@ -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. ``` @@ -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` | **Yes** | | `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: | @@ -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. ``` @@ -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 8f761b377..f508021d4 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 6505b7781..e0ce80755 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 7a8081ea4..1a6ea0da9 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 59f7d9821..54c13f42d 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. */ From d8c5cba461b99b2126a8935d1037e1a3bb35d456 Mon Sep 17 00:00:00 2001 From: Nick McCurdy Date: Sat, 25 Jun 2022 05:28:23 -0400 Subject: [PATCH 2/2] Fix documented requirement of branch --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 57bef676d..38facd3c9 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: @@ -96,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 ``` @@ -157,7 +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` | **Yes** | +| `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** | @@ -265,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: @@ -333,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: