From 954c6b35efa8981c6b249789fda39bcb73b2cbe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Sat, 4 Nov 2023 11:06:21 -0400 Subject: [PATCH 1/5] Create output of generator to a file --- mega-linter-runner/__tests__/mega-linter.js | 19 ------- mega-linter-runner/__tests__/mega-linter.mjs | 54 ++++++++++++++++++++ mega-linter-runner/package.json | 6 ++- 3 files changed, 58 insertions(+), 21 deletions(-) delete mode 100644 mega-linter-runner/__tests__/mega-linter.js create mode 100755 mega-linter-runner/__tests__/mega-linter.mjs diff --git a/mega-linter-runner/__tests__/mega-linter.js b/mega-linter-runner/__tests__/mega-linter.js deleted file mode 100644 index 0670cfc0381..00000000000 --- a/mega-linter-runner/__tests__/mega-linter.js +++ /dev/null @@ -1,19 +0,0 @@ -// Tests done from mega-linter-runner test methods -/* -'use strict'; -const path = require('path'); -const assert = require('yeoman-assert'); -const helpers = require('yeoman-test'); - -describe('mega-linter-runner:mega-linter', () => { - beforeAll(() => { - return helpers - .run(path.join(__dirname, '../generators/mega-linter')) - .withPrompts({ someAnswer: true }); - }); - - it('creates files', () => { - assert.file(['dummy_file.txt']); - }); -}); -*/ diff --git a/mega-linter-runner/__tests__/mega-linter.mjs b/mega-linter-runner/__tests__/mega-linter.mjs new file mode 100755 index 00000000000..d58f40124ec --- /dev/null +++ b/mega-linter-runner/__tests__/mega-linter.mjs @@ -0,0 +1,54 @@ +import helpers, { RunResult, result } from "yeoman-test"; +import MyGenerator from "../generators/mega-linter/index.js"; + +import { basename, dirname } from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +const generator = basename(__dirname); + +import * as path from "path"; + +describe("generator test", () => { + describe("test", () => { + beforeEach(async () => { + const files = { + "mega-linter-runner/generators/mega-linter/templates/mega-linter.yml": + {}, + }; + await helpers + .run(MyGenerator, { + targetDir: RunResult, + resolved: path.join(__dirname, "..", "generators", "mega-linter"), + namespace: "mega-linter-runner:mega-linter", + }) + .withFiles( + path.join(__dirname, "..", "generators", "mega-linter", "templates"), + { + "mega-linter.yml": "foo: Bar", + } + ) + .withAnswers({ flavor: "all", ox: false, validateAllCodeBase: "diff" }); + }); + + it("creates files", () => { + // before(() => helpers.prepareTemporaryDir()); + result + .dumpFiles(".github/workflows/mega-linter.yml") + .fs.copy( + ".github/workflows/mega-linter.yml", + path.join( + __dirname, + "..", + "generators", + "mega-linter", + "out", + ".github/workflows/mega-linter.yml" + ) + ); + result.fs.commit(); + result.dumpFilenames(); + }); + }); +}); diff --git a/mega-linter-runner/package.json b/mega-linter-runner/package.json index 4aa2cd616f6..84ce9666ded 100644 --- a/mega-linter-runner/package.json +++ b/mega-linter-runner/package.json @@ -16,7 +16,8 @@ "mega-linter-runner": "lib/index.js" }, "scripts": { - "test": "mocha \"test/**/*.test.js\"" + "test": "mocha \"test/**/*.test.js\"", + "generator-samples": "mocha \"__tests__/mega-linter.mjs\"" }, "keywords": [ "mega-linter", @@ -95,7 +96,8 @@ "devDependencies": { "assert": "^2.1.0", "eslint": "^8.50.0", - "mocha": "^10.2.0" + "mocha": "^10.2.0", + "yeoman-test": "^8.2.0" }, "resolutions": { "semver": "7.5.2" From 00779966fc87de953b0e4cb379fcc9c0b3a7a176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Sat, 4 Nov 2023 12:38:51 -0400 Subject: [PATCH 2/5] Add ending newlines to the validateAllCodeBaseGha snippet --- mega-linter-runner/generators/mega-linter/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mega-linter-runner/generators/mega-linter/index.js b/mega-linter-runner/generators/mega-linter/index.js index d3dc5e8852d..b89e71b3125 100644 --- a/mega-linter-runner/generators/mega-linter/index.js +++ b/mega-linter-runner/generators/mega-linter/index.js @@ -195,9 +195,9 @@ When you don't know what option to select, please use default values` this.validateAllCodeBaseGha = "true"; } else { this.validateAllCodeBaseGha = ">-\n" - this.validateAllCodeBaseGha += " ${{"; - this.validateAllCodeBaseGha += " github.event_name == 'push' &&" - this.validateAllCodeBaseGha += " github.ref == 'refs/heads/main'" + this.validateAllCodeBaseGha += " ${{\n"; + this.validateAllCodeBaseGha += " github.event_name == 'push' &&\n" + this.validateAllCodeBaseGha += " github.ref == 'refs/heads/main'\n" this.validateAllCodeBaseGha += " }}"; } this.disable = false; From 0e921c07d017f7e6837a2400ddef06fcde48c423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Sat, 4 Nov 2023 12:39:35 -0400 Subject: [PATCH 3/5] Continue simplifying the script to generate the samples --- mega-linter-runner/__tests__/mega-linter.mjs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/mega-linter-runner/__tests__/mega-linter.mjs b/mega-linter-runner/__tests__/mega-linter.mjs index d58f40124ec..fea51705a3d 100755 --- a/mega-linter-runner/__tests__/mega-linter.mjs +++ b/mega-linter-runner/__tests__/mega-linter.mjs @@ -1,12 +1,11 @@ import helpers, { RunResult, result } from "yeoman-test"; import MyGenerator from "../generators/mega-linter/index.js"; -import { basename, dirname } from "path"; +import { dirname } from "path"; import { fileURLToPath } from "url"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); -const generator = basename(__dirname); import * as path from "path"; @@ -23,13 +22,7 @@ describe("generator test", () => { resolved: path.join(__dirname, "..", "generators", "mega-linter"), namespace: "mega-linter-runner:mega-linter", }) - .withFiles( - path.join(__dirname, "..", "generators", "mega-linter", "templates"), - { - "mega-linter.yml": "foo: Bar", - } - ) - .withAnswers({ flavor: "all", ox: false, validateAllCodeBase: "diff" }); + .withAnswers({ flavor: "all", ox: false, ci: "gitHubActions" }); }); it("creates files", () => { From ef5c3e57214de63e1d158af7b9c8868bc4866339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Sat, 4 Nov 2023 12:40:14 -0400 Subject: [PATCH 4/5] Add tags for the github workflows examples in the README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 879c59ca8b8..56f6bb184d9 100644 --- a/README.md +++ b/README.md @@ -421,6 +421,8 @@ In your repository you should have a `.github/workflows` folder with **GitHub**
This file should have this code + + ```yml --- # MegaLinter GitHub Action configuration file @@ -514,6 +516,7 @@ jobs: commit_user_name: megalinter-bot commit_user_email: nicolas.vuillamy@ox.security ``` +
From dd67b5b2360a69a64eb126fc6fc28a440fbfc822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Sat, 4 Nov 2023 12:40:45 -0400 Subject: [PATCH 5/5] Generate the samples from the generator in build.sh --- build.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.sh b/build.sh index 6fd90fec8da..79c39513b58 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash set -eu +npm install --prefix mega-linter-runner +npm run --prefix mega-linter-runner generator-samples + PYTHONPATH=. export PYTHONPATH if type python3 >/dev/null 2>/dev/null; then