rossjrw / pr-preview-action

GitHub Action that deploys a pull request preview to GitHub Pages, similar to Vercel and Netlify, and cleans up after itself.
https://github.com/marketplace/actions/deploy-pr-preview
MIT License
255 stars 39 forks source link

Customize the directory to serve from #42

Open Tbhesswebber opened 1 year ago

Tbhesswebber commented 1 year ago

Our Github Pages configuration is set up to serve from a subdirectory and there is currently no documented way to address this with pr-preview-action.

Example:

Preview Deployment Action

      - name: Deploy Preview
        uses: rossjrw/pr-preview-action@v1
        with:
          source-dir: docs
          preview-branch: gh-pages
          umbrella-dir: docs/pr-preview
          action: auto

Deployment Action


      - uses: JamesIves/github-pages-deploy-action@v4
        with:
          folder: docs
          target-folder: docs
          branch: gh-pages
          clean-exclude: docs/pr-preview

With the above configurations, we end up with everything correctly being saved to the docs directory.  The generated preview link is /docs/pr-preview/pr-xx.  I can delete the /docs path part and see the preview just fine, but the generated link shows a totally valid 404 because we are serving directly from the docs directory that things are being saved to rather than serving from the root directory.

rossjrw commented 1 year ago

Deploying documentation to docs/ on the main branch vs deploying it to the root directory on the gh-pages branch are typically two different methods of isolating GitHub Pages deployments from the rest of the codebase. I'd say it's unusual to see a deployment to the docs/ directory on the gh-pages branch - is this setup definitely intended?

A more traditional approach would be to copy docs/ on your feature branch to the root of the gh-pages branch:

# Preview
      - name: Deploy Preview
        uses: rossjrw/pr-preview-action@v1
        with:
          source-dir: docs
          preview-branch: gh-pages
          umbrella-dir: pr-preview
          action: auto
# Main deployment
      - uses: JamesIves/github-pages-deploy-action@v4
        with:
          folder: docs
          target-folder: .
          branch: gh-pages
          clean-exclude: pr-preview

That would probably be easiest and more in line with the 'standard' approach.

But assumptions and principle aside, if you really do need to deploy from docs/ on gh-pages and you're using the root dir on gh-pages for something else, then you're right - there's currently no way to do that. The variable used for the deployment target dir is the same as the one used to construct the URL:

https://github.com/rossjrw/pr-preview-action/blob/022361539c71c58a7141d4fe8c3e0e4a1c34f9c5/action.yml#L131

https://github.com/rossjrw/pr-preview-action/blob/022361539c71c58a7141d4fe8c3e0e4a1c34f9c5/action.yml#L152-L153

The long-term solution to this would be to add a parameter that indicates what directory Pages is being served from in that repo, as you originally suggested.

Tbhesswebber commented 1 year ago

We can definitely get around this by changing configurations in GH, but I think this is still a valuable feature to add for anyone who doesn't have easy access to the repo settings or a person with repo admin access.

RedSparr0w commented 5 months ago

+1 for this, even if it was just a separate input which would replace the partial string of umbrella-dir.

          umbrella-dir: 'docs/preview'
          pages-base: 'docs/'

then on the output just replace any instance of pages-base in umbrella-dir before sending the url.