Skip to content

Commit b3605fe

Browse files
authored
Merge pull request #7 from skywarth/custom-domain-expansion
Custom domain expansion
2 parents 85b2698 + 073df36 commit b3605fe

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,32 @@ Want to see it in action? Sure thing, head on to this vue project to see it live
124124
## 4. Input Parameters :wrench:
125125

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

131131

132-
[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 `/`.
132+
[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 `/`.
133133

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

136+
#### Here's how `public_base_path` is resolved:
137+
138+
- If `public_base_path` parameter/input is provided, it will be used regardless.
139+
- If `public_base_path` parameter/input is **NOT** provided:
140+
- If the repository root has `CNAME` file for GitHub Pages Custom Domain setup, then `public_base_path` default value will resolve to `/`
141+
- If the repository root does **NOT** have `CNAME`, `public_base_path` default value will resolve to `/{your-repo-name}`
142+
143+
<a name="public-base-path-ack"></a>
144+
#### Acknowledgement
145+
146+
See the suggestion for the CNAME expansion [here](https://github.com/skywarth/vite-github-pages-deployer/issues/5)
147+
148+
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.
149+
150+
<br>
151+
152+
136153
### `build_path`(optional)
137154
| Type | Default | Example Values |
138155
|----------|----------|--------------------------------------|

action.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ inputs:
99
public_base_path:
1010
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."
1111
required: false
12-
default: "/${{ github.event.repository.name }}"
12+
#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
13+
default: ''
1314
build_path:
1415
description: "Which folder do you want your Github Page to use as root directory. Usually it is your build output directory such as ./dist "
1516
required: false
@@ -41,6 +42,20 @@ outputs:
4142
runs:
4243
using: "composite"
4344
steps:
45+
- name: Determine Public Base Path
46+
run: |
47+
if [ -z "${{ inputs.public_base_path }}" ]; then
48+
if [ -f $GITHUB_WORKSPACE/CNAME ]; then
49+
PUBLIC_BASE_PATH="/"
50+
else
51+
PUBLIC_BASE_PATH="/${{ github.event.repository.name }}"
52+
fi
53+
else
54+
PUBLIC_BASE_PATH="${{ inputs.public_base_path }}"
55+
fi
56+
echo "PUBLIC_BASE_PATH=${PUBLIC_BASE_PATH}" >> $GITHUB_ENV
57+
shell: bash
58+
4459
- name: Dump context
4560
if: ${{ inputs.debug_mode=='true'}}
4661
uses: crazy-max/ghaction-dump-context@v2
@@ -72,14 +87,15 @@ runs:
7287
NODE_ENV: ${{ inputs.build_phase_node_env}}
7388
run: |
7489
# Building project
90+
echo "public base path. $PUBLIC_BASE_PATH";
7591
if [[ "${{ inputs.debug_mode }}" == "true" ]]; then echo "Build phase began. build_phase_node_env: ${{ inputs.build_phase_node_env}}"; fi;
7692
if [[ "${{ inputs.package_manager }}" == "yarn" ]]
7793
then
7894
if [[ "${{ inputs.debug_mode }}" == "true" ]]; then echo "Building via yarn"; fi;
79-
yarn build -- --base=${{ inputs.public_base_path }}
95+
yarn build -- --base=$PUBLIC_BASE_PATH #${{ inputs.public_base_path }}
8096
else
8197
if [[ "${{ inputs.debug_mode }}" == "true" ]]; then echo "Building via npm"; fi;
82-
npm run build -- --base=${{ inputs.public_base_path }}
98+
npm run build -- --base=$PUBLIC_BASE_PATH #${{ inputs.public_base_path }}
8399
fi
84100
shell: bash
85101
- name: Upload artifact

0 commit comments

Comments
 (0)