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