Skip to content

deployblog

deployblog #182

#...........................................................................................................................
# References:
# - https://github.com/orchid00/actions_sandbox/issues/41#issuecomment-816970613
# - https://github.com/murraycadzow/test_blogdown/blob/master/.github/workflows/deploy_blogdown.yml
# - https://blog--simonpcouch.netlify.app/blog/r-github-actions-commit/
# - https://github.com/simonpcouch/scheduled-commit-action/blob/master/.github/workflows/schedule-commit.yaml
# - https://github.community/t/github-actions-bot-email-address/17204
# - https://www.etiennebacher.com/posts/2021-03-19-use-github-actions-with-r-markdown-and-distill/
# - https://github.com/pbatey/flexdashboard-example
# - https://ramikrispin.github.io/2020/09/deploying-flexdashboard-on-github-pages/
#
# It is also possible to create a "single" (not a multi-page) Github Pages by including
# - a 'docs' directory in the root of the repository
# - by converting the .Rmd to .html then rename the .html file to 'index.html' and adding the 'index.html' to 'docs'
# - by including a '.nojekyll' file inside the 'docs' directory
# then just push to github. Reference:
# https://jupyterbook.org/publish/gh-pages.html#option-1-copy-and-paste-your-books-build-contents-into-a-new-folder
#...........................................................................................................................
#................................................................................................
# run a cron-job every week (say, on Sunday at 23:00 pm
# The time difference between UTC and EEST - my current time zone - is 3 hours:
#
# https://crontab.guru/examples.html
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#scheduled-events#
# https://upptime.js.org/blog/2021/01/22/github-actions-schedule-not-working/
#................................................................................................
on:
schedule:
- cron: "0 23 * * SUN"
push:
branches: master
#.............................................................................................................................................
# Create every week an updated .Rmd file (including the .Rds data) and push these files to a separate directory of the "/content/post" folder
# Before building the 'hugo' website use "build_rmd = TRUE" otherwise the index of website won't be built, see:
# https://github.com/rstudio/blogdown/blob/master/NEWS.md#new-features-3
# since blogdown version==0.21 the blogdown::build_site() no longer recompiles R Markdown files by default
# For major Changes in Blogdown (especially from version >=0.21), see: https://github.com/rstudio/blogdown/blob/master/NEWS.md
#
# To commit and push the changes I use the default setting of the github actions repo
# Because I received an error I've added "${{ github.event.pull_request.head.ref }}"
#
# The "asc_desc_linestring" parameter must be one of the following:
# - an empty string ( "" ). In this case a sinle color Linestring will be plotted
# - a boolean in form of a character ('TRUE' or 'FALSE'). If TRUE split in peak of the data
# - a lubridate::hms('17:05:00') object in form of a character string, i.e. "17H 5M 0S"
# The GPS data will be split based on the input lubridate time point
#
# As mentioned in
# https://github.com/aws-actions/configure-aws-credentials/issues/9#issuecomment-569370732
# the "awscli" is available when using "aws-actions/configure-aws-credentials@v1"
#
# Switch to environment variables for the input parameters as discussed in the next weblinks and make sure that these are character strings:
# https://github.blog/changelog/2019-10-01-github-actions-new-workflow-syntax-features/#env-at-the-workflow-and-job-level
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#env
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#env-context
# https://github.com/actions/starter-workflows/issues/68#issuecomment-538026112
# https://github.com/actions/starter-workflows/issues/68#issuecomment-524661275
#
# Using the "working-directory" keyword, I can specify the working directory of where to run the command of a specific step
# It seems that the default path of the working directory was changed before running the step "Fitbit Parameter Setting and Script"
#
# I solved the issue related with the issue ‘No such file or directory’, see:
# https://github.community/t/no-such-file-or-directory-error-when-running-scheduled-github-action/184570
#
# Regarding the 'DATE' parameter, I had to create an additional step, see also:
# https://github.community/t/how-can-i-set-an-expression-as-an-environment-variable-at-workflow-level/16516/7
# https://stackoverflow.com/a/64649397/8302386
#.............................................................................................................................................
name: deployblog
jobs:
blogdown:
name: Render-Blog
runs-on: macOS-latest
steps:
- uses: actions/checkout@v2
if: github.event_name == 'pull_request'
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
- uses: actions/checkout@v2
if: github.event_name != 'pull_request'
with:
fetch-depth: 0
- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-pandoc@v1
- name: Install XQuartz
run: brew install xquartz
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-central-1
# - name: test if awscli is available
# run: aws s3 ls
- name: Install ImageMagick
run: brew install imagemagick
- name: Install udunits
run: brew install udunits
- name: "Install spatial libraries (copied from https://github.com/r-spatial/sf/blob/master/.github/workflows/tic-db.yml#L99)"
run: |
# conflicts with gfortran from r-lib/actions when linking gcc
rm '/usr/local/bin/gfortran'
brew install pkg-config gdal proj geos
- name: Install required packages
run: |
Rscript -e 'install.packages(c("DT", "magick", "glue", "rmarkdown", "remotes"))'
Rscript -e "Sys.setenv(GITHUB_PAT = '${{ secrets.GH_PAT }}'); remotes::install_github(c('rstudio/blogdown'), upgrade = 'always', dependencies = TRUE, repos = 'https://cloud.r-project.org/')"
- name: "Install the Github version of 'rayshader'"
run: Rscript -e "Sys.setenv(GITHUB_PAT = '${{ secrets.GH_PAT }}'); remotes::install_github(c('tylermorganwall/rayshader'), upgrade = 'always', dependencies = TRUE, repos = 'https://cloud.r-project.org/')"
- name: "Install the Github versions of 'CopernicusDEM' and 'fitbitViz'"
run: Rscript -e "Sys.setenv(GITHUB_PAT = '${{ secrets.GH_PAT }}'); remotes::install_github(c('mlampros/CopernicusDEM', 'mlampros/fitbitViz'), upgrade = 'always', dependencies = TRUE, repos = 'https://cloud.r-project.org/')"
- name: install hugo
run: Rscript -e 'blogdown::install_hugo()'
- name: Fitbit DATE parameter (this has to be a separate step)
# run: echo "DATE='2022-02-27'">> $GITHUB_ENV
run: echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Fitbit Parameter Setting and Script
working-directory: ${{ github.workspace }}
env:
previous_n_days: "6"
sleep_time_begins: "00H 40M 0S"
sleep_time_ends: "08H 00M 0S"
asc_desc_linestring: ""
time_zone: "Europe/Athens"
buffer_meters: "1500"
resolution_dem: "30"
verbose_Rmd: "FALSE"
run: Rscript R_templates/data_template.R ${{ secrets.USER_ID }} ${{ secrets.FITBIT_TOKEN }} ${previous_n_days} ${{ env.DATE }} "${sleep_time_begins}" "${sleep_time_ends}" "${asc_desc_linestring}" ${time_zone} ${buffer_meters} ${resolution_dem} ${verbose_Rmd}
- name: Commit files
run: |
git config --local user.email "actions@github.com"
git config --local user.name "GitHub Actions"
git add --all
git commit -am "add data and .Rmd file"
git push
- name: Render blog
run: Rscript -e 'blogdown::build_site(build_rmd = TRUE)'
- uses: actions/upload-artifact@v1
with:
name: public
path: public/
#.............................................................................
# Need to first create an empty gh-pages branch see
# https://pkgdown.r-lib.org/reference/deploy_site_github.html
# and also add secrets for a GH_PAT and EMAIL to the repository gh-action from
# Cecilapp/GitHub-Pages-deploy
#.............................................................................
checkout-and-deploy:
runs-on: ubuntu-latest
needs: blogdown
steps:
- name: Checkout
uses: actions/checkout@master
- name: Download artifact
uses: actions/download-artifact@v1.0.0
with:
name: public # Artifact name (optional)
path: public # Destination path (optional)
- name: Deploy to GitHub Pages
uses: Cecilapp/GitHub-Pages-deploy@v3
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }} # https://github.com/settings/tokens
with:
email: ${{ secrets.EMAIL }}
build_dir: public/ # "_site/" by default