11name : Website
22on :
33 push :
4- branches : gh-pages
4+ branches :
5+ - gh-pages
6+ - main
57 pull_request : []
68jobs :
79 build-website :
8- if : github.repository != 'carpentries/styles' && (github.repository_owner == 'swcarpentry' || github.repository_owner == 'datacarpentry' || github.repository_owner == 'librarycarpentry' || github.repository_owner == 'carpentries')
9- runs-on : ubuntu-latest
10+ if : ${{ !endsWith(github.repository, '/styles') }}
11+ runs-on : ubuntu-20.04
12+ env :
13+ RSPM : " https://packagemanager.rstudio.com/cran/__linux__/focal/latest"
14+ GITHUB_PAT : ${{ secrets.GITHUB_TOKEN }}
1015 defaults :
1116 run :
1217 shell : bash
1318 steps :
1419 - name : Set up Ruby
15- uses : actions /setup-ruby@v1
20+ uses : ruby /setup-ruby@v1
1621 with :
1722 ruby-version : ' 2.7'
23+ bundler-cache : true
1824
1925 - name : Set up Python
2026 uses : actions/setup-python@v2
2329
2430 - name : Install GitHub Pages, Bundler, and kramdown gems
2531 run : |
26- gem install github-pages bundler kramdown
32+ gem install github-pages bundler kramdown kramdown-parser-gfm
2733
2834 - name : Install Python modules
2935 run : |
@@ -46,10 +52,19 @@ jobs:
4652 with :
4753 r-version : ' release'
4854
55+ - name : Cache R packages
56+ if : steps.check-rmd.outputs.count != 0
57+ uses : actions/cache@v1
58+ with :
59+ path : ${{ env.R_LIBS_USER }}
60+ key : ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
61+ restore-keys : ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
62+
4963 - name : Install needed packages
5064 if : steps.check-rmd.outputs.count != 0
5165 run : |
52- install.packages(c('remotes', 'rprojroot', 'renv', 'desc', 'rmarkdown', 'knitr'))
66+ packages = setdiff(c('remotes', 'rprojroot', 'renv', 'desc', 'rmarkdown', 'knitr'), rownames(installed.packages()))
67+ install.packages(packages, repo="https://cran.rstudio.com/")
5368 shell : Rscript {0}
5469
5570 - name : Query dependencies
@@ -62,24 +77,45 @@ jobs:
6277 writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
6378 shell : Rscript {0}
6479
65- - name : Cache R packages
66- if : steps.check-rmd.outputs.count != 0
67- uses : actions/cache@v1
68- with :
69- path : ${{ env.R_LIBS_USER }}
70- key : ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
71- restore-keys : ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
7280
7381 - name : Install system dependencies for R packages
7482 if : steps.check-rmd.outputs.count != 0
7583 run : |
7684 while read -r cmd
7785 do
7886 eval sudo $cmd
79- done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "18.04"), sep = "\n")')
87+ done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "20.04"), sep = "\n")')
88+
89+ - name : Render the markdown and confirm that the site can be built
90+ run : make site
91+
92+ - name : Checkout github pages
93+ if : ${{ github.event_name == 'push' && steps.check-rmd.outputs.count != 0 && github.ref != 'refs/heads/gh-pages'}}
94+ uses : actions/checkout@master
95+ with :
96+ ref : gh-pages
97+ path : gh-pages
98+
99+ - name : Commit and Push
100+ if : ${{ github.event_name == 'push' && steps.check-rmd.outputs.count != 0 && github.ref != 'refs/heads/gh-pages'}}
101+ run : |
102+ # clean up gh-pages
103+ cd gh-pages
104+ git rm -rf . # remove all previous files
105+ git restore --staged . # remove things from the stage
106+ cd ..
107+ # copy everything into gh-pages site
108+ cp -r `ls -A | grep -v 'gh-pages' | grep -v '.git' | grep -v '.bundle/' | grep -v '_site'` gh-pages
109+ # move into gh-pages, add, commit, and push
110+ cd gh-pages
111+ # setup git
112+ git config --local user.email "[email protected] " 113+ git config --local user.name "GitHub Actions"
114+ git add -A .
115+ git commit --allow-empty -m "[Github Actions] render website (via ${{ github.sha }})"
116+ git push origin gh-pages
117+ # return
118+ cd ..
80119
81- - run : make site
82- - run : make lesson-check
83- if : always()
84120 - run : make lesson-check-all
85121 if : always()
0 commit comments