deploy R-based lessons without using another action
[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       - run: make site
87
88       - name: Setup Git
89         if: ${{ steps.check-rmd.outputs.count != 0 }}
90         run: |
91           git config --local user.email "actions@github.com"
92           git config --local user.name "GitHub Actions"
93           git checkout --orphan gha-rendering
94
95       - name: Push site
96         if: ${{ github.event.push == 'true' && steps.check-rmd.outputs.count != 0 && github.ref == 'refs/heads/main' }}
97         run: |
98           rm -rf .bundle
99           git add --force .
100           git commit -m "[GitHub Actions] render website"
101           git push --force origin +gha-rendering:gh-pages
102
103       - run: make lesson-check
104         if: always()
105       - run: make lesson-check-all
106         if: always()