From 2049ebc394d617a2523b239d8a4e355b798fdd45 Mon Sep 17 00:00:00 2001
From: Matt Wang <matt@matthewwang.me>
Date: Fri, 22 Jul 2022 20:50:12 -0700
Subject: [PATCH] consolidate CI files, updates Ruby and Node versions (#820)

This is a PR with three key changes:

1. Consolidate two identical CI files, `ci.yml` and `ci-master.yml` into one file
2. Consolidate two almost-identical jobs (`jekyll-build-*`) into one job with a strategy matrix
3. Update various dependencies/platforms
    * Node: `12.x` -> `16.x` (only in CI); `12.x` has been EOL for a while
    * Ruby: `2.6` -> `2.7`; `2.6` just reached EOL
    * `actions/checkout` -> `v2` -> `v3`
    * switches `jekyll/builder` to `jekyll/jekyll`, since we don't actually use any of the features in `jekyll/builder`

## on our CI philosophy

In working on this, I have a couple of questions:

1. We don't actually use our `Dockerfile` that we provide. Does this make sense? Should we be running CI with this instead?
2. Is there a specific reason that we're using `jekyll/jekyll`? Notably, this isn't an official package, but a community-driven one. Does it match what's used by GitHub Pages?
3. Do we have to use any docker image at all? For example, what if we just rely on the `setup-ruby` action?
    * one advantage of this is that it's much easier for us to test across multiple OS versions; we just need to have a strategy matrix for OS and do windows, macos, ubuntu, etc.
    * another advantage is that we can easily test different ruby versions in conjunction with different jekyll versions

Eventually, I would like to see us test across:

* different Jekyll versions
* different OSes
* different Ruby versions

but perhaps that might be too aggressive. Happy for any feedback on this PR or those questions!
---
 .github/workflows/ci-master.yml | 42 -----------------------------
 .github/workflows/ci.yml        | 48 ++++++++++++++++-----------------
 Dockerfile                      |  3 +--
 README.md                       |  2 +-
 4 files changed, 25 insertions(+), 70 deletions(-)
 delete mode 100644 .github/workflows/ci-master.yml

diff --git a/.github/workflows/ci-master.yml b/.github/workflows/ci-master.yml
deleted file mode 100644
index 4f970d4c..00000000
--- a/.github/workflows/ci-master.yml
+++ /dev/null
@@ -1,42 +0,0 @@
-on:
-  push:
-    branches:
-      - main
-
-name: main branch CI
-
-jobs:
-  jekyll-latest:
-    name: Build Jekyll site (latest)
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@main
-
-      - name: Build the site in the jekyll/builder container
-        run: |
-          docker run --rm \
-          --volume="${{ github.workspace }}:/srv/jekyll" \
-          jekyll/builder:latest /bin/bash -c "gem install bundler && chmod -R 777 /srv/jekyll && bundle install && bundle exec jekyll build && bundle exec rake search:init"
-  jekyll-3-8-5:
-    name: Build Jekyll site (v3.8.5)
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@main
-
-      - name: Build the site in the jekyll/builder container
-        run: |
-          docker run --rm \
-          --volume="${{ github.workspace }}:/srv/jekyll" \
-          jekyll/builder:3.8.5 /bin/bash -c "gem install bundler && chmod -R 777 /srv/jekyll && bundle install && bundle exec jekyll build && bundle exec rake search:init"
-  assets:
-    name: Format and test CSS and JS
-    runs-on: ubuntu-latest
-
-    steps:
-      - uses: actions/checkout@v2
-      - name: Use Node.js 12.x
-        uses: actions/setup-node@v1
-        with:
-          node-version: "12.x"
-      - run: npm install
-      - run: npm test
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 3fb78091..4eaa17d9 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,44 +1,42 @@
-on: [pull_request]
+on:
+  push:
+    branches:
+      - main
+  pull_request:
+    branches:
+      - main
+      - 'v**'
 
 name: CI
 
 jobs:
-
-  jekyll-latest:
-    name: Build Jekyll site (latest)
-    runs-on: ubuntu-latest
-    steps:
-
-    - uses: actions/checkout@v2
-
-    - name: Build the site in the jekyll/builder container
-      run: |
-        docker run --rm \
-        --volume="${{ github.workspace }}:/srv/jekyll" \
-        jekyll/builder:latest /bin/bash -c "gem install bundler && chmod -R 777 /srv/jekyll && bundle install && bundle exec jekyll build && bundle exec rake search:init"
-
-  jekyll-3-8-5:
-    name: Build Jekyll site (v3.8.5)
+  jekyll-build:
+    name: Build Jekyll site
     runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        jekyll-version: [3.8.5, latest]
     steps:
-
-    - uses: actions/checkout@v2
-
-    - name: Build the site in the jekyll/builder container
+    - uses: actions/checkout@v3
+    - name: Build the site in the jekyll/jekyll container
       run: |
         docker run --rm \
         --volume="${{ github.workspace }}:/srv/jekyll" \
-        jekyll/builder:3.8.5 /bin/bash -c "gem install bundler && chmod -R 777 /srv/jekyll && bundle install && bundle exec jekyll build && bundle exec rake search:init"
+        jekyll/jekyll:${{ matrix.jekyll-version }} /bin/bash -c "gem install bundler && chmod -R 777 /srv/jekyll && bundle install && bundle exec jekyll build && bundle exec rake search:init"
 
   assets:
     name: Test CSS and JS
     runs-on: ubuntu-latest
 
+    strategy:
+      matrix:
+        node-version: [16.x]
+
     steps:
-    - uses: actions/checkout@v2
-    - name: Use Node.js 12.x
+    - uses: actions/checkout@v3
+    - name: Use Node.js ${{ matrix.node-version }}
       uses: actions/setup-node@v1
       with:
-        node-version: '12.x'
+        node-version: ${{ matrix.node-version }}
     - run: npm install
     - run: npm test
diff --git a/Dockerfile b/Dockerfile
index 5f0ddaeb..a499513b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM ruby:2.6
+FROM ruby:2.7
 
 ENV LC_ALL C.UTF-8
 ENV LANG en_US.UTF-8
@@ -10,4 +10,3 @@ COPY Gemfile just-the-docs.gemspec ./
 RUN gem install bundler && bundle install
 
 EXPOSE 4000
-
diff --git a/README.md b/README.md
index 30665abc..43775d10 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
 <p align="right">
-    <a href="https://badge.fury.io/rb/just-the-docs"><img src="https://badge.fury.io/rb/just-the-docs.svg" alt="Gem version"></a> <a href="https://github.com/just-the-docs/just-the-docs/actions?query=workflow%3A%22main+branch+CI%22"><img src="https://github.com/just-the-docs/just-the-docs/workflows/main%20branch%20CI/badge.svg" alt="Build status"></a> <a href="https://app.netlify.com/sites/just-the-docs/deploys"><img src="https://api.netlify.com/api/v1/badges/9dc0386d-c2a4-4077-ad83-f02c33a6c0ca/deploy-status" alt="Netlify Status"></a>
+    <a href="https://badge.fury.io/rb/just-the-docs"><img src="https://badge.fury.io/rb/just-the-docs.svg" alt="Gem version"></a> <a href="https://github.com/just-the-docs/just-the-docs/actions/workflows/ci.yml"><img src="https://github.com/just-the-docs/just-the-docs/actions/workflows/ci.yml/badge.svg" alt="CI Build status"></a> <a href="https://app.netlify.com/sites/just-the-docs/deploys"><img src="https://api.netlify.com/api/v1/badges/9dc0386d-c2a4-4077-ad83-f02c33a6c0ca/deploy-status" alt="Netlify Status"></a>
 </p>
 <br><br>
 <p align="center">
-- 
GitLab