Skip to content

Commit

Permalink
Merge pull request #61 from jhudsl/cansavvy/comprehensive-preview
Browse files Browse the repository at this point in the history
Add downloadable comprehensive preview
  • Loading branch information
cansavvy authored Mar 13, 2024
2 parents 88dda92 + 2fc90bc commit 3ff2e81
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
32 changes: 21 additions & 11 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 "[email protected]"
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 "[email protected]"
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 " " "-")
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")
echo "zip_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 }})
:eyes: Quick [preview of website here](${{ steps.build-components.outputs.website_link }}) \*
:microscope: Comprehensive [download of the website here](${{ steps.build-components.outputs.zip_link }})
_Updated at ${{ steps.build-components.outputs.time }} with changes from ${{ steps.build-components.outputs.commit_id }}_
\* 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

0 comments on commit 3ff2e81

Please sign in to comment.