Skip to content

Commit

Permalink
Merge pull request #7 from skywarth/custom-domain-expansion
Browse files Browse the repository at this point in the history
Custom domain expansion
  • Loading branch information
skywarth authored Nov 20, 2023
2 parents 85b2698 + 073df36 commit b3605fe
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,32 @@ Want to see it in action? Sure thing, head on to this vue project to see it live
## 4. Input Parameters :wrench:

### `public_base_path` (optional)
| Type | Default | Example Values |
|----------|---------------------|--------------------|
| `string` | `/{your-repo-name}` | `/my-vite-project` |
| Type | Default | Example Values |
|----------|----------------------------------------------|--------------------|
| `string` | `/{your-repo-name}` OR `/` if you have CNAME | `/my-vite-project` |


[Public base path](https://vitejs.dev/guide/build.html#public-base-path) string for Vite, this affects the routing, history and asset links. Make sure to provide appropriately since Github Pages stores your app in a directory under a subdomain. If you plan on deploying to alternative platform such as Vercel, you should simply provide `/`.
[Public base path](https://vitejs.dev/guide/build.html#public-base-path) string for Vite, this affects the routing, history and asset links. Make sure to provide appropriately since GitHub Pages stores your app in a directory under a subdomain. If you plan on deploying to alternative platform such as Vercel, you should simply provide `/`.

Under normal circumstances, you don't need to provide/override this parameter, action will set it to your repo name appropriately.

#### Here's how `public_base_path` is resolved:

- If `public_base_path` parameter/input is provided, it will be used regardless.
- If `public_base_path` parameter/input is **NOT** provided:
- If the repository root has `CNAME` file for GitHub Pages Custom Domain setup, then `public_base_path` default value will resolve to `/`
- If the repository root does **NOT** have `CNAME`, `public_base_path` default value will resolve to `/{your-repo-name}`

<a name="public-base-path-ack"></a>
#### Acknowledgement

See the suggestion for the CNAME expansion [here](https://github.com/skywarth/vite-github-pages-deployer/issues/5)

Grateful to the [Greg Sadetsky](https://github.com/gregsadetsky) for his proposition on alternating default value of this input. Also, thankful for his collaboration on explaining GitHub pages custom domain setting and testing phase of these changes.

<br>


### `build_path`(optional)
| Type | Default | Example Values |
|----------|----------|--------------------------------------|
Expand Down
22 changes: 19 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ inputs:
public_base_path:
description: "Public base path string for vite, this affects the routing, history and asset links. Make sure to provide appropriately since Github Pages stores your app in a directory under a subdomain."
required: false
default: "/${{ github.event.repository.name }}"
#default: "/${{ github.event.repository.name }}" //Vanilla default value. Altered down the steps in regard for https://github.com/skywarth/vite-github-pages-deployer/issues/5
default: ''
build_path:
description: "Which folder do you want your Github Page to use as root directory. Usually it is your build output directory such as ./dist "
required: false
Expand Down Expand Up @@ -41,6 +42,20 @@ outputs:
runs:
using: "composite"
steps:
- name: Determine Public Base Path
run: |
if [ -z "${{ inputs.public_base_path }}" ]; then
if [ -f $GITHUB_WORKSPACE/CNAME ]; then
PUBLIC_BASE_PATH="/"
else
PUBLIC_BASE_PATH="/${{ github.event.repository.name }}"
fi
else
PUBLIC_BASE_PATH="${{ inputs.public_base_path }}"
fi
echo "PUBLIC_BASE_PATH=${PUBLIC_BASE_PATH}" >> $GITHUB_ENV
shell: bash

- name: Dump context
if: ${{ inputs.debug_mode=='true'}}
uses: crazy-max/ghaction-dump-context@v2
Expand Down Expand Up @@ -72,14 +87,15 @@ runs:
NODE_ENV: ${{ inputs.build_phase_node_env}}
run: |
# Building project
echo "public base path. $PUBLIC_BASE_PATH";
if [[ "${{ inputs.debug_mode }}" == "true" ]]; then echo "Build phase began. build_phase_node_env: ${{ inputs.build_phase_node_env}}"; fi;
if [[ "${{ inputs.package_manager }}" == "yarn" ]]
then
if [[ "${{ inputs.debug_mode }}" == "true" ]]; then echo "Building via yarn"; fi;
yarn build -- --base=${{ inputs.public_base_path }}
yarn build -- --base=$PUBLIC_BASE_PATH #${{ inputs.public_base_path }}
else
if [[ "${{ inputs.debug_mode }}" == "true" ]]; then echo "Building via npm"; fi;
npm run build -- --base=${{ inputs.public_base_path }}
npm run build -- --base=$PUBLIC_BASE_PATH #${{ inputs.public_base_path }}
fi
shell: bash
- name: Upload artifact
Expand Down

0 comments on commit b3605fe

Please sign in to comment.