From bd6e95390bbf0037d36583c9b9a745fe4c6dbc85 Mon Sep 17 00:00:00 2001 From: Kevin Traini Date: Mon, 15 Jul 2024 21:45:20 +0200 Subject: [PATCH] feat: Add first test workflow Part of #2 --- .github/workflows/tests.yml | 44 +++++++++++++++++++++++++++++++++++++ tools/ci/.gitignore | 1 + tools/ci/generate_matrix.js | 16 ++++++++++++++ tools/nix/default.nix | 1 + tools/nix/pinned-nodejs.nix | 5 +++++ 5 files changed, 67 insertions(+) create mode 100644 .github/workflows/tests.yml create mode 100644 tools/ci/.gitignore create mode 100644 tools/ci/generate_matrix.js create mode 100644 tools/nix/pinned-nodejs.nix diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..a8cdbe2 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,44 @@ +name: Tests + +on: + push: + branches: + - master + pull_request: + +jobs: + configure: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - uses: actions/checkout@v4 + + - name: Install Nix + uses: cachix/install-nix-action@v27 + - name: Build matrix json + uses: workflow/nix-shell-action@v3 + with: + script: | + node ./tools/ci/generate_matrix.js + + - name: Set matrix data + id: set-matrix + run: echo "matrix=$(jq -c . < ./tools/ci/workflow-matrix.json)" >> $GITHUB_OUTPUT + + build: + name: Build & Run + needs: configure + strategy: + matrix: ${{ fromJson(needs.configure.outputs.matrix) }} + runs-on: ${{ matrix.include.runner }} + steps: + - uses: actions/checkout@v4 + + - name: Install Nix + uses: cachix/install-nix-action@v27 + - name: Build then run + uses: workflow/nix-shell-action@v3 + with: + script: | + bazel run //:filc diff --git a/tools/ci/.gitignore b/tools/ci/.gitignore new file mode 100644 index 0000000..9d117c5 --- /dev/null +++ b/tools/ci/.gitignore @@ -0,0 +1 @@ +workflow-matrix.json \ No newline at end of file diff --git a/tools/ci/generate_matrix.js b/tools/ci/generate_matrix.js new file mode 100644 index 0000000..9d8a90b --- /dev/null +++ b/tools/ci/generate_matrix.js @@ -0,0 +1,16 @@ +const fs = require("node:fs"); + +const OUTPUT_FILE = __dirname + "/workflow-matrix.json"; + +const runners = ["ubuntu-latest", "macos-latest", "windows-latest"]; + +let result = []; + +for (let runner of runners) { + result.push({ + runner, + }); +} + +fs.writeFileSync(OUTPUT_FILE, JSON.stringify({include: result})); + diff --git a/tools/nix/default.nix b/tools/nix/default.nix index 8da5a10..5605179 100644 --- a/tools/nix/default.nix +++ b/tools/nix/default.nix @@ -3,4 +3,5 @@ [ (import ./pinned-bazel.nix { inherit pkgs; }) (import ./pinned-clang.nix { inherit pkgs; }) + (import ./pinned-nodejs.nix { inherit pkgs; }) ] diff --git a/tools/nix/pinned-nodejs.nix b/tools/nix/pinned-nodejs.nix new file mode 100644 index 0000000..a8c42cc --- /dev/null +++ b/tools/nix/pinned-nodejs.nix @@ -0,0 +1,5 @@ +{ pkgs }: + +[ + pkgs.nodejs_22 +] \ No newline at end of file