Skip to content

Commit

Permalink
Tweak CI
Browse files Browse the repository at this point in the history
  • Loading branch information
henriqueinonhe committed Nov 26, 2023
1 parent eb6e440 commit 07c8d34
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 33 deletions.
50 changes: 21 additions & 29 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ concurrency:
cancel-in-progress: true

jobs:
e2e:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
get-node-version:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Get Node Version
id: get-node-version
Expand All @@ -28,33 +24,29 @@ jobs:
# breaks the github action that consumes this data
run: echo node-version=$(cat package.json | jq ".engines.node" | sed 's/^"\(.*\)"$/\1/') >> $GITHUB_OUTPUT

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ steps.get-node-version.outputs.node-version }}
outputs:
node-version: ${{ steps.get-node-version.outputs.node-version }}

- name: Get Node Modules Cache Key
id: get-node-modules-cache-key
run: echo cache-key=${{ matrix.os }}-${{ hashFiles('package-lock.json') }} >> $GITHUB_OUTPUT
e2e:
needs:
- get-node-version
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v3
- name: Setup Node
uses: actions/setup-node@v4
with:
key: ${{ steps.get-node-modules-cache-key.outputs.cache-key }}
path: node_modules
lookup-only: true
node-version: ${{ needs.get-node-version.outputs.node-version }}
cache: "npm"

- name: Install Dependencies
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
run: npm install

- name: Restore Node Modules
uses: actions/cache/restore@v3
with:
key: ${{ steps.get-node-modules-cache-key.outputs.cache-key }}
path: node_modules
fail-on-cache-miss: true
run: npm ci

- name: Run E2E Tests
run: npm run e2e
36 changes: 32 additions & 4 deletions scripts/e2eTest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execSync } from "node:child_process";
import { execSync, spawn } from "node:child_process";
import tar from "tar";
import { mkdir, readFile, readdir, copyFile, rm } from "fs/promises";

Expand All @@ -10,11 +10,15 @@ const run = (...args: Parameters<typeof execSync>) => {

const main = async () => {
run("npm run prepublishOnly");

// Simulates publishing to npm
// and includes only the files that would be published
run("npm pack");

await mkdir("e2e");

await extractPackage();

if (process.env.CI === "true") {
run(`git config --global user.email "[email protected]"`, {
cwd: "e2e",
Expand All @@ -23,16 +27,19 @@ const main = async () => {
cwd: "e2e",
});
}
run("echo ./installation | ./package/bin.js", {
cwd: "e2e",
});

await install();

run("npm run postpublish");

await Promise.all(
["graph", "concrete", "foundation"].map(copyExerciseAnswers)
);

run("npm run check -- --run", {
cwd: "e2e/installation",
});

rm("e2e", { recursive: true, force: true });
};

Expand All @@ -50,6 +57,27 @@ const extractPackage = async () => {
});
};

const install = async () => {
// For some reason piping stuff with echo
// doesn't work properly with Windows

const process = spawn("node ./package/bin.js", {
stdio: ["pipe", "inherit", "inherit"],
cwd: "e2e",
shell: true,
});

await new Promise((resolve) => {
process.on("spawn", resolve);
});

process.stdin.write("installation\n");

await new Promise((resolve) => {
process.on("exit", resolve);
});
};

const copyExerciseAnswers = async (category: string) => {
const exercises = await readdir(`./src/exercises/${category}`);

Expand Down

0 comments on commit 07c8d34

Please sign in to comment.