Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use links of the deploy preview, not actual deployment #14

Open
dharmit opened this issue Aug 19, 2022 · 3 comments
Open

Use links of the deploy preview, not actual deployment #14

dharmit opened this issue Aug 19, 2022 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@dharmit
Copy link

dharmit commented Aug 19, 2022

I'm running into an issue where clicking on any link on the landing page on deploy preview take me to the page on actual deployment being served from the root of gh-pages branch instead of the deploy preview generated using pr-review-action.

For example, my index page has a link to "Introduction" which takes me to <user>.github.io/<repo>/docs/introduction. For a deploy preview built using pr-review-action, I expect it to take me to <user>.github.io/<repo>/pr-review/pr-<pr-number>/docs/introduction.

For reference, you can take a look at https://github.com/dharmit/odo-gh-actions/pull/6. The deploy preview is available at https://dharmit.github.io/odo-gh-actions/pr-preview/pr-6/. But when I click on "Read the docs" button, it takes me to https://dharmit.github.io/odo-gh-actions/docs/introduction while I expect it to take me to https://dharmit.github.io/odo-gh-actions/pr-preview/pr-6//docs/introduction.

@rossjrw rossjrw added the enhancement New feature or request label Aug 21, 2022
@rossjrw
Copy link
Owner

rossjrw commented Aug 21, 2022

I see that your site is built using Docusaurus. To reflect the changed base URL in your build, you should use the baseUrl config setting: https://docusaurus.io/docs/api/docusaurus-config#baseUrl

You may wish to determine this value programmatically in your config.js file. Your preview workflow might for example set an environment variable containing the path of the preview deployment, which you could then pick up in your config, e.g.:

# .github/workflows/test-deploy.yml

...
jobs:
  test-deploy:
    ...
    steps:
      ...
      - run: echo "PREVIEW_PATH=pr-preview/pr-${{ github.event.number }}" >> "$GITHUB_ENV"
      - name: Build website
        run: yarn build
      - name: Deploy preview
        uses: rossjrw/pr-preview-action@v1
        with:
          source-dir: ./docs/website/build/
// docs/website/docusaurus.config.js

let baseUrl = "/odo-gh-actions/"
if (process.env.PREVIEW_PATH) baseUrl += process.env.PREVIEW_PATH

module.exports = {
  ...
  baseUrl: baseUrl,
  ...
}

I'm going to record this as a documentation task, because while I feel that it's beyond the scope of the action to do this automatically, it should at least be mentioned in the documentation along with a pointer on how to get started setting it up.

@rossjrw rossjrw added documentation Improvements or additions to documentation and removed enhancement New feature or request labels Apr 30, 2023
@james-s-w-clark
Copy link

james-s-w-clark/docusaurus-pr-preview-gh#3

Here's an example of this working in a public repo. The above suggestion works great.

@0o-de-lally
Copy link

Very helpful example. Perhaps this can be promoted somewhere in the docs?
Thanks for a great tool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants