13f03bcf8b937c159513b823c75fa9d3997cc4a1
[rnaseq-cwl-training.git] / .github / workflows / template.yml
1 name: Template
2 on:
3   push:
4     branches: gh-pages
5   pull_request:
6 jobs:
7   check-template:
8     name: Test lesson template
9     if: github.repository == 'carpentries/styles'
10     runs-on: ${{ matrix.os }}
11     strategy:
12       fail-fast: false
13       matrix:
14         lesson: [swcarpentry/shell-novice, datacarpentry/r-intro-geospatial, librarycarpentry/lc-git]
15         os: [ubuntu-latest, macos-latest, windows-latest]
16     defaults:
17       run:
18         shell: bash # forces 'Git for Windows' on Windows
19     env:
20       RSPM: 'https://packagemanager.rstudio.com/cran/__linux__/bionic/latest'
21     steps:
22       - name: Set up Ruby
23         uses: actions/setup-ruby@main
24         with:
25           ruby-version: '2.7.1'
26
27       - name: Set up Python
28         uses: actions/setup-python@v2
29         with:
30           python-version: '3.x'
31
32       - name: Install GitHub Pages, Bundler, and kramdown gems
33         run: |
34           gem install github-pages bundler kramdown
35
36       - name: Install Python modules
37         run: |
38           if [[ $RUNNER_OS == macOS || $RUNNER_OS == Linux ]]; then
39             python3 -m pip install --upgrade pip setuptools wheel pyyaml==5.3.1 requests
40           elif [[ $RUNNER_OS == Windows ]]; then
41             python -m pip install --upgrade pip setuptools wheel pyyaml==5.3.1 requests
42           fi
43
44       - name: Checkout the ${{ matrix.lesson }} lesson
45         uses: actions/checkout@master
46         with:
47           repository: ${{ matrix.lesson }}
48           path: lesson
49           fetch-depth: 0
50
51       - name: Determine the proper reference to use
52         id: styles-ref
53         run: |
54           if [[ -n "${{ github.event.pull_request.number }}" ]]; then
55             echo "::set-output name=ref::refs/pull/${{ github.event.pull_request.number }}/head"
56           else
57             echo "::set-output name=ref::gh-pages"
58           fi
59
60       - name: Sync lesson with carpentries/styles
61         working-directory: lesson
62         run: |
63           git config --global user.email "team@carpentries.org"
64           git config --global user.name "The Carpentries Bot"
65           git remote add styles https://github.com/carpentries/styles.git
66           git config --local remote.styles.tagOpt --no-tags
67           git fetch styles ${{ steps.styles-ref.outputs.ref }}:styles-ref
68           git merge -s recursive -Xtheirs --no-commit styles-ref
69           git commit -m "Sync lesson with carpentries/styles"
70
71       - name: Look for R-markdown files
72         id: check-rmd
73         working-directory: lesson
74         run: |
75           echo "::set-output name=count::$(shopt -s nullglob; files=($(find . -iname '*.Rmd')); echo ${#files[@]})"
76
77       - name: Set up R
78         if: steps.check-rmd.outputs.count != 0
79         uses: r-lib/actions/setup-r@master
80         with:
81           r-version: 'release'
82
83       - name: Install needed packages
84         if: steps.check-rmd.outputs.count != 0
85         run: |
86           install.packages(c('remotes', 'rprojroot', 'renv', 'desc', 'rmarkdown', 'knitr'))
87         shell: Rscript {0}
88
89       - name: Query dependencies
90         if: steps.check-rmd.outputs.count != 0
91         working-directory: lesson
92         run: |
93           source('bin/dependencies.R')
94           deps <- identify_dependencies()
95           create_description(deps)
96           saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
97           writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
98         shell: Rscript {0}
99
100       - name: Cache R packages
101         if: runner.os != 'Windows' && steps.check-rmd.outputs.count != 0
102         uses: actions/cache@v1
103         with:
104           path: ${{ env.R_LIBS_USER }}
105           key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
106           restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
107
108       - name: Install system dependencies for R packages
109         if: runner.os == 'Linux' && steps.check-rmd.outputs.count != 0
110         working-directory: lesson
111         run: |
112           while read -r cmd
113           do
114             eval sudo $cmd
115           done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "18.04"), sep = "\n")')
116
117       - run: make site
118         working-directory: lesson