Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/NodeCG-CI #327

Merged
merged 4 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,49 @@ jobs:
- name: Run tests
run: npm run coverage -- --verbose

nodecg:
# This test runs with the current version of NodeCG as defined by the
# nodecg-cli. It checks if all bundles (only core, services, samples)
# are mounted by NodeCG. It will fail if one of them is not mounted.
# You may check for other NodeCG runtime errors in the output (these
# may not fail the run).
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v2
with:
node-version: "16"

- name: Install nodecg-cli
run: npm install --global nodecg-cli

- name: Setup NodeCG
run: nodecg setup

- name: Setup NodeCG config
run: |
mkdir cfg
echo '{"bundles": {"paths": ["'${GITHUB_WORKSPACE}'/nodecg-io","'${GITHUB_WORKSPACE}'/nodecg-io/services","'${GITHUB_WORKSPACE}'/nodecg-io/samples"]}}' > ./cfg/nodecg.json

# nodecg-io needs to be cloned after NodeCG setup because the nodecg-cli requires an empty directory.
- uses: actions/checkout@v2
with:
path: "nodecg-io"

- name: Install system dependencies
run: sudo apt update && sudo apt-get -y install libusb-1.0-0-dev libasound2-dev libudev-dev

- name: Install nodejs dependencies
run: npm ci
working-directory: ./nodecg-io

- name: Build Typescript
run: npm run build
working-directory: ./nodecg-io

- name: Run test
run: node .scripts/ci-nodecg-integration.mjs
working-directory: ./nodecg-io

publish:
runs-on: ubuntu-latest
name: Publish compilation results
Expand All @@ -57,6 +100,7 @@ jobs:
needs:
- build
- tests
- nodecg
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand Down
75 changes: 75 additions & 0 deletions .scripts/ci-nodecg-integration.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import * as fs from "fs";
import * as path from "path";
import * as child_process from "child_process";

const cwd = path.parse(process.cwd());
const nodecgiodir = fs.readdirSync(process.cwd()).some((v) => v === "nodecg-io-core");

// Check if we are in the nodecg-io folder because we use relative paths later on.
if (!nodecgiodir) {
throw new Error("You will have to run this script from inside the nodecg-io folder!");
}
/**
* expected data:
*
* ~~~json
* {
* name: 'nodecg-io',
* dependencies: {
* 'name': {
* version: 'version',
* resolved: 'optional'
* },
* }
* }
* ~~~
*/
const npm = JSON.parse(child_process.execSync("npm ls --json"));

// Filter out any dependencies which are not resolved locally in samples or services because the other npm packages will not be loaded by NodeCG
let bundles = Object.entries(npm.dependencies)
.filter((i) =>
Object.entries(i[1]).some(
(j) =>
j[0] === "resolved" &&
(`${j[1]}`.startsWith("file:../samples/") ||
`${j[1]}`.startsWith("file:../services/" || `${j[1]}` === "file:../nodecg-io-core")),
),
)
.map((v) => v[0]);

console.log(`Found ${bundles.length} bundles in this install.`);

console.log("");
console.log("NodeCG sterr");
console.log("--------------------------------------------------------------------------------");

// expects a NodeCG folder be the parent of the cwd needs timeout
const log = child_process
.execSync("timeout --preserve-status 15s node " + cwd.dir + path.sep + "index.js", { cwd: cwd.dir })
.toString("utf8");

const lines = log.split("\n");


// Try to find each bundle in the logs.
const missing = bundles.filter(
/*Using endsWith here to remove possible ansi styling of "[info]" caused by ModeCG's logger when run locally*/
(i) => !lines.some((j) => j.endsWith("[nodecg/lib/server/extensions] Mounted " + i + " extension")),
);

// Fail the run if there are missing bundles.
if (missing.length > 0) {
// Only log stout if the run has failed because otherwise its unimportant and everything important should be in stderr
console.log("");
console.log("NodeCG stout");
console.log("--------------------------------------------------------------------------------");
console.log(log);

console.log("");
console.log("Missing Bundles");
console.log("--------------------------------------------------------------------------------");
console.log(missing);

throw new Error(`NodeCG did not mount ${missing.length} bundle(s).`);
}