add missing parenthesis
[rnaseq-cwl-training.git] / .github / workflows / website.yml
1 name: Website
2 on:
3   push:
4     branches:
5       - gh-pages
6       - main
7   pull_request: []
8 jobs:
9   build-website:
10     if: ${{ !endsWith(github.repository, '/styles') }}
11     runs-on: ubuntu-20.04
12     env:
13       RSPM: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"
14       GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
15     defaults:
16       run:
17         shell: bash
18     steps:
19       - name: Set up Ruby
20         uses: actions/setup-ruby@v1
21         with:
22           ruby-version: '2.7'
23
24       - name: Set up Python
25         uses: actions/setup-python@v2
26         with:
27           python-version: '3.x'
28
29       - name: Install GitHub Pages, Bundler, and kramdown gems
30         run: |
31           gem install github-pages bundler kramdown
32
33       - name: Install Python modules
34         run: |
35           python3 -m pip install --upgrade pip setuptools wheel pyyaml==5.3.1 requests
36
37       - name: Checkout the lesson
38         uses: actions/checkout@master
39         with:
40           fetch-depth: 0
41           ref: ${{ github.event.pull_request.head.sha }}
42
43       - name: Look for R-markdown files
44         id: check-rmd
45         run: |
46           echo "::set-output name=count::$(shopt -s nullglob; files=($(find . -iname '*.Rmd')); echo ${#files[@]})"
47
48       - name: Set up R
49         if: steps.check-rmd.outputs.count != 0
50         uses: r-lib/actions/setup-r@master
51         with:
52           r-version: 'release'
53
54       - name: Cache R packages
55         if: steps.check-rmd.outputs.count != 0
56         uses: actions/cache@v1
57         with:
58           path: ${{ env.R_LIBS_USER }}
59           key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
60           restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
61
62       - name: Install needed packages
63         if: steps.check-rmd.outputs.count != 0
64         run: |
65           install.packages(setdiff(c('remotes', 'rprojroot', 'renv', 'desc', 'rmarkdown', 'knitr'), rownames(installed.packages())))
66         shell: Rscript {0}
67
68       - name: Query dependencies
69         if: steps.check-rmd.outputs.count != 0
70         run: |
71           source('bin/dependencies.R')
72           deps <- identify_dependencies()
73           create_description(deps)
74           saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
75           writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
76         shell: Rscript {0}
77
78
79       - name: Install system dependencies for R packages
80         if: steps.check-rmd.outputs.count != 0
81         run: |
82           while read -r cmd
83           do
84             eval sudo $cmd
85           done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "20.04"), sep = "\n")')
86
87       - name: Render the markdown and confirm that the site can be built
88         run: make site
89
90       - name: Checkout github pages
91         if: ${{ github.event_name == 'push' && steps.check-rmd.outputs.count != 0 && github.ref != 'refs/heads/gh-pages'}}
92         uses: actions/checkout@master
93         with:
94           ref: gh-pages
95           path: gh-pages
96
97       - name: Commit and Push
98         if: ${{ github.event_name == 'push' && steps.check-rmd.outputs.count != 0 && github.ref != 'refs/heads/gh-pages'}}
99         run: |
100           # copy everything into gh-pages site
101           cp -r `ls -A | grep -v 'gh-pages' | grep -v '.git' | grep -v '.bundle/' | grep -v '_site'` gh-pages
102           # move into gh-pages, add, commit, and push
103           cd gh-pages
104           # setup git
105           git config --local user.email "actions@github.com"
106           git config --local user.name "GitHub Actions"
107           git add -A .
108           git commit --allow-empty -m "[Github Actions] render website (via ${{ github.sha }}"
109           git push origin gh-pages
110           # return
111           cd ..
112
113       - run: make lesson-check-all
114         if: always()