pin ubuntu version to 20.04 (#540)
[rnaseq-cwl-training.git] / .github / workflows / website.yml
index f82339b889a87c45734a305103268845162e2f70..b67e07ecc6f862331a70c28df4943732dbc5de8a 100644 (file)
@@ -1,20 +1,25 @@
-name: Build website
+name: Website
 on:
   push:
-    branches: gh-pages
+    branches:
+      - gh-pages
+      - main
   pull_request: []
 jobs:
   build-website:
-    if: github.repository != 'carpentries/styles' && (github.repository_owner == 'swcarpentry' || github.repository_owner == 'datacarpentry' || github.repository_owner == 'librarycarpentry' || github.repository_owner == 'carpentries')
-    runs-on: ubuntu-latest
+    if: ${{ !endsWith(github.repository, '/styles') }}
+    runs-on: ubuntu-20.04
+    env:
+      RSPM: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"
+      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
     defaults:
       run:
         shell: bash
     steps:
       - name: Set up Ruby
-        uses: actions/setup-ruby@main
+        uses: actions/setup-ruby@v1
         with:
-          ruby-version: '2.7.1'
+          ruby-version: '2.7'
 
       - name: Set up Python
         uses: actions/setup-python@v2
@@ -37,7 +42,6 @@ jobs:
 
       - name: Look for R-markdown files
         id: check-rmd
-        working-directory: lesson
         run: |
           echo "::set-output name=count::$(shopt -s nullglob; files=($(find . -iname '*.Rmd')); echo ${#files[@]})"
 
@@ -55,7 +59,6 @@ jobs:
 
       - name: Query dependencies
         if: steps.check-rmd.outputs.count != 0
-        working-directory: lesson
         run: |
           source('bin/dependencies.R')
           deps <- identify_dependencies()
@@ -74,15 +77,37 @@ jobs:
 
       - name: Install system dependencies for R packages
         if: steps.check-rmd.outputs.count != 0
-        working-directory: lesson
         run: |
           while read -r cmd
           do
             eval sudo $cmd
-          done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "18.04"), sep = "\n")')
+          done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "20.04"), sep = "\n")')
+
+      - name: Render the markdown and confirm that the site can be built
+        run: make site
+
+      - name: Checkout github pages
+        if: ${{ github.event_name == 'push' && steps.check-rmd.outputs.count != 0 && github.ref != 'refs/heads/gh-pages'}}
+        uses: actions/checkout@master
+        with:
+          ref: gh-pages
+          path: gh-pages
+
+      - name: Commit and Push
+        if: ${{ github.event_name == 'push' && steps.check-rmd.outputs.count != 0 && github.ref != 'refs/heads/gh-pages'}}
+        run: |
+          # copy everything into gh-pages site
+          cp -r `ls -A | grep -v 'gh-pages' | grep -v '.git' | grep -v '.bundle/' | grep -v '_site'` gh-pages
+          # move into gh-pages, add, commit, and push
+          cd gh-pages
+          # setup git
+          git config --local user.email "actions@github.com"
+          git config --local user.name "GitHub Actions"
+          git add -A .
+          git commit --allow-empty -m "[Github Actions] render website (via ${{ github.sha }}"
+          git push origin gh-pages
+          # return
+          cd ..
 
-      - run: make site
-      - run: make lesson-check
-        if: always()
       - run: make lesson-check-all
         if: always()