include @zkamvar suggestions
[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-latest
12     env:
13       RSPM: "https://packagemanager.rstudio.com/cran/__linux__/bionic/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: Install needed packages
55         if: steps.check-rmd.outputs.count != 0
56         run: |
57           install.packages(c('remotes', 'rprojroot', 'renv', 'desc', 'rmarkdown', 'knitr'))
58         shell: Rscript {0}
59
60       - name: Query dependencies
61         if: steps.check-rmd.outputs.count != 0
62         run: |
63           source('bin/dependencies.R')
64           deps <- identify_dependencies()
65           create_description(deps)
66           saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
67           writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
68         shell: Rscript {0}
69
70       - name: Cache R packages
71         if: steps.check-rmd.outputs.count != 0
72         uses: actions/cache@v1
73         with:
74           path: ${{ env.R_LIBS_USER }}
75           key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
76           restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
77
78       - name: Install system dependencies for R packages
79         if: steps.check-rmd.outputs.count != 0
80         run: |
81           while read -r cmd
82           do
83             eval sudo $cmd
84           done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "18.04"), sep = "\n")')
85
86       - name: Render the markdown and confirm that the site can be built
87         run: make site
88
89       - name: Checkout github pages
90         if: ${{ github.event_name == 'push' && steps.check-rmd.outputs.count != 0 && github.ref != 'refs/heads/gh-pages'}}
91         uses: actions/checkout@master
92         with:
93           ref: gh-pages
94           path: gh-pages
95
96       - name: Commit and Push
97         if: ${{ github.event_name == 'push' && steps.check-rmd.outputs.count != 0 && github.ref != 'refs/heads/gh-pages'}}
98         run: |
99           # copy everything into gh-pages site
100           cp -r `ls -A | grep -v 'gh-pages' | grep -v '.git' | grep -v '.bundle/' | grep -v '_site'` gh-pages
101           # move into gh-pages, add, commit, and push
102           cd gh-pages
103           # setup git
104           git config --local user.email "actions@github.com"
105           git config --local user.name "GitHub Actions"
106           git add -A .
107           git commit --allow-empty -m "[Github Actions] render website (via ${{ github.sha }}"
108           git push origin gh-pages
109           # return
110           cd ..
111
112       - run: make lesson-check-all
113         if: always()