From cf83fb32351bb680cf23a66a2e8fb23c94e6b353 Mon Sep 17 00:00:00 2001
From: chris48s <chris48s@users.noreply.github.com>
Date: Mon, 5 Sep 2022 21:00:20 +0100
Subject: [PATCH] migrate package tests to GHA (#8351)

migrate package tests to GHA
---
 .circleci/config.yml                     | 60 ------------------------
 .github/actions/package-tests/action.yml | 26 ++++++++++
 .github/workflows/test-package-cli.yml   | 44 +++++++++++++++++
 .github/workflows/test-package-lib.yml   | 32 +++++++++++++
 badge-maker/CHANGELOG.md                 |  2 +-
 badge-maker/package.json                 |  2 +-
 scripts/run_package_tests.sh             | 34 --------------
 7 files changed, 104 insertions(+), 96 deletions(-)
 create mode 100644 .github/actions/package-tests/action.yml
 create mode 100644 .github/workflows/test-package-cli.yml
 create mode 100644 .github/workflows/test-package-lib.yml
 delete mode 100755 scripts/run_package_tests.sh

diff --git a/.circleci/config.yml b/.circleci/config.yml
index d7c9574cb3..9ec5895ab7 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -47,56 +47,6 @@ services_steps: &services_steps
     - store_test_results:
         path: junit
 
-package_steps: &package_steps
-  steps:
-    - checkout
-
-    - run:
-        name: Install node and npm
-        command: |
-          set +e
-          export NVM_DIR="/opt/circleci/.nvm"
-          [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
-          nvm install v14
-          nvm use v14
-          npm install -g npm
-
-    # Run the package tests on each currently supported node version. See:
-    # https://github.com/badges/shields/blob/master/badge-maker/README.md#node-version-support
-    # https://nodejs.org/en/about/releases/
-
-    - run:
-        environment:
-          mocha_reporter: mocha-junit-reporter
-          MOCHA_FILE: junit/badge-maker/v12/results.xml
-          NODE_VERSION: v12
-          CYPRESS_INSTALL_BINARY: 0
-          NPM_CONFIG_ENGINE_STRICT: 'false'
-        name: Run package tests on Node 12
-        command: scripts/run_package_tests.sh
-
-    - run:
-        environment:
-          mocha_reporter: mocha-junit-reporter
-          MOCHA_FILE: junit/badge-maker/v14/results.xml
-          NODE_VERSION: v14
-          CYPRESS_INSTALL_BINARY: 0
-          NPM_CONFIG_ENGINE_STRICT: 'false'
-        name: Run package tests on Node 14
-        command: scripts/run_package_tests.sh
-
-    - run:
-        environment:
-          mocha_reporter: mocha-junit-reporter
-          MOCHA_FILE: junit/badge-maker/v16/results.xml
-          NODE_VERSION: v16
-          CYPRESS_INSTALL_BINARY: 0
-        name: Run package tests on Node 16
-        command: scripts/run_package_tests.sh
-
-    - store_test_results:
-        path: junit
-
 jobs:
   integration:
     docker:
@@ -172,12 +122,6 @@ jobs:
           when: always
           command: npm run build
 
-  package:
-    machine:
-      image: 'ubuntu-2004:202111-02'
-
-    <<: *package_steps
-
   services:
     docker:
       - image: cimg/node:16.15
@@ -249,10 +193,6 @@ workflows:
           filters:
             branches:
               ignore: gh-pages
-      - package:
-          filters:
-            branches:
-              ignore: gh-pages
       - services:
           filters:
             branches:
diff --git a/.github/actions/package-tests/action.yml b/.github/actions/package-tests/action.yml
new file mode 100644
index 0000000000..8ddedc3d09
--- /dev/null
+++ b/.github/actions/package-tests/action.yml
@@ -0,0 +1,26 @@
+name: 'Package tests'
+description: 'Run package tests and check types'
+runs:
+  using: 'composite'
+  steps:
+    - name: Tests
+      if: always()
+      run: npm run test:package -- --reporter json --reporter-option 'output=reports/package-tests.json'
+      shell: bash
+
+    - name: Type Checks
+      if: always()
+      run: |
+        set -o pipefail
+        npm run check-types:package 2>&1 | tee reports/package-types.txt
+      shell: bash
+
+    - name: Write Markdown Summary
+      if: always()
+      run: |
+        node scripts/mocha2md.js 'Package Tests' reports/package-tests.json >> $GITHUB_STEP_SUMMARY
+        echo '# Package Types' >> $GITHUB_STEP_SUMMARY
+        echo '```' >> $GITHUB_STEP_SUMMARY
+        cat reports/package-types.txt >> $GITHUB_STEP_SUMMARY
+        echo '```' >> $GITHUB_STEP_SUMMARY
+      shell: bash
diff --git a/.github/workflows/test-package-cli.yml b/.github/workflows/test-package-cli.yml
new file mode 100644
index 0000000000..082197020b
--- /dev/null
+++ b/.github/workflows/test-package-cli.yml
@@ -0,0 +1,44 @@
+name: Package CLI
+on:
+  pull_request:
+  push:
+    branches-ignore:
+      - 'gh-pages'
+
+# Smoke test (render a badge with the CLI) with only the package
+# dependencies installed.
+
+jobs:
+  test-package-cli:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        include:
+          - node: '14'
+            engine-strict: 'false'
+          - node: '16'
+            engine-strict: 'false'
+          - node: '18'
+            engine-strict: 'true'
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v3
+
+      - name: Install Node JS ${{ inputs.node-version }}
+        uses: actions/setup-node@v2
+        with:
+          node-version: ${{ matrix.node }}
+
+      - name: Install dependencies
+        env:
+          CYPRESS_INSTALL_BINARY: 0
+          NPM_CONFIG_ENGINE_STRICT: ${{ matrix.engine-strict }}
+        run: |
+          cd badge-maker
+          npm install
+          npm link
+
+      - name: Render a badge with the CLI
+        run: |
+          cd badge-maker
+          badge cactus grown :green @flat
diff --git a/.github/workflows/test-package-lib.yml b/.github/workflows/test-package-lib.yml
new file mode 100644
index 0000000000..aa733eb233
--- /dev/null
+++ b/.github/workflows/test-package-lib.yml
@@ -0,0 +1,32 @@
+name: Package Library
+on:
+  pull_request:
+  push:
+    branches-ignore:
+      - 'gh-pages'
+
+jobs:
+  test-package-lib:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        include:
+          - node: '14'
+            engine-strict: 'false'
+          - node: '16'
+            engine-strict: 'true'
+          - node: '18'
+            engine-strict: 'false'
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v3
+
+      - name: Setup
+        uses: ./.github/actions/setup
+        with:
+          node-version: ${{ matrix.node }}
+        env:
+          NPM_CONFIG_ENGINE_STRICT: ${{ matrix.engine-strict }}
+
+      - name: Package tests
+        uses: ./.github/actions/package-tests
diff --git a/badge-maker/CHANGELOG.md b/badge-maker/CHANGELOG.md
index 3cf6c3c37f..619785c230 100644
--- a/badge-maker/CHANGELOG.md
+++ b/badge-maker/CHANGELOG.md
@@ -2,7 +2,7 @@
 
 ## 4.0.0 [WIP]
 
-- Drop compatibility with Node 10
+- Drop compatibility with Node < 14
 
 ## 3.3.1
 
diff --git a/badge-maker/package.json b/badge-maker/package.json
index fc6702acb7..374ce54793 100644
--- a/badge-maker/package.json
+++ b/badge-maker/package.json
@@ -26,7 +26,7 @@
     "badge": "lib/badge-cli.js"
   },
   "engines": {
-    "node": ">= 12",
+    "node": ">= 14",
     "npm": ">= 6"
   },
   "collective": {
diff --git a/scripts/run_package_tests.sh b/scripts/run_package_tests.sh
deleted file mode 100755
index b83bd39c94..0000000000
--- a/scripts/run_package_tests.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/bash
-
-# https://discuss.circleci.com/t/switch-nodejs-version-on-machine-executor-solved/26675/3
-
-# Start off less strict to work around various nvm errors.
-set -e
-export NVM_DIR="/opt/circleci/.nvm"
-[ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh"
-nvm install $NODE_VERSION
-nvm use $NODE_VERSION
-
-# Stricter.
-set -euo pipefail
-node --version
-
-# Install the shields.io dependencies.
-npm ci
-
-# Run the package tests.
-npm run test:package
-npm run check-types:package
-
-# Delete the full shields.io dependency tree
-rm -rf node_modules/
-
-
-# Run a smoke test (render a badge with the CLI) with only the package
-# dependencies installed.
-cd badge-maker
-
-npm install # install only the package dependencies for this test
-npm link
-badge cactus grown :green @flat
-rm package-lock.json && rm -rf node_modules/ # clean up package dependencies
-- 
GitLab