Skip to content

update-dashboard

update-dashboard #630

on:
push:
branches:
- main
schedule:
- cron: '13 05 * * 1-5'
name: update-dashboard
jobs:
update-dashboard:
name: Update Dashboard
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
cache-version: 2
extra-packages: any::rmarkdown, local::.
- name: Render Dashboard
run: Rscript -e 'rmarkdown::render("vignettes/actions-dashboard.Rmd", rmarkdown::html_vignette(), "index.html")'
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
- name: Push to GitHub Pages branch
run: |
# setup git credentials
git config --local user.email "actions@github.com"
git config --local user.name "GitHub Actions"
# code below is essentialy what pkgdown does: https://github.com/r-lib/pkgdown/blob/9aae87398abdbe1cd5af5ff6f168d2e142d531c9/R/deploy-site.R#L105
# create gh-pages folder
mkdir temp
git fetch origin gh-pages
git worktree add --track -B gh-pages temp origin/gh-pages
# delete everything and manually delete a few hidden files
tree -a temp
rm -rf temp/* temp/.Rbuildignore temp/.Rprofile temp/.gitignore temp/.github
tree -a temp
# move new html file
mv vignettes/index.html temp/index.html
tree -a temp
cd temp
git status
git add --all .
echo "GITHUB_EVENT_NAME=${GITHUB_EVENT_NAME}"
if [ "${GITHUB_EVENT_NAME}" = 'schedule' ]; then
message="Built site for commit ${GITHUB_SHA} from scheduled run at $(date)"
else
message="Built site for commit ${GITHUB_SHA}"
fi
git commit -m "${message}"
git push --force origin HEAD:gh-pages
cd ..
git worktree remove temp
shell: bash