GitHub Actions: check lesson template (#489)
[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     steps:
20       - name: Set up Ruby
21         uses: actions/setup-ruby@main
22         with:
23           ruby-version: '2.7.1'
24
25       - name: Set up Python
26         uses: actions/setup-python@v2
27         with:
28           python-version: '3.x'
29
30       - name: Install GitHub Pages, Bundler, and kramdown gems
31         run: |
32           gem install github-pages bundler kramdown
33
34       - name: Install Python modules
35         run: |
36           if [[ $RUNNER_OS == macOS || $RUNNER_OS == Linux ]]; then
37             python3 -m pip install --upgrade pip setuptools wheel pyyaml==5.3.1 requests
38           elif [[ $RUNNER_OS == Windows ]]; then
39             python -m pip install --upgrade pip setuptools wheel pyyaml==5.3.1 requests
40           fi
41
42       - name: Checkout the ${{ matrix.lesson }} lesson
43         uses: actions/checkout@master
44         with:
45           repository: ${{ matrix.lesson }}
46           path: lesson
47           fetch-depth: 0
48
49       - name: Look for R-markdown files
50         id: check-rmd
51         working-directory: lesson
52         run: |
53           echo "::set-output name=count::$(shopt -s nullglob; files=($(find . -iname '*.Rmd')); echo ${#files[@]})"
54
55       - name: Set up R
56         if: steps.check-rmd.outputs.count != 0
57         uses: r-lib/actions/setup-r@master
58         with:
59           r-version: 'release'
60
61       - name: Install needed packages
62         if: steps.check-rmd.outputs.count != 0
63         run: |
64           install.packages(c('remotes', 'rprojroot', 'renv', 'desc'))
65         shell: Rscript {0}
66
67       - name: Query dependencies
68         if: steps.check-rmd.outputs.count != 0
69         working-directory: lesson
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       - name: Cache R packages
79         if: runner.os != 'Windows' && steps.check-rmd.outputs.count != 0
80         uses: actions/cache@v1
81         with:
82           path: ${{ env.R_LIBS_USER }}
83           key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
84           restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
85
86       - name: Install system dependencies for R packages
87         if: runner.os == 'Linux' && steps.check-rmd.outputs.count != 0
88         working-directory: lesson
89         run: |
90           while read -r cmd
91           do
92             eval $cmd
93           done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "18.04"), sep = "\n")')
94
95       - name: Install R lessons package dependencies
96         if: steps.check-rmd.outputs.count != 0
97         working-directory: lesson
98         run: |
99           remotes::install_deps(dependencies = TRUE)
100           file.remove("DESCRIPTION")
101         shell: Rscript {0}
102
103       - name: Determine the proper reference to use
104         id: styles-ref
105         run: |
106           if [[ -n "${{ github.event.pull_request.number }}" ]]; then
107             echo "::set-output name=ref::refs/pull/${{ github.event.pull_request.number }}/head"
108           else
109             echo "::set-output name=ref::gh-pages"
110           fi
111
112       - name: Sync lesson with carpentries/styles
113         working-directory: lesson
114         run: |
115           git config --global user.email "team@carpentries.org"
116           git config --global user.name "The Carpentries Bot"
117           git remote add styles https://github.com/carpentries/styles.git
118           git config --local remote.styles.tagOpt --no-tags
119           git fetch styles ${{ steps.styles-ref.outputs.ref }}:styles-ref
120           git merge -s recursive -Xtheirs --no-commit styles-ref
121           git commit -m "Sync lesson with carpentries/styles"
122
123       - run: make site
124         working-directory: lesson