|
| 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 | + continue-on-error: ${{ matrix.experimental }} |
| 12 | + strategy: |
| 13 | + fail-fast: false |
| 14 | + matrix: |
| 15 | + lesson: [swcarpentry/shell-novice, datacarpentry/r-intro-geospatial, librarycarpentry/lc-git] |
| 16 | + os: [ubuntu-20.04, macos-latest, windows-latest] |
| 17 | + experimental: [false] |
| 18 | + include: |
| 19 | + - os: ubuntu-20.04 |
| 20 | + os-name: Linux |
| 21 | + - os: macos-latest |
| 22 | + os-name: macOS |
| 23 | + - os: windows-latest |
| 24 | + os-name: Windows |
| 25 | + - lesson: swcarpentry/shell-novice |
| 26 | + lesson-name: (SWC) Shell novice |
| 27 | + - lesson: datacarpentry/r-intro-geospatial |
| 28 | + lesson-name: (DC) R Intro Geospatial |
| 29 | + - lesson: librarycarpentry/lc-git |
| 30 | + lesson-name: (LC) Intro to Git |
| 31 | + - lesson: datacarpentry/astronomy-python |
| 32 | + lesson-name: (DC) Foundations of Astronomical Data Science |
| 33 | + experimental: true |
| 34 | + os: ubuntu-20.04 |
| 35 | + os-name: Linux |
| 36 | + - lesson: carpentries/lesson-example |
| 37 | + lesson-name: (CP) Lesson Example |
| 38 | + experimental: false |
| 39 | + os: ubuntu-20.04 |
| 40 | + os-name: Linux |
| 41 | + defaults: |
| 42 | + run: |
| 43 | + shell: bash # forces 'Git for Windows' on Windows |
| 44 | + env: |
| 45 | + RSPM: 'https://packagemanager.rstudio.com/cran/__linux__/focal/latest' |
| 46 | + steps: |
| 47 | + - name: Set up Ruby |
| 48 | + uses: ruby/setup-ruby@v1 |
| 49 | + with: |
| 50 | + ruby-version: '3.0' |
| 51 | + bundler-cache: true |
| 52 | + |
| 53 | + - name: Set up Python |
| 54 | + uses: actions/setup-python@v2 |
| 55 | + with: |
| 56 | + python-version: '3.x' |
| 57 | + |
| 58 | + - name: Install GitHub Pages, Bundler, and kramdown gems |
| 59 | + run: | |
| 60 | + gem install github-pages bundler kramdown kramdown-parser-gfm |
| 61 | +
|
| 62 | + - name: Install Python modules |
| 63 | + run: | |
| 64 | + if [[ $RUNNER_OS == macOS || $RUNNER_OS == Linux ]]; then |
| 65 | + python3 -m pip install --upgrade pip setuptools wheel pyyaml==5.3.1 requests |
| 66 | + elif [[ $RUNNER_OS == Windows ]]; then |
| 67 | + python -m pip install --upgrade pip setuptools wheel pyyaml==5.3.1 requests |
| 68 | + fi |
| 69 | +
|
| 70 | + - name: Checkout the ${{ matrix.lesson }} lesson |
| 71 | + uses: actions/checkout@master |
| 72 | + with: |
| 73 | + repository: ${{ matrix.lesson }} |
| 74 | + path: lesson |
| 75 | + fetch-depth: 0 |
| 76 | + |
| 77 | + - name: Sync lesson with carpentries/styles |
| 78 | + working-directory: lesson |
| 79 | + run: | |
| 80 | + echo "::group::Fetch Styles" |
| 81 | + if [[ -n "${{ github.event.pull_request.number }}" ]] |
| 82 | + then |
| 83 | + ref="refs/pull/${{ github.event.pull_request.number }}/head" |
| 84 | + else |
| 85 | + ref="gh-pages" |
| 86 | + fi |
| 87 | +
|
| 88 | + git config --global user.email "team@carpentries.org" |
| 89 | + git config --global user.name "The Carpentries Bot" |
| 90 | +
|
| 91 | + git remote add styles https://github.com/carpentries/styles.git |
| 92 | + git fetch styles $ref:styles-ref |
| 93 | + echo "::endgroup::" |
| 94 | + echo "::group::Synchronize Styles" |
| 95 | + # Sync up only if necessary |
| 96 | + if [[ $(git rev-list --count HEAD..styles-ref) != 0 ]] |
| 97 | + then |
| 98 | +
|
| 99 | + # The merge command below might fail for lessons that use remote theme |
| 100 | + # https://github.com/carpentries/carpentries-theme |
| 101 | + echo "Testing merge using recursive strategy, accepting upstream changes without committing" |
| 102 | + if ! git merge -s recursive -Xtheirs --no-commit styles-ref |
| 103 | + then |
| 104 | +
|
| 105 | + # Remove "deleted by us, unmerged" files from the staging area. |
| 106 | + # these are the files that were removed from the lesson |
| 107 | + # but are still present in the carpentries/styles repo |
| 108 | + echo "Removing previously deleted files" |
| 109 | + git rm $(git diff --name-only --diff-filter=DU) |
| 110 | +
|
| 111 | + # If there are still "unmerged" files, |
| 112 | + # let's raise an error and look into this more closely |
| 113 | + if [[ -n $(git diff --name-only --diff-filter=U) ]] |
| 114 | + then |
| 115 | + echo "There were unmerged files in ${{ matrix.lesson-name }}:" |
| 116 | + echo "$(git diff --compact-summary --diff-filter=U)" |
| 117 | + exit 1 |
| 118 | + fi |
| 119 | + fi |
| 120 | +
|
| 121 | + echo "Committing changes" |
| 122 | + git commit -m "Sync lesson with carpentries/styles" |
| 123 | + fi |
| 124 | + echo "::endgroup::" |
| 125 | +
|
| 126 | + - name: Look for R-markdown files |
| 127 | + id: check-rmd |
| 128 | + working-directory: lesson |
| 129 | + run: | |
| 130 | + echo "count=$(shopt -s nullglob; files=($(find . -iname '*.Rmd')); echo ${#files[@]})" >> $GITHUB_OUTPUT |
| 131 | +
|
| 132 | + - name: Set up R |
| 133 | + if: steps.check-rmd.outputs.count != 0 |
| 134 | + uses: r-lib/actions/setup-r@v2 |
| 135 | + with: |
| 136 | + use-public-rspm: true |
| 137 | + install-r: false |
| 138 | + |
| 139 | + - name: Install needed packages |
| 140 | + if: steps.check-rmd.outputs.count != 0 |
| 141 | + working-directory: lesson |
| 142 | + run: | |
| 143 | + source('bin/dependencies.R') |
| 144 | + install_required_packages(.libPaths()[1]) |
| 145 | + shell: Rscript {0} |
| 146 | + |
| 147 | + - name: Query dependencies |
| 148 | + if: steps.check-rmd.outputs.count != 0 |
| 149 | + working-directory: lesson |
| 150 | + run: | |
| 151 | + source('bin/dependencies.R') |
| 152 | + deps <- identify_dependencies() |
| 153 | + create_description(deps) |
| 154 | + use_bioc_repos() |
| 155 | + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) |
| 156 | + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") |
| 157 | + shell: Rscript {0} |
| 158 | + |
| 159 | + - name: Restore Package Cache |
| 160 | + if: runner.os != 'Windows' && steps.check-rmd.outputs.count != 0 |
| 161 | + uses: actions/cache@v2 |
| 162 | + with: |
| 163 | + path: ${{ env.R_LIBS_USER }} |
| 164 | + key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} |
| 165 | + restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- |
| 166 | + |
| 167 | + - name: Install stringi from source |
| 168 | + if: runner.os == 'Linux' && steps.check-rmd.outputs.count != 0 |
| 169 | + run: install.packages('stringi', repos='https://cloud.r-project.org') |
| 170 | + shell: Rscript {0} |
| 171 | + |
| 172 | + - name: Install system dependencies for R packages |
| 173 | + if: runner.os == 'Linux' && steps.check-rmd.outputs.count != 0 |
| 174 | + working-directory: lesson |
| 175 | + run: | |
| 176 | + while read -r cmd |
| 177 | + do |
| 178 | + eval sudo $cmd || echo "Nothing to update" |
| 179 | + done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "20.04"), sep = "\n")') |
| 180 | +
|
| 181 | + - run: make site |
| 182 | + working-directory: lesson |
| 183 | + |
| 184 | + - run: make lesson-check-all |
| 185 | + working-directory: lesson |
0 commit comments