-
Notifications
You must be signed in to change notification settings - Fork 8
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
[DOCS-1262] Add GH action for per-page preview links #1091
Open
mdlinville
wants to merge
2
commits into
main
Choose a base branch
from
DOCS-1262
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
name: List files changed as GitHub comment | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
list-files-changed: | ||
if: github.event.pull_request.head.repo.full_name == github.repository | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 2 | ||
|
||
- name: Format list of changed files | ||
id: format | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: | | ||
declare -a output | ||
pr_num=${{ github.event.pull_request.number }} | ||
|
||
files=$(gh pr view ${pr_num} --json files --jq '.files.[].path') | ||
removed_files=$(gh api repos/wandb/docs/pulls/${pr_num}/files -q '.[] | [.status,.filename] | @tsv' |grep 'removed' | awk -F ' ' {'print $2'}) | ||
|
||
SAVEIFS=$IFS | ||
IFS=$'\n' | ||
files=($files) | ||
IFS=$SAVEIFS | ||
|
||
function generatePreviewURL() { | ||
# Preprocess input paths to output paths | ||
# using # as sed separation character | ||
# | ||
# - Remove content/ | ||
# - Remove _index/ | ||
# - Remove integration_tutorials/ | ||
|
||
# Generate HTML preview for added and modified files only | ||
if [[ ! " ${removed_files[*]} " =~ $1 ]]; then | ||
html_file=$(echo "${1%.md}/" | sed -E 's#content\/##g' | sed -E 's#/_index/##g' | sed -E 's#integration-tutorials\/##g') | ||
# Save a URL instead of just a plaintext file | ||
file="<a href=\"https://docs-$pr_num.docodile.pages.dev/$html_file\" target=\"_blank\" rel=\"noopener\">$1</a>" | ||
else | ||
file="<b>Removed</b>: $1" | ||
fi | ||
|
||
# Apend to output (non-Markdown added in the else of the next block) | ||
output+="<li>$file</li>" | ||
} | ||
|
||
for file in ${files[@]}; do | ||
# Generate links for changed Markdown files | ||
if [[ $file == content/**/*.md ]] | ||
then | ||
generatePreviewURL "$file" | ||
# Otherwise just list changed file paths | ||
else | ||
output+="<li><b>No preview</b>: $file</li>" | ||
fi | ||
done; | ||
body="${output[@]}" | ||
echo "body:\n\n$body" | ||
echo "body=$body" >> $GITHUB_ENV | ||
|
||
- name: Find Comment | ||
uses: peter-evans/[email protected] | ||
id: find-comment | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
comment-author: 'github-actions[bot]' | ||
body-includes: 'HTML previews:' | ||
|
||
- name: Create comment | ||
uses: peter-evans/[email protected] | ||
with: | ||
comment-id: ${{ steps.find-comment.outputs.comment-id }} | ||
issue-number: ${{ github.event.pull_request.number }} | ||
edit-mode: replace | ||
body: | | ||
<h3>HTML previews:</h3><ul>${{ env.body }}</ul><p>Preview links work **only** after the `Cloudflare Pages` build check succeeds. Links are generated only for new and modified <code>.md</code> files under <code>content/</code>.</p><p><a href="https://github.com/wandb/docs/issues/new?title=Feedback+about+HTML+preview+comments&assignees=mdlinville&body=Link+to+PR+and+describe+the+issue">Feedback about HTML previews</a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we want to be concise with the comment, we can move: "Links are generated only for new and modified to a |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format of the markdown is a little confusing.
Can separate the non generated vs generated links into separate sections or add "Generated preview" to the second bullet point in
body
?i.e. From this:
HTML previews:
To something like:
HTML previews:
or perhaps even
HTML previews: