diff --git a/.github/workflows/common-build.yml b/.github/workflows/common-build.yml new file mode 100644 index 0000000..d38e0f0 --- /dev/null +++ b/.github/workflows/common-build.yml @@ -0,0 +1,43 @@ +name: Common CI build + +on: + workflow_call: + +permissions: + id-token: write + contents: write + +env: + node_version: 20 + +jobs: + build: + runs-on: ubuntu-latest + concurrency: + group: build + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.node_version }} + registry-url: "https://registry.npmjs.org" + - name: Install dependencies + run: npm ci + - name: Typecheck + run: npm run typecheck + - name: Build + run: npm run build + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-region: eu-west-1 + role-to-assume: ${{ secrets.AWS_ROLE }} + role-session-name: GitHubActions + - name: Bootstrap CDK + # so I do not have to do it manually when CDK is updated + run: npx cdk bootstrap aws://${{secrets.AWS_ACCOUNT_ID}}/eu-west-1 + - uses: actions/upload-artifact@v4 + with: + name: dist + path: dist diff --git a/.github/workflows/common.yml b/.github/workflows/common-test.yml similarity index 65% rename from .github/workflows/common.yml rename to .github/workflows/common-test.yml index cb1f31e..647c911 100644 --- a/.github/workflows/common.yml +++ b/.github/workflows/common-test.yml @@ -1,7 +1,16 @@ -name: Common CI +name: Common CI tests on: workflow_call: + inputs: + mode: + description: "'build' (just builded code, used while publishing) or 'global' (real NPM installed globally) or 'local' (real NPM installed locally)" + type: string + required: true + testMonorepo: + description: "Test monorepo by specifying folder in config" + type: string + default: false permissions: id-token: write @@ -9,43 +18,12 @@ permissions: env: DISABLE_PARALLEL_DEPLOY: false + REAL_NPM: ${{ github.event.inputs.mode == 'global' || github.event.inputs.mode == 'local' }} + TEST_MONOREPO: ${{ github.event.inputs.testMonorepo }} node_version: 20 jobs: - build: - runs-on: ubuntu-latest - concurrency: - group: build - steps: - - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.node_version }} - registry-url: "https://registry.npmjs.org" - - name: Install dependencies - run: npm ci - - name: Typecheck - run: npm run typecheck - - name: Build - run: npm run build - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-region: eu-west-1 - role-to-assume: ${{ secrets.AWS_ROLE }} - role-session-name: GitHubActions - - name: Bootstrap CDK - # so I do not have to do it manually when CDK is updated - run: npx cdk bootstrap aws://${{secrets.AWS_ACCOUNT_ID}}/eu-west-1 - - uses: actions/upload-artifact@v4 - with: - name: dist - path: dist - test-cdk-basic: - needs: - - build runs-on: ubuntu-latest concurrency: group: test-cdk-basic @@ -58,10 +36,22 @@ jobs: registry-url: "https://registry.npmjs.org" - name: Install dependencies run: npm ci - - uses: actions/download-artifact@v4 + - name: Download build artifact + uses: actions/download-artifact@v4 + if: ${{ github.event.inputs.mode == 'build' }} with: name: dist path: dist + - name: Install lambda-live-debugger globally + if: ${{ github.event.inputs.mode == 'global' }} + run: | + npm i lambda-live-debugger -g + working-directory: test + - name: Install lambda-live-debugger locally + if: ${{ github.event.inputs.mode == 'local' }} + run: | + npm i lambda-live-debugger + working-directory: test - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v4 with: @@ -81,8 +71,6 @@ jobs: run: OBSERVABLE_MODE=true npx vitest --retry 1 test/cdk-basic.test.ts test-sls-basic: - needs: - - build runs-on: ubuntu-latest concurrency: group: test-sls-basic @@ -95,10 +83,23 @@ jobs: registry-url: "https://registry.npmjs.org" - name: Install dependencies run: npm ci - - uses: actions/download-artifact@v4 + - name: Download build artifact + uses: actions/download-artifact@v4 + if: ${{ github.event.inputs.mode == 'build' }} with: name: dist path: dist + - name: Install lambda-live-debugger globally + if: ${{ github.event.inputs.mode == 'global' }} + run: | + npm i lambda-live-debugger -g + npm i serverless@3.38.0 -g + working-directory: test + - name: Install lambda-live-debugger locally + if: ${{ github.event.inputs.mode == 'local' }} + run: | + npm i lambda-live-debugger + working-directory: test - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v4 with: @@ -118,8 +119,6 @@ jobs: run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-basic.test.ts test-sls-esbuild-cjs: - needs: - - build runs-on: ubuntu-latest concurrency: group: test-sls-esbuild-cjs @@ -132,10 +131,23 @@ jobs: registry-url: "https://registry.npmjs.org" - name: Install dependencies run: npm ci - - uses: actions/download-artifact@v4 + - name: Download build artifact + uses: actions/download-artifact@v4 + if: ${{ github.event.inputs.mode == 'build' }} with: name: dist path: dist + - name: Install lambda-live-debugger globally + if: ${{ github.event.inputs.mode == 'global' }} + run: | + npm i lambda-live-debugger -g + npm i serverless@3.38.0 -g + working-directory: test + - name: Install lambda-live-debugger locally + if: ${{ github.event.inputs.mode == 'local' }} + run: | + npm i lambda-live-debugger + working-directory: test - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v4 with: @@ -155,8 +167,6 @@ jobs: run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-esbuild-cjs.test.ts test-sls-esbuild-esm: - needs: - - build runs-on: ubuntu-latest concurrency: group: test-sls-esbuild-esm @@ -169,10 +179,23 @@ jobs: registry-url: "https://registry.npmjs.org" - name: Install dependencies run: npm ci - - uses: actions/download-artifact@v4 + - name: Download build artifact + uses: actions/download-artifact@v4 + if: ${{ github.event.inputs.mode == 'build' }} with: name: dist path: dist + - name: Install lambda-live-debugger globally + if: ${{ github.event.inputs.mode == 'global' }} + run: | + npm i lambda-live-debugger -g + npm i serverless@3.38.0 -g + working-directory: test + - name: Install lambda-live-debugger locally + if: ${{ github.event.inputs.mode == 'local' }} + run: | + npm i lambda-live-debugger + working-directory: test - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v4 with: @@ -192,8 +215,6 @@ jobs: run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-esbuild-esm.test.ts test-sam-basic: - needs: - - build runs-on: ubuntu-latest concurrency: group: test-sam-basic @@ -210,10 +231,22 @@ jobs: registry-url: "https://registry.npmjs.org" - name: Install dependencies run: npm ci - - uses: actions/download-artifact@v4 + - name: Download build artifact + uses: actions/download-artifact@v4 + if: ${{ github.event.inputs.mode == 'build' }} with: name: dist path: dist + - name: Install lambda-live-debugger globally + if: ${{ github.event.inputs.mode == 'global' }} + run: | + npm i lambda-live-debugger -g + working-directory: test + - name: Install lambda-live-debugger locally + if: ${{ github.event.inputs.mode == 'local' }} + run: | + npm i lambda-live-debugger + working-directory: test - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v4 with: @@ -233,8 +266,6 @@ jobs: run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sam-basic.test.ts test-terraform-basic: - needs: - - build runs-on: ubuntu-latest concurrency: group: test-terraform-basic @@ -247,10 +278,22 @@ jobs: registry-url: "https://registry.npmjs.org" - name: Install dependencies run: npm ci - - uses: actions/download-artifact@v4 + - name: Download build artifact + uses: actions/download-artifact@v4 + if: ${{ github.event.inputs.mode == 'build' }} with: name: dist path: dist + - name: Install lambda-live-debugger globally + if: ${{ github.event.inputs.mode == 'global' }} + run: | + npm i lambda-live-debugger -g + working-directory: test + - name: Install lambda-live-debugger locally + if: ${{ github.event.inputs.mode == 'local' }} + run: | + npm i lambda-live-debugger + working-directory: test - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v4 with: @@ -275,37 +318,3 @@ jobs: run: npx vitest --retry 1 test/terraform-basic.test.ts - name: Test - observable mode run: OBSERVABLE_MODE=true npx vitest --retry 1 test/terraform-basic.test.ts - - publish: - needs: - - test-cdk-basic - - test-sls-basic - - test-sls-esbuild-cjs - - test-sls-esbuild-esm - - test-sam-basic - - test-terraform-basic - if: github.event_name == 'workflow_dispatch' - runs-on: ubuntu-latest - concurrency: - group: publish - steps: - - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.node_version }} - registry-url: "https://registry.npmjs.org" - - name: Install dependencies - run: npm ci - - uses: actions/download-artifact@v4 - with: - name: dist - path: dist - - name: Semantic Release - run: | - npm whoami - npx semantic-release - env: - GITHUB_TOKEN: ${{ secrets.PRIVATE_GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0063395..c1fe90c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -7,13 +7,23 @@ permissions: id-token: write contents: write +env: + node_version: 20 + jobs: - build-and-test: - uses: ./.github/workflows/common.yml + build: + uses: ./.github/workflows/common-build.yml + secrets: inherit + + test: + uses: ./.github/workflows/common-test.yml secrets: inherit + needs: build + with: + mode: build publish: - needs: build-and-test + needs: test if: github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest concurrency: @@ -23,7 +33,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v4 with: - node-version: "20" + node-version: ${{ env.node_version }} registry-url: "https://registry.npmjs.org" - name: Install dependencies run: npm ci diff --git a/.github/workflows/test-with-real-npm-all.yml b/.github/workflows/test-with-real-npm-all.yml new file mode 100644 index 0000000..bf8cae6 --- /dev/null +++ b/.github/workflows/test-with-real-npm-all.yml @@ -0,0 +1,37 @@ +name: Test with real npm - all combinations + +on: + workflow_dispatch: + +permissions: + id-token: write + contents: write + +jobs: + test-global-not-monorepo: + uses: ./.github/workflows/common-test.yml + with: + mode: "global" + testMonorepo: "false" + secrets: inherit + + test-local-not-monorepo: + uses: ./.github/workflows/common-test.yml + with: + mode: "local" + testMonorepo: "false" + secrets: inherit + + test-global-monorepo: + uses: ./.github/workflows/common-test.yml + with: + mode: "global" + testMonorepo: "true" + secrets: inherit + + test-local-monorepo: + uses: ./.github/workflows/common-test.yml + with: + mode: "local" + testMonorepo: "true" + secrets: inherit diff --git a/.github/workflows/test-with-real-npm.yml b/.github/workflows/test-with-real-npm.yml index ac75f31..e1978c9 100644 --- a/.github/workflows/test-with-real-npm.yml +++ b/.github/workflows/test-with-real-npm.yml @@ -1,363 +1,30 @@ name: Test with real npm +run-name: Test with real npm: mode=${{ github.event.inputs.mode }}, testMonorepo=${{ github.event.inputs.testMonorepo }} + on: workflow_dispatch: inputs: - installGlobally: - description: "Install lambda-live-debugger globally" - default: "true" + mode: + description: "'global' (real NPM installed globally) or 'local' (real NPM installed locally) " + type: choice + required: true + options: + - global + - local + testMonorepo: + description: "Test monorepo by specifying folder in config" + type: boolean + default: false permissions: id-token: write contents: write -env: - REAL_NPM: true - DISABLE_PARALLEL_DEPLOY: false - node_version: 20 - jobs: - test-cdk-basic: - runs-on: ubuntu-latest - concurrency: - group: test-cdk-basic - steps: - - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.node_version }} - registry-url: "https://registry.npmjs.org" - - name: Move vite.config.ts to test folder - run: | - mv vite.config.ts test/vite.config.ts - - name: Delete everything except the test folder - run: | - # Enable extended globbing - shopt -s extglob - rm -rf !(test) - - name: Install dependencies - run: | - npm i - cd cdk-basic - npm i - working-directory: test - - name: Install lambda-live-debugger globally - if: ${{ github.event.inputs.installGlobally == 'true' }} - run: | - npm i lambda-live-debugger -g - working-directory: test - - name: Install lambda-live-debugger locally - if: ${{ github.event.inputs.installGlobally != 'true' }} - run: | - npm i lambda-live-debugger - working-directory: test - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-region: eu-west-1 - role-to-assume: ${{ secrets.AWS_ROLE }} - role-session-name: GitHubActions - - name: Destroy - run: npm run destroy - working-directory: test/cdk-basic - continue-on-error: true - - name: Deploy - run: npm run deploy - working-directory: test/cdk-basic - - name: Test - run: npx vitest --retry 1 cdk-basic.test.ts - working-directory: test - - name: Test - observable mode - run: OBSERVABLE_MODE=true npx vitest --retry 1 cdk-basic.test.ts - working-directory: test - - test-sls-basic: - runs-on: ubuntu-latest - concurrency: - group: test-sls-basic - steps: - - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.node_version }} - registry-url: "https://registry.npmjs.org" - - name: Move vite.config.ts to test folder - run: | - mv vite.config.ts test/vite.config.ts - - name: Delete everything except the test folder - run: | - # Enable extended globbing - shopt -s extglob - rm -rf !(test) - - name: Install dependencies - run: | - npm i - cd sls-basic - npm i - working-directory: test - - name: Install lambda-live-debugger globally - if: ${{ github.event.inputs.installGlobally == 'true' }} - run: | - npm i lambda-live-debugger -g - npm i serverless@3.38.0 -g - working-directory: test - - name: Install lambda-live-debugger locally - if: ${{ github.event.inputs.installGlobally != 'true' }} - run: | - npm i lambda-live-debugger - working-directory: test - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-region: eu-west-1 - role-to-assume: ${{ secrets.AWS_ROLE }} - role-session-name: GitHubActions - - name: Destroy - run: npm run destroy - working-directory: test/sls-basic - continue-on-error: true - - name: Deploy - run: npm run deploy - working-directory: test/sls-basic - - name: Test - run: npx vitest --retry 1 sls-basic.test.ts - working-directory: test - - name: Test - observable mode - run: OBSERVABLE_MODE=true npx vitest --retry 1 sls-basic.test.ts - working-directory: test - - test-sls-esbuild-cjs: - runs-on: ubuntu-latest - concurrency: - group: test-sls-esbuild-cjs - steps: - - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.node_version }} - registry-url: "https://registry.npmjs.org" - - name: Move vite.config.ts to test folder - run: | - mv vite.config.ts test/vite.config.ts - - name: Delete everything except the test folder - run: | - # Enable extended globbing - shopt -s extglob - rm -rf !(test) - - name: Install dependencies - run: | - npm i - cd sls-esbuild-cjs - npm i - working-directory: test - - name: Install lambda-live-debugger globally - if: ${{ github.event.inputs.installGlobally == 'true' }} - run: | - npm i lambda-live-debugger -g - npm i serverless@3.38.0 -g - working-directory: test - - name: Install lambda-live-debugger locally - if: ${{ github.event.inputs.installGlobally != 'true' }} - run: | - npm i lambda-live-debugger - working-directory: test - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-region: eu-west-1 - role-to-assume: ${{ secrets.AWS_ROLE }} - role-session-name: GitHubActions - - name: Destroy - run: npm run destroy - working-directory: test/sls-esbuild-cjs - continue-on-error: true - - name: Deploy - run: npm run deploy - working-directory: test/sls-esbuild-cjs - - name: Test - run: npx vitest --retry 1 sls-esbuild-cjs.test.ts - working-directory: test - - name: Test - observable mode - run: OBSERVABLE_MODE=true npx vitest --retry 1 sls-esbuild-cjs.test.ts - working-directory: test - - test-sls-esbuild-esm: - runs-on: ubuntu-latest - concurrency: - group: test-sls-esbuild-esm - steps: - - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.node_version }} - registry-url: "https://registry.npmjs.org" - - name: Move vite.config.ts to test folder - run: | - mv vite.config.ts test/vite.config.ts - - name: Delete everything except the test folder - run: | - # Enable extended globbing - shopt -s extglob - rm -rf !(test) - - name: Install dependencies - run: | - npm i - cd sls-esbuild-esm - npm i - working-directory: test - - name: Install lambda-live-debugger globally - if: ${{ github.event.inputs.installGlobally == 'true' }} - run: | - npm i lambda-live-debugger -g - npm i serverless@3.38.0 -g - working-directory: test - - name: Install lambda-live-debugger locally - if: ${{ github.event.inputs.installGlobally != 'true' }} - run: | - npm i lambda-live-debugger - working-directory: test - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-region: eu-west-1 - role-to-assume: ${{ secrets.AWS_ROLE }} - role-session-name: GitHubActions - - name: Destroy - run: npm run destroy - working-directory: test/sls-esbuild-esm - continue-on-error: true - - name: Deploy - run: npm run deploy - working-directory: test/sls-esbuild-esm - - name: Test - run: npx vitest --retry 1 sls-esbuild-esm.test.ts - working-directory: test - - name: Test - observable mode - run: OBSERVABLE_MODE=true npx vitest --retry 1 sls-esbuild-esm.test.ts - working-directory: test - - test-sam-basic: - runs-on: ubuntu-latest - concurrency: - group: test-sam-basic - steps: - - uses: actions/checkout@v4 - - uses: aws-actions/setup-sam@v2 - with: - use-installer: true - token: ${{ secrets.GITHUB_TOKEN }} - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.node_version }} - registry-url: "https://registry.npmjs.org" - - name: Move vite.config.ts to test folder - run: | - mv vite.config.ts test/vite.config.ts - - name: Delete everything except the test folder - run: | - # Enable extended globbing - shopt -s extglob - rm -rf !(test) - - name: Install dependencies - run: | - npm i - cd sam-basic - npm i - working-directory: test - - name: Install lambda-live-debugger globally - if: ${{ github.event.inputs.installGlobally == 'true' }} - run: | - npm i lambda-live-debugger -g - npm i serverless@3.38.0 -g - working-directory: test - - name: Install lambda-live-debugger locally - if: ${{ github.event.inputs.installGlobally != 'true' }} - run: | - npm i lambda-live-debugger - working-directory: test - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-region: eu-west-1 - role-to-assume: ${{ secrets.AWS_ROLE }} - role-session-name: GitHubActions - - name: Destroy - run: npm run destroy - working-directory: test/sam-basic - continue-on-error: true - - name: Deploy - run: npm run deploy - working-directory: test/sam-basic - - name: Test - run: npx vitest --retry 1 sam-basic.test.ts - working-directory: test - - name: Test - observable mode - run: OBSERVABLE_MODE=true npx vitest --retry 1 sam-basic.test.ts - working-directory: test - - test-terraform-basic: - runs-on: ubuntu-latest - concurrency: - group: test-terraform-basic - steps: - - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.node_version }} - registry-url: "https://registry.npmjs.org" - - name: Move vite.config.ts to test folder - run: | - mv vite.config.ts test/vite.config.ts - - name: Delete everything except the test folder - run: | - # Enable extended globbing - shopt -s extglob - rm -rf !(test) - - name: Install dependencies - run: | - npm i - cd terraform-basic - npm i - working-directory: test - - name: Install lambda-live-debugger globally - if: ${{ github.event.inputs.installGlobally == 'true' }} - run: | - npm i lambda-live-debugger -g - working-directory: test - - name: Install lambda-live-debugger locally - if: ${{ github.event.inputs.installGlobally != 'true' }} - run: | - npm i lambda-live-debugger - working-directory: test - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-region: eu-west-1 - role-to-assume: ${{ secrets.AWS_ROLE }} - role-session-name: GitHubActions - - name: Setup Terraform - uses: hashicorp/setup-terraform@v1 - - name: Terraform Init - run: | - ./create_bucket.sh lld-terraform-basic - terraform init -backend-config="bucket=lld-terraform-basic" - working-directory: test/terraform-basic - - name: Destroy - run: npm run destroy - working-directory: test/terraform-basic - continue-on-error: true - - name: Deploy - run: npm run deploy - working-directory: test/terraform-basic - - name: Test - run: npx vitest --retry 1 terraform-basic.test.ts - working-directory: test - - name: Test - observable mode - run: OBSERVABLE_MODE=true npx vitest --retry 1 terraform-basic.test.ts - working-directory: test + test: + uses: ./.github/workflows/common-test.yml + with: + mode: ${{ github.event.inputs.mode }} + testMonorepo: ${{ github.event.inputs.testMonorepo }} + secrets: inherit diff --git a/test/utils/startDebugger.ts b/test/utils/startDebugger.ts index 856c094..d35e9ee 100644 --- a/test/utils/startDebugger.ts +++ b/test/utils/startDebugger.ts @@ -18,21 +18,37 @@ export async function startDebugger(folder: string, args: string[] = []) { async function startDebuggerInternal(folder: string, args: string[] = []) { console.log("Starting LLD..."); + let testMonorepo = false; + if (process.env.TEST_MONOREPO === "true") { + testMonorepo = true; + // just the last two part of the folder + const folderParts = folder.split("/"); + const testProjectFolder = + folderParts[folderParts.length - 2] + + "/" + + folderParts[folderParts.length - 1]; + args.push(`-m ${testProjectFolder}`); + } + if (process.env.OBSERVABLE_MODE === "true") { args.push("-o"); } args.push("-v"); - let command = `node ../../dist/lldebugger.mjs ${args?.join(" ")}`; + let command = `node ${ + testMonorepo ? "" : "../../" + }dist/lldebugger.mjs ${args?.join(" ")}`; if (process.env.REAL_NPM === "true") { console.log("Running the debugger with the real NPM"); command = `lld ${args?.join(" ")}`; + } else { + console.log("Running the debugger with just genereted code"); } const lldProcess = spawn(command, { - cwd: folder, + cwd: !testMonorepo ? folder : undefined, shell: true, });