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

ci : Add github action workflow to generate documentation preview #23

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rohanKanojia
Copy link
Contributor

@rohanKanojia rohanKanojia commented Feb 3, 2025

Description

This pull request adds functionality of publishing documentation changes added in pull requests to some temporary github repository and posting the generated preview documentation via a URL.

Added GitHub action to generate documentation preview by publishing GitHub Pages on an external repository.

I've tested this workflow on my fork. You can see a demo PR here

Prerequisites

In order to changes added in this pull request to work, we need to do these things first:

  • A target github repository where these pull request preview documentation would be published needs to be created
  • A GitHub personal access token (PAT) needs to be created with write permissions to this repository.
  • We need to configure crc-org/docs repository settings and add the following secrets:
    • PREVIEW_PUBLISH_USERNAME : GitHub user/organization name where preview repository is hosted
    • PREVIEW_PUBLISH_REPOSITORY: Github repository name where preview docs would be published
    • PREVIEW_PUBLISH_BRANCH: GitHub branch for the repository which is configured for github pages
    • PREVIEW_PUBLISH_TOKEN: GitHub Personal access token that has write permissions to abovementioned repository.

Github Action workflows added:

This change adds four new github action workflows:

  • Documentation Preview Request: A workflow that would run on the pull request and generate website and upload it as a github artifact.
  • Documentation Preview Generator: A workflow that would get triggered on the completion of Documentation Preview Request workflow and it would download the uploaded artifact and deploy the content to github repository configured in secrets.
  • Documentation Preview Cleanup Request: A workflow that would run on pull request upon the closing event of pull request. It would save pull request number as an artifact and upload it.
  • Documentation Preview Cleanup: A workflow that would get triggered on the completion of Documentation Preview Cleanup Request workflow and it would download the uploaded artifact and update the github repository and remove the generated preview directory.

- name: Save pull request context to artifact directory
run: |
echo ${{ github.event.pull_request.number }} > ./public/pr_number.txt
echo ${{ github.sha }} | cut -c 1-7 > ./public/sha.txt
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't find a way to extract PR number and SHA from pull request context.

Choose a reason for hiding this comment

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

for PR number I use the ${{ github.event.number }} but I guess this way is fine as well...
https://github.com/redhat-developer/mapt/blob/main/.github/workflows/build-oci.yaml#L27C49-L27C75

About the sha... I did not make it but I recall Jakub struggle a bit with it... on the e2e sample flow he moved all github context and inspect for the sha like this https://github.com/crc-org/crc/blob/6d72284a886c4978e13e4775b9b8f552e134bf18/.github/workflows/windows-qe-tpl.yml#L65

Cause if I recall it right values were a but messy as they depend on firs open for the PR or forced push...but I can not ensure may your payload value is always valid...just take a look at the code from the link...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think I should drop the SHA specific preview approach altogether? I think contributor would only be interested in the latest pushed branch preview only 🤔 .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anyway, I think it's better to upload PR github context file as artifact rather than creating single files for specific attributes.

Let me update it as per your suggestion.


jobs:
on-close:
runs-on: ubuntu-latest

Choose a reason for hiding this comment

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

minor thing, I would suggest to set the version instead of latest to be sure about it ubuntu-24.04

this would apply to the other files as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I've updated all workflows to use ubuntu-24.04

- name: Save pull request context to artifact directory
run: |
echo ${{ github.event.pull_request.number }} > ./public/pr_number.txt
echo ${{ github.sha }} | cut -c 1-7 > ./public/sha.txt

Choose a reason for hiding this comment

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

for PR number I use the ${{ github.event.number }} but I guess this way is fine as well...
https://github.com/redhat-developer/mapt/blob/main/.github/workflows/build-oci.yaml#L27C49-L27C75

About the sha... I did not make it but I recall Jakub struggle a bit with it... on the e2e sample flow he moved all github context and inspect for the sha like this https://github.com/crc-org/crc/blob/6d72284a886c4978e13e4775b9b8f552e134bf18/.github/workflows/windows-qe-tpl.yml#L65

Cause if I recall it right values were a but messy as they depend on firs open for the PR or forced push...but I can not ensure may your payload value is always valid...just take a look at the code from the link...


jobs:
documentation-preview:
runs-on: ubuntu-latest

Choose a reason for hiding this comment

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

May recall to add a condition on trigger completed + is successfully??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I had forgotten to add the condition for successful completion. I've added it.

@rohanKanojia rohanKanojia force-pushed the main branch 3 times, most recently from 629282f to a64507d Compare February 3, 2025 17:56
Add github action to generate documentation preview by publishing gh-pages on an external repository. This change adds four new github action workflows:
- Documentation Preview Request: A workflow that would run on the pull request and generate website and upload it as a github artifact.
- Documentation Preview Generator: A workflow that would get triggered on the completion of `Documentation Preview Request` workflow and it would download the uploaded artifact and deploy the content to github repository configured in secrets.
- Documentation Preview Cleanup Request: A workflow that would run on pull request upon the closing event of pull request. It would save pull request number as an artifact and upload it.
- Documentation Preview Cleanup: A workflow that would get triggered on the completion of `Documentation Preview Cleanup Request` workflow and it would download the uploaded artifact and update the github repository and remove the generated preview directory.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants