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

Tools: Preview was using main (still) #143

Conversation

codeallthethingz
Copy link
Contributor

@codeallthethingz codeallthethingz commented Jan 17, 2025

Turns out github.event.pull_request.merge_commit_sha was not uploading the docs from the new branch, so I tried another method of only checking out the docs folder on the branch of the PR using sparse checkout.

Copy link

github-actions bot commented Jan 17, 2025

📚 Documentation Preview

✅ A preview of the documentation changes in this PR is available for maintainers at:
https://thousandbrainsproject.readme.io/v0.0-codeallthethingz-bug-preview-does-not

Last updated: 2025-01-24 03:19 UTC

@codeallthethingz codeallthethingz added infrastructure Changes to infrastructure triaged This issue or pull request was triaged labels Jan 17, 2025
ref: ${{ github.event.pull_request.merge_commit_sha }}
ref: ${{ github.event.pull_request.head.sha }}
sparse-checkout-cone-mode: false
sparse-checkout: |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (non-blocking): I don't think the size of tbp.monty is large enough to matter whether we check out all of it or some of it. And if it is just as quick to checkout the whole repository, then we could get by without having another place to manage a file list.

- name: Deploy docs
working-directory: tbp.monty
run: |
export PATH="$HOME/miniconda/bin:$PATH"
source activate tbp.monty
export README_API_KEY=${{ secrets.README_API_KEY }}
export IMAGE_PATH=${{ vars.IMAGE_PATH }}
python -m tools.github_readme_sync.cli upload docs "${{ steps.preview_info.outputs.monty_version }}-${{ steps.preview_info.outputs.branch_name }}"

python -m tools.github_readme_sync.cli upload ../pr_docs/docs "${{ steps.preview_info.outputs.monty_version }}-${{ steps.preview_info.outputs.branch_name }}"
Copy link
Contributor

@tristanls tristanls Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: I don't understand where ../pr_docs/docs comes from. Why does this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's in the sparse checkout from above.

The flow is

  • check out the main branch using checkout action into ~/tbp.monty/
  • check out the PR's branch using the head reference into ~/pr_docs/ (was using sparse checkout but could be the entire project as you suggest)
  • run the tool from the main branch code, but upload the docs from the PR branch. ../pr_docs/docs

Thinking about it last night, this does put us at some risk of markdown/regex attacks as the PR could introduce some documentation that our regex parsing/markdown lib doesn't deal with very well and explodes. https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, ignore that, the code has gone... Lemme find it.

Copy link
Contributor Author

@codeallthethingz codeallthethingz Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok! That was embarrassing. The code is now back @tristanls

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Now I see what's going on 🙂!

@codeallthethingz codeallthethingz marked this pull request as draft January 17, 2025 17:51
@codeallthethingz codeallthethingz marked this pull request as ready for review January 17, 2025 18:28
Copy link
Contributor

@tristanls tristanls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

note: As you pointed out, there's likely security nuance with checking out a pull request branch and having README_API_KEY secret available. At first glance, it appears that per your indication ReDoS is possible, followed by some wider escape depending on github_readme_sync tool behavior as well as if anything fancy happens on checkout of a PR. Lastly, it could be an attack vector on Maintainers who open the preview in the browser.

@codeallthethingz codeallthethingz enabled auto-merge (squash) January 24, 2025 03:16
@codeallthethingz codeallthethingz merged commit 607505a into thousandbrainsproject:main Jan 24, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infrastructure Changes to infrastructure triaged This issue or pull request was triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants