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

Add ability to specify GitHub pages directory #80

Closed
RedSparr0w opened this issue Feb 9, 2024 · 3 comments
Closed

Add ability to specify GitHub pages directory #80

RedSparr0w opened this issue Feb 9, 2024 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@RedSparr0w
Copy link

RedSparr0w commented Feb 9, 2024

Currently as far as I can tell, you are not able to specify the directory you are using to serve your GitHub pages project.
This means when the preview URL is generated it still includes the pages directory pointing to a broken link.

For example, my repo uses docs/ as the GitHub pages base directory, with the following config I get this output:

          source-dir: 'build'
          preview-branch: 'master'
          umbrella-dir: 'docs/preview'
          custom-url: 'example.site'

Output URL: https://example.site/docs/preview/pr-123
Expected URL: https://example.site/preview/pr-123

@rossjrw
Copy link
Owner

rossjrw commented Feb 9, 2024

Closing this issue as a duplicate of #42.

@rossjrw rossjrw closed this as not planned Won't fix, can't repro, duplicate, stale Feb 9, 2024
@rossjrw
Copy link
Owner

rossjrw commented Feb 9, 2024

@RedSparr0w I wouldn't set master as the preview branch.

The preview action will put a copy of the entire contents of your repo into the preview branch. In this case you've got docs/preview/pr-123/ containing a copy of the repo, modified as per PR 123, but it'll also include its own docs directory docs/preview/pr-123/docs/. Bear in mind that this is all on the master branch.

Next person to make a pull request branches from master, which contains PR 123's preview, and opens PR 124. Now master's docs dir contains docs/preview/pr-123/ and also docs/preview/pr-124/. Sounds good so far but because PR 123 and PR 124 are happening at the same time, and PR 124 came later, you also have docs/preview/pr-123/docs/preview/pr-123/.

Let's say PR 123 is a little out of date and merges master into itself. Now you've got docs/preview/pr-123/docs/preview/pr-124/docs/preview/pr-123/. Your preview directory is growing exponentially with seemingly-harmless operations like updating pull requests. All of this is happening on the master branch, affecting pull time, repo size etc.

In my projects, a rule I stick to is that the main branch should only ever contain work authored by humans. Previews are technically computer-generated given that they're just copies of human-written work.

Deploying from docs/ on the master branch has presumably worked fine for you up until now because, I assume, all the stuff in there is entirely authored by humans. Now that you want to add generated files I suggest a different workflow.

I would suggest adopting the 'gh-pages' workflow that my preview action assumes as a default. By deploying from the root directory of the gh-pages branch, you create a dedicated space for your deployment and subdeployments (like these previews) to exist without impacting anything else. Critically, no-one is going to want to branch from gh-pages to add new stuff to your repo, so you'll never get the feedback loop that I described.

You should still keep your deployment in docs/, but add a new workflow that copies it into gh-pages on push to master - e.g. https://github.com/rossjrw/pr-preview-action?tab=readme-ov-file#full-example (but change the source-dir and folder parameters from . to ./docs/)

@rossjrw rossjrw added the duplicate This issue or pull request already exists label Feb 9, 2024
@RedSparr0w
Copy link
Author

Oh sorry, some how missed #42 😅

All of our code and PRs go to our develop branch, It's all deploying fine without recursion, we build to the build/ directory, and then move it over to the docs/ directory for deployment.

Or in the case of the PR previews, it's just copying the build directory over to docs/preview/pr-123 on our gh-pages specified branch (have had multiple PRs and re-deployments of PRs to confirm).

Our master branch only contains the gh-pages data, and not the rest of the code.

Unfortunately it has to be on the master branch and docs directory due to some other systems we have relying on it being there due to how it was previously deployed a long while ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants