From ed2e41996a73ecd806041577674609a7f5106981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Zorro=20=28Windows=20PC=29?= Date: Thu, 21 Nov 2024 07:18:02 -0500 Subject: [PATCH 01/12] ci(e2e): fix windows tests --- .github/workflows/e2e.yaml | 22 +++++++++++----------- lib/generators/component.ts | 4 ++-- lib/generators/container.ts | 2 +- lib/generators/relationship.ts | 6 +++--- package.json | 3 ++- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 4653da4..7188a4e 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -56,6 +56,7 @@ jobs: run: | choco install jq --version 1.7.1 choco install bun --version 1.1.20 + choco install openjdk --version 22.0.2 if: ${{ matrix.os == 'windows' }} - run: bun install --ignore-scripts - name: Download created artifacts @@ -112,14 +113,13 @@ jobs: run: | export STRUCTURIZR_CLI_PATH=./dist/structurizr-cli-bin/structurizr.sh bun test:e2e - # TODO: Windows E2E Tests - # - name: E2E Test (Smoke) (Windows) - # if: ${{ inputs.smoke && matrix.os == 'windows' }} - # run: | - # $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" - # bun test:e2e:smoke - # - name: E2E Test (Full) (Windows) - # if: ${{ !inputs.smoke && matrix.os == 'windows' }} - # run: | - # $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" - # bun test:e2e \ No newline at end of file + - name: E2E Test (Smoke) (Windows) + if: ${{ inputs.smoke && matrix.os == 'windows' }} + run: | + $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" + bun test:e2e:smoke + - name: E2E Test (Full) (Windows) + if: ${{ !inputs.smoke && matrix.os == 'windows' }} + run: | + $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" + bun test:e2e \ No newline at end of file diff --git a/lib/generators/component.ts b/lib/generators/component.ts index 8b3f7d9..c85a01f 100644 --- a/lib/generators/component.ts +++ b/lib/generators/component.ts @@ -122,7 +122,7 @@ const generator: GeneratorDefinition = { type: "append", path: "architecture/components/{{kebabCase systemName}}--{{kebabCase containerName}}.dsl", createIfNotExists: true, - pattern: /[\s\S]*\n/, + pattern: /[\s\S]*\r?\n/, templateFile: "templates/components/component.hbs", } as AppendAction, { @@ -148,7 +148,7 @@ const generator: GeneratorDefinition = { `Component relationship for "${answers.containerName}" already included` ); }, - pattern: /.*{\n/, + pattern: /[\s\S]*{\r?\n/, templateFile: "templates/include.hbs", } as AppendAction, { diff --git a/lib/generators/container.ts b/lib/generators/container.ts index e8cf770..8162130 100644 --- a/lib/generators/container.ts +++ b/lib/generators/container.ts @@ -137,7 +137,7 @@ const generator: GeneratorDefinition = { `Container relationship for "${answers.systemName}" already included` ); }, - pattern: /.*\n!include.*/, + pattern: /.*\r?\n!include.*/, templateFile: "templates/include.hbs", } as AppendAction, { diff --git a/lib/generators/relationship.ts b/lib/generators/relationship.ts index 229e7e7..54b7617 100644 --- a/lib/generators/relationship.ts +++ b/lib/generators/relationship.ts @@ -107,7 +107,7 @@ const generator: GeneratorDefinition = { "No system relationships", type: "append", path: "architecture/relationships/_{{kebabCase elementType}}.dsl", - pattern: /\n.* -> .*\n/, + pattern: /\r?\n.* -> .*\r?\n/, templateFile: "templates/relationships/multiple.hbs", } as AppendAction, { @@ -119,7 +119,7 @@ const generator: GeneratorDefinition = { type: "append", createIfNotExists: true, path: "architecture/relationships/{{kebabCase systemName}}.dsl", - pattern: /[\s\S]*\n/, + pattern: /[\s\S]*\r?\n/, templateFile: "templates/relationships/multiple.hbs", } as AppendAction, { @@ -129,7 +129,7 @@ const generator: GeneratorDefinition = { Object.keys(answers.relationships).length <= 0 && "No component relationships", type: "append", - pattern: /[\s\S]*\n/, + pattern: /[\s\S]*\r?\n/, path: "architecture/relationships/{{kebabCase systemName}}.dsl", templateFile: "templates/relationships/multiple-component.hbs", } as AppendAction, diff --git a/package.json b/package.json index 99cff51..c7d86d0 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "scfz": "lib/main.ts" }, "scripts": { - "build:dev": "bun build ./lib/main.ts --compile --watch --outfile ./dist/scfz", + "build:dev": "bun build ./lib/main.ts --compile --outfile ./dist/scfz", + "build:watch": "bun build:dev --watch", "test:dev": "bun test --watch", "test": "bun test", "test:ci": "bun test --coverage", From 894c5f616ea515e3e57725d0464f4b98cf9efde5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Zorro=20=28Windows=20PC=29?= Date: Thu, 21 Nov 2024 07:47:16 -0500 Subject: [PATCH 02/12] ci(e2e): fix windows tests --- .github/workflows/e2e.yaml | 4 ++++ e2e/scfz.test.ts | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 7188a4e..b455561 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -107,19 +107,23 @@ jobs: if: ${{ inputs.smoke && matrix.os != 'windows' }} run: | export STRUCTURIZR_CLI_PATH=./dist/structurizr-cli-bin/structurizr.sh + export TMP_FOLDER=${{ runner.temp }} bun test:e2e:smoke - name: E2E Test (Full) if: ${{ !inputs.smoke && matrix.os != 'windows' }} run: | export STRUCTURIZR_CLI_PATH=./dist/structurizr-cli-bin/structurizr.sh + export TMP_FOLDER=${{ runner.temp }} bun test:e2e - name: E2E Test (Smoke) (Windows) if: ${{ inputs.smoke && matrix.os == 'windows' }} run: | $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" + $env:TMP_FOLDER = ${{ runner.temp }} bun test:e2e:smoke - name: E2E Test (Full) (Windows) if: ${{ !inputs.smoke && matrix.os == 'windows' }} run: | $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" + $env:TMP_FOLDER = ${{ runner.temp }} bun test:e2e \ No newline at end of file diff --git a/e2e/scfz.test.ts b/e2e/scfz.test.ts index 0570f44..f8df781 100644 --- a/e2e/scfz.test.ts +++ b/e2e/scfz.test.ts @@ -1,5 +1,6 @@ import { afterAll, describe, expect, test } from "bun:test"; import { readdir } from "node:fs/promises"; +import { join } from "node:path"; import { $, type Subprocess, file, spawn } from "bun"; import stripAnsi from "strip-ansi"; import pkg from "../package.json"; @@ -35,8 +36,12 @@ const loop = ( } }; +const TMP_FOLDER = process.env.TMP_FOLDER ?? '/tmp' + describe("e2e", () => { - const folder = `/tmp/test-${(1000 + Math.ceil(Math.random() * 1000)).toString(16)}`; + const folder = join(TMP_FOLDER, `test-${ + (1000 + Math.ceil(Math.random() * 1000)).toString(16) + }`); test("@smoke: should return the correct version", async () => { const proc = spawn(["dist/scfz", "--version"]); From 5b178cb2f301420ce64f8353768532aa447434ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Zorro=20=28Windows=20PC=29?= Date: Thu, 21 Nov 2024 08:16:39 -0500 Subject: [PATCH 03/12] ci(e2e): fix windows tests --- .github/workflows/e2e.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index b455561..32d6714 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -119,11 +119,11 @@ jobs: if: ${{ inputs.smoke && matrix.os == 'windows' }} run: | $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" - $env:TMP_FOLDER = ${{ runner.temp }} + $env:TMP_FOLDER = "${{ runner.temp }}" bun test:e2e:smoke - name: E2E Test (Full) (Windows) if: ${{ !inputs.smoke && matrix.os == 'windows' }} run: | $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" - $env:TMP_FOLDER = ${{ runner.temp }} + $env:TMP_FOLDER = "${{ runner.temp }}" bun test:e2e \ No newline at end of file From e7ec612c6b797d68bcff49e842e62309f0966a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Zorro=20=28Windows=20PC=29?= Date: Thu, 21 Nov 2024 09:13:05 -0500 Subject: [PATCH 04/12] ci(e2e): improved error message for workspace creation --- lib/main.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/main.ts b/lib/main.ts index f6f495d..ab81f65 100644 --- a/lib/main.ts +++ b/lib/main.ts @@ -71,7 +71,8 @@ Let's create a new one by answering the questions below. ); process.exit(0); } catch (err) { - console.error(err); + console.error(chalk.red("[ERROR]:"), err?.toString()); + console.log(chalk.gray("[DEBUG]:"), (err as Error)); process.exit(1); } } From 21bdef5d757d35ec3ea74106aba3ee81cd0d37c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Zorro?= Date: Thu, 21 Nov 2024 09:23:21 -0500 Subject: [PATCH 05/12] ci(e2e): increased e2e tests timeout --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c7d86d0..412ed7a 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ "test:dev": "bun test --watch", "test": "bun test", "test:ci": "bun test --coverage", - "test:e2e:smoke": "bun --config=./e2e/e2e.toml test -t '@smoke' --bail --timeout 15000", - "test:e2e": "bun --config=./e2e/e2e.toml test --bail --timeout 15000", + "test:e2e:smoke": "bun --config=./e2e/e2e.toml test -t '@smoke' --bail --timeout 30000", + "test:e2e": "bun --config=./e2e/e2e.toml test --bail --timeout 30000", "prepare": "husky" }, "trustedDependencies": [".", "@biomejs/biome"], From 57530ff047357a0ab81d0b0d2d9f53c06e7ee801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Zorro?= Date: Thu, 21 Nov 2024 09:54:52 -0500 Subject: [PATCH 06/12] ci(e2e): increased e2e input timeout --- .github/workflows/e2e.yaml | 2 ++ .husky/pre-commit | 1 + e2e/scfz.test.ts | 11 ++++++----- lib/main.ts | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 32d6714..0aab032 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -120,10 +120,12 @@ jobs: run: | $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" $env:TMP_FOLDER = "${{ runner.temp }}" + $env:INPUT_TIMEOUT = "600" bun test:e2e:smoke - name: E2E Test (Full) (Windows) if: ${{ !inputs.smoke && matrix.os == 'windows' }} run: | $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" $env:TMP_FOLDER = "${{ runner.temp }}" + $env:INPUT_TIMEOUT = "600" bun test:e2e \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit index 426d989..67ca653 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -6,4 +6,5 @@ if [ "$(git config --get custom.hooks.pre-commit)" == "false" ]; then exit 0 fi +bun build:dev bun lint-staged --relative diff --git a/e2e/scfz.test.ts b/e2e/scfz.test.ts index f8df781..201ff46 100644 --- a/e2e/scfz.test.ts +++ b/e2e/scfz.test.ts @@ -12,7 +12,7 @@ const keypress = { SPACE: "\x20", }; -const INPUT_TIMEOUT = 400; +const INPUT_TIMEOUT = Number.parseInt(process.env.INPUT_TIMEOUT || "400", 10); const loop = ( process: Subprocess<"pipe", "pipe", "inherit">, @@ -36,12 +36,13 @@ const loop = ( } }; -const TMP_FOLDER = process.env.TMP_FOLDER ?? '/tmp' +const TMP_FOLDER = process.env.TMP_FOLDER || "/tmp"; describe("e2e", () => { - const folder = join(TMP_FOLDER, `test-${ - (1000 + Math.ceil(Math.random() * 1000)).toString(16) - }`); + const folder = join( + TMP_FOLDER, + `test-${(1000 + Math.ceil(Math.random() * 1000)).toString(16)}`, + ); test("@smoke: should return the correct version", async () => { const proc = spawn(["dist/scfz", "--version"]); diff --git a/lib/main.ts b/lib/main.ts index ab81f65..d720ae0 100644 --- a/lib/main.ts +++ b/lib/main.ts @@ -25,7 +25,7 @@ type CLIArguments = { }; const STRUCTURIZR_CLI_PATH = - process.env.STRUCTURIZR_CLI_PATH ?? "structurizr-cli"; + process.env.STRUCTURIZR_CLI_PATH || "structurizr-cli"; async function main(args: CLIArguments = { dest: "." }) { console.log( @@ -72,7 +72,7 @@ Let's create a new one by answering the questions below. process.exit(0); } catch (err) { console.error(chalk.red("[ERROR]:"), err?.toString()); - console.log(chalk.gray("[DEBUG]:"), (err as Error)); + console.log(chalk.gray("[DEBUG]:"), err as Error); process.exit(1); } } From bdad5bef8c7bc7b8bd0c6187552f544e29d43c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Zorro?= Date: Thu, 21 Nov 2024 10:20:48 -0500 Subject: [PATCH 07/12] ci(e2e): configure java version 23 --- .github/workflows/e2e.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 0aab032..a77f308 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -56,8 +56,12 @@ jobs: run: | choco install jq --version 1.7.1 choco install bun --version 1.1.20 - choco install openjdk --version 22.0.2 if: ${{ matrix.os == 'windows' }} + - uses: actions/setup-java@v4 + if: ${{ matrix.os == 'windows' }} + with: + distribution: 'temurin' + java-version: '23' - run: bun install --ignore-scripts - name: Download created artifacts uses: actions/download-artifact@v4 From 072698f2a5d679e02f70cb4ef39c8753db7fc2ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Zorro?= Date: Thu, 21 Nov 2024 10:30:32 -0500 Subject: [PATCH 08/12] ci(e2e): configure a previous version of structurizr-cli --- .github/workflows/e2e.yaml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index a77f308..4e38c2c 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -15,7 +15,7 @@ jobs: name: e2e-${{matrix.name}} runs-on: ${{matrix.runs-on}} env: - STRUCTURIZR_CLI_VERSION: v2024.11.04 + STRUCTURIZR_CLI_VERSION: v2024.07.03 strategy: fail-fast: true matrix: @@ -56,12 +56,8 @@ jobs: run: | choco install jq --version 1.7.1 choco install bun --version 1.1.20 + choco install openjdk --version 22.0.2 if: ${{ matrix.os == 'windows' }} - - uses: actions/setup-java@v4 - if: ${{ matrix.os == 'windows' }} - with: - distribution: 'temurin' - java-version: '23' - run: bun install --ignore-scripts - name: Download created artifacts uses: actions/download-artifact@v4 From f0310b4e9c365b50fd5718028db68380158087a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Zorro?= Date: Thu, 21 Nov 2024 10:38:59 -0500 Subject: [PATCH 09/12] ci(e2e): log java version --- .github/workflows/e2e.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 4e38c2c..8f39feb 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -121,6 +121,7 @@ jobs: $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" $env:TMP_FOLDER = "${{ runner.temp }}" $env:INPUT_TIMEOUT = "600" + java -version bun test:e2e:smoke - name: E2E Test (Full) (Windows) if: ${{ !inputs.smoke && matrix.os == 'windows' }} @@ -128,4 +129,5 @@ jobs: $env:STRUCTURIZR_CLI_PATH = ".\dist\structurizr-cli-bin\structurizr.bat" $env:TMP_FOLDER = "${{ runner.temp }}" $env:INPUT_TIMEOUT = "600" + java -version bun test:e2e \ No newline at end of file From 8062d5aa764c5f1ba76b2bd6f98f5817b87e6bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Zorro?= Date: Thu, 21 Nov 2024 10:45:50 -0500 Subject: [PATCH 10/12] ci(e2e): refresh env to pick java changes --- .github/workflows/e2e.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 8f39feb..800d1bd 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -57,6 +57,10 @@ jobs: choco install jq --version 1.7.1 choco install bun --version 1.1.20 choco install openjdk --version 22.0.2 + $step_java_home=$env:JAVA_HOME + Import-Module "$env:ChocolateyInstall/helpers/chocolateyInstaller.psm1" + refreshenv + $env:JAVA_HOME=$step_java_home if: ${{ matrix.os == 'windows' }} - run: bun install --ignore-scripts - name: Download created artifacts From 00383e6acd4bce9c822f17f8bf687c2d44ed232d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Zorro?= Date: Thu, 21 Nov 2024 10:54:04 -0500 Subject: [PATCH 11/12] ci(e2e): reconfigure setup-java --- .github/workflows/e2e.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 800d1bd..71eb4f7 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -56,12 +56,12 @@ jobs: run: | choco install jq --version 1.7.1 choco install bun --version 1.1.20 - choco install openjdk --version 22.0.2 - $step_java_home=$env:JAVA_HOME - Import-Module "$env:ChocolateyInstall/helpers/chocolateyInstaller.psm1" - refreshenv - $env:JAVA_HOME=$step_java_home if: ${{ matrix.os == 'windows' }} + - uses: actions/setup-java@v4 + if: ${{ matrix.os == 'windows' }} + with: + distribution: 'temurin' # See 'Supported distributions' for available options + java-version: '21' - run: bun install --ignore-scripts - name: Download created artifacts uses: actions/download-artifact@v4 From b908efa5eeb9a45d4b98a8bf9ba748af1925bdc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Zorro?= Date: Thu, 21 Nov 2024 11:01:26 -0500 Subject: [PATCH 12/12] ci(e2e): configure smoke to run on non-main branch --- .github/workflows/pr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 9f48810..4bb2d41 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -38,4 +38,4 @@ jobs: if: always() uses: ./.github/workflows/e2e.yaml with: - smoke: true \ No newline at end of file + smoke: ${{ github.base_ref != 'main' }} \ No newline at end of file