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 downloadable comprehensive preview #61

Merged
merged 13 commits into from
Mar 13, 2024
34 changes: 22 additions & 12 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ jobs:
# Make the branch fresh
- name: Make the branch fresh
run: |
git config --local user.email "itcrtrainingnetwork@gmail.com"
git config --local user.name "jhudsl-robot"
git config --global --add safe.directory $GITHUB_WORKSPACE
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

branch_name='preview-${{ github.event.pull_request.number }}'
echo branch doesnt exist
git checkout -b $branch_name || echo branch exists
Expand Down Expand Up @@ -83,9 +85,9 @@ jobs:
# Set up git checkout
- name: Set up git checkout
run: |
git config --system --add safe.directory $GITHUB_WORKSPACE
git config --local user.email "itcrtrainingnetwork@gmail.com"
git config --local user.name "jhudsl-robot"
git config --global --add safe.directory $GITHUB_WORKSPACE
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

branch_name='preview-${{ github.event.pull_request.number }}'
git fetch --all
Expand All @@ -110,13 +112,16 @@ jobs:
echo site status ${{steps.site.outcome}}
exit 1

- name: Website preview for download
run: zip website-preview.zip docs/* -r

# Commit the rendered website files
- name: Commit rendered website files to preview branch
id: commit
run: |
branch_name='preview-${{ github.event.pull_request.number }}'
git diff origin/main -- '*.html' >/dev/null && changes=true || changes=false
echo ::set-output name=changes::$changes
echo "changes=$changes" >> $GITHUB_OUTPUT
git add . --force
git commit -m 'Render preview' || echo "No changes to commit"
git pull --set-upstream origin $branch_name --allow-unrelated-histories --strategy-option=ours
Expand All @@ -136,9 +141,11 @@ jobs:
run: |
course_name=$(head -n 1 _website.yml | cut -d'"' -f 2| tr " " "-")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
course_name=$(head -n 1 _website.yml | cut -d'"' -f 2| tr " " "-")

appears not to be used. Did you mean to echo it to the log?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted!

website_link=$(echo "https://htmlpreview.github.io/?https://raw.githubusercontent.com/$GITHUB_REPOSITORY/preview-${{ github.event.pull_request.number }}/docs/index.html")
echo ::set-output name=website_link::$website_link
echo ::set-output name=time::$(date +'%Y-%m-%d')
echo ::set-output name=commit_id::$GITHUB_SHA
docs_link=$(echo "https://github.com/$GITHUB_REPOSITORY/raw/preview-${{ github.event.pull_request.number }}/website-preview.zip")
Copy link
Contributor

Choose a reason for hiding this comment

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

can we name this something more descriptive, like "zip_file" ? docs_link makes it sound like its gonna take you to documentation

Copy link
Contributor

@avahoffman avahoffman Mar 12, 2024

Choose a reason for hiding this comment

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

Could we also break this chunk up into "# Store variables" and "# Print to log" for readability?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do! On both accounts!

Copy link
Contributor Author

@cansavvy cansavvy Mar 13, 2024

Choose a reason for hiding this comment

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

Oh actually the "echo to log" can't really be separated the echo "zip_link=$docs_link" >> $GITHUB_OUTPUT aren't echoing to log, the are saving the GitHub variables to the output and have to be done in the same step.

echo "docs_link=$docs_link" >> $GITHUB_OUTPUT
echo "website_link=$website_link" >> $GITHUB_OUTPUT
echo "time=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
echo "commit_id=$GITHUB_SHA" >> $GITHUB_OUTPUT
echo ${{steps.commit.outputs.changes}}

- name: Create or update comment
Expand All @@ -148,9 +155,12 @@ jobs:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Re-rendered previews from the latest commit: See [preview of website here](${{ steps.build-components.outputs.website_link }})

_Updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_
:eyes: Quick [preview of website here](${{ steps.build-components.outputs.website_link }}) \*
:microscope: Comprehensive [download of the website here](${{ steps.build-components.outputs.docs_link }})

\* note not all html features will be properly displayed in the "quick preview" but it will give you a rough idea.

_Updated at ${{ steps.build-components.outputs.time }} with changes from the latest commit ${{ steps.build-components.outputs.commit_id }}_
edit-mode: replace

- name: No comment if no changes
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/render-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ jobs:
# Commit the rendered site files - html files and site_libs files
- name: Commit rendered site files
run: |
git config --system --add safe.directory $GITHUB_WORKSPACE
git config --local user.email "actions@github.com"
git config --local user.name "GitHub Actions"
git config --global --add safe.directory $GITHUB_WORKSPACE
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add --force docs/*
git commit -m 'Render site' || echo "No changes to commit"
git push origin main || echo "No changes to push"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
Loading