From 4135fc073df2d5e795fe823ab887aeaae120d1cd Mon Sep 17 00:00:00 2001 From: Jon Steinich Date: Fri, 31 Jul 2020 01:25:46 +0000 Subject: [PATCH 01/15] os specific pipenv check --- packages/cdktf-cli/templates/python/.hooks.sscaff.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/cdktf-cli/templates/python/.hooks.sscaff.js b/packages/cdktf-cli/templates/python/.hooks.sscaff.js index 43aa64ba78..f8333a76a5 100644 --- a/packages/cdktf-cli/templates/python/.hooks.sscaff.js +++ b/packages/cdktf-cli/templates/python/.hooks.sscaff.js @@ -1,12 +1,18 @@ const { execSync } = require('child_process'); const { chmodSync } = require('fs'); const { readFileSync, writeFileSync } = require('fs'); +const os = require('os'); const cli = require.resolve('../../bin/cdktf'); exports.pre = () => { try { - execSync('which pipenv') + if (os.platform() === 'win32') { + execSync('where pipenv') + } + else { + execSync('which pipenv') + } } catch { console.error(`Unable to find "pipenv". Install from https://pipenv.kennethreitz.org`) process.exit(1); From 22e998f1294252cea8f73e8d45c66d05613f36bc Mon Sep 17 00:00:00 2001 From: Jon Steinich Date: Thu, 30 Jul 2020 20:27:23 -0500 Subject: [PATCH 02/15] remove exact python version constraint pipenv doesn't support minimum --- packages/cdktf-cli/templates/python/Pipfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/cdktf-cli/templates/python/Pipfile b/packages/cdktf-cli/templates/python/Pipfile index 1543c8f0dd..7064d9e96e 100644 --- a/packages/cdktf-cli/templates/python/Pipfile +++ b/packages/cdktf-cli/templates/python/Pipfile @@ -1,7 +1,4 @@ [[source]] name = "pypi" url = "https://pypi.org/simple" -verify_ssl = true - -[requires] -python_version = "3.7" \ No newline at end of file +verify_ssl = true \ No newline at end of file From 584c2c60f32c3fe39e77379f6d26a99e83f6cb25 Mon Sep 17 00:00:00 2001 From: Jon Steinich Date: Thu, 30 Jul 2020 20:36:46 -0500 Subject: [PATCH 03/15] use explicit node call --- packages/cdktf-cli/templates/python/.hooks.sscaff.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cdktf-cli/templates/python/.hooks.sscaff.js b/packages/cdktf-cli/templates/python/.hooks.sscaff.js index f8333a76a5..9eb1d20ad2 100644 --- a/packages/cdktf-cli/templates/python/.hooks.sscaff.js +++ b/packages/cdktf-cli/templates/python/.hooks.sscaff.js @@ -35,7 +35,7 @@ exports.post = options => { execSync(`pipenv install ${pypi_cdktf}`, { stdio: 'inherit' }); chmodSync('main.py', '700'); - execSync(`${cli} get`, { stdio: 'inherit' }); + execSync(`node ${cli} get`, { stdio: 'inherit' }); execSync(`pipenv run ./main.py`); console.log(readFileSync('./help', 'utf-8')); From 94159bb27bcdb94a298f0645e44383ac850a3bd6 Mon Sep 17 00:00:00 2001 From: Jon Steinich Date: Thu, 30 Jul 2020 21:37:18 -0500 Subject: [PATCH 04/15] make windows happy with python --- packages/cdktf-cli/templates/python/.hooks.sscaff.js | 2 +- packages/cdktf-cli/templates/python/cdktf.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cdktf-cli/templates/python/.hooks.sscaff.js b/packages/cdktf-cli/templates/python/.hooks.sscaff.js index 9eb1d20ad2..76e4cc7791 100644 --- a/packages/cdktf-cli/templates/python/.hooks.sscaff.js +++ b/packages/cdktf-cli/templates/python/.hooks.sscaff.js @@ -36,7 +36,7 @@ exports.post = options => { chmodSync('main.py', '700'); execSync(`node ${cli} get`, { stdio: 'inherit' }); - execSync(`pipenv run ./main.py`); + execSync(`pipenv run main.py`); console.log(readFileSync('./help', 'utf-8')); }; diff --git a/packages/cdktf-cli/templates/python/cdktf.json b/packages/cdktf-cli/templates/python/cdktf.json index d3f20d177b..82aeef2518 100644 --- a/packages/cdktf-cli/templates/python/cdktf.json +++ b/packages/cdktf-cli/templates/python/cdktf.json @@ -1,6 +1,6 @@ { "language": "python", - "app": "pipenv run ./main.py", + "app": "pipenv run main.py", "terraformProviders": ["aws@~> 2.0"], "codeMakerOutput": "imports" } \ No newline at end of file From 64e9e52db970cfc697ccc0b054783f2320f8ffbb Mon Sep 17 00:00:00 2001 From: Jon Steinich Date: Thu, 30 Jul 2020 21:37:34 -0500 Subject: [PATCH 05/15] keep some version constrain in pipfile --- packages/cdktf-cli/templates/python/Pipfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/cdktf-cli/templates/python/Pipfile b/packages/cdktf-cli/templates/python/Pipfile index 7064d9e96e..68e00c2c02 100644 --- a/packages/cdktf-cli/templates/python/Pipfile +++ b/packages/cdktf-cli/templates/python/Pipfile @@ -1,4 +1,7 @@ [[source]] name = "pypi" url = "https://pypi.org/simple" -verify_ssl = true \ No newline at end of file +verify_ssl = true + +[requires] +python_version = "3" \ No newline at end of file From e6c6bdf4c2db8c2d3e146230148863dbaa688133 Mon Sep 17 00:00:00 2001 From: Jon Steinich Date: Fri, 31 Jul 2020 02:59:53 +0000 Subject: [PATCH 06/15] trying to find something that works cross platform --- packages/cdktf-cli/templates/python/.hooks.sscaff.js | 2 +- packages/cdktf-cli/templates/python/cdktf.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cdktf-cli/templates/python/.hooks.sscaff.js b/packages/cdktf-cli/templates/python/.hooks.sscaff.js index 76e4cc7791..f32a937466 100644 --- a/packages/cdktf-cli/templates/python/.hooks.sscaff.js +++ b/packages/cdktf-cli/templates/python/.hooks.sscaff.js @@ -36,7 +36,7 @@ exports.post = options => { chmodSync('main.py', '700'); execSync(`node ${cli} get`, { stdio: 'inherit' }); - execSync(`pipenv run main.py`); + execSync(`pipenv run python main.py`); console.log(readFileSync('./help', 'utf-8')); }; diff --git a/packages/cdktf-cli/templates/python/cdktf.json b/packages/cdktf-cli/templates/python/cdktf.json index 82aeef2518..4f3636e7dc 100644 --- a/packages/cdktf-cli/templates/python/cdktf.json +++ b/packages/cdktf-cli/templates/python/cdktf.json @@ -1,6 +1,6 @@ { "language": "python", - "app": "pipenv run main.py", + "app": "pipenv run python main.py", "terraformProviders": ["aws@~> 2.0"], "codeMakerOutput": "imports" } \ No newline at end of file From ffd614f90917a73108f06cfa2a1b4371121e7182 Mon Sep 17 00:00:00 2001 From: Jon Steinich Date: Fri, 21 Aug 2020 14:08:30 +0000 Subject: [PATCH 07/15] try again not changing pipfile --- packages/cdktf-cli/templates/python/.hooks.sscaff.js | 2 +- packages/cdktf-cli/templates/python/Pipfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cdktf-cli/templates/python/.hooks.sscaff.js b/packages/cdktf-cli/templates/python/.hooks.sscaff.js index f32a937466..a302cc9a5c 100644 --- a/packages/cdktf-cli/templates/python/.hooks.sscaff.js +++ b/packages/cdktf-cli/templates/python/.hooks.sscaff.js @@ -35,7 +35,7 @@ exports.post = options => { execSync(`pipenv install ${pypi_cdktf}`, { stdio: 'inherit' }); chmodSync('main.py', '700'); - execSync(`node ${cli} get`, { stdio: 'inherit' }); + execSync(`${process.execPath} ${cli} get`, { stdio: 'inherit' }); execSync(`pipenv run python main.py`); console.log(readFileSync('./help', 'utf-8')); diff --git a/packages/cdktf-cli/templates/python/Pipfile b/packages/cdktf-cli/templates/python/Pipfile index 68e00c2c02..1543c8f0dd 100644 --- a/packages/cdktf-cli/templates/python/Pipfile +++ b/packages/cdktf-cli/templates/python/Pipfile @@ -4,4 +4,4 @@ url = "https://pypi.org/simple" verify_ssl = true [requires] -python_version = "3" \ No newline at end of file +python_version = "3.7" \ No newline at end of file From 1fdde16d0b54c89e0a77c3b28185938bb5b87e49 Mon Sep 17 00:00:00 2001 From: Jon Steinich Date: Sat, 22 Aug 2020 12:40:37 -0500 Subject: [PATCH 08/15] fix path quoting --- packages/cdktf-cli/templates/python/.hooks.sscaff.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cdktf-cli/templates/python/.hooks.sscaff.js b/packages/cdktf-cli/templates/python/.hooks.sscaff.js index a302cc9a5c..df5a2e3f77 100644 --- a/packages/cdktf-cli/templates/python/.hooks.sscaff.js +++ b/packages/cdktf-cli/templates/python/.hooks.sscaff.js @@ -35,7 +35,7 @@ exports.post = options => { execSync(`pipenv install ${pypi_cdktf}`, { stdio: 'inherit' }); chmodSync('main.py', '700'); - execSync(`${process.execPath} ${cli} get`, { stdio: 'inherit' }); + execSync(`\"${process.execPath}\" ${cli} get`, { stdio: 'inherit' }); execSync(`pipenv run python main.py`); console.log(readFileSync('./help', 'utf-8')); From c761f7f3a4c57c27594f27d88875f3949103dc04 Mon Sep 17 00:00:00 2001 From: Jon Steinich Date: Sat, 22 Aug 2020 12:45:25 -0500 Subject: [PATCH 09/15] update examples and tests to win friendly app --- examples/python/aws-eks/cdktf.json | 2 +- examples/python/aws/cdktf.json | 2 +- examples/python/docker/cdktf.json | 2 +- examples/python/kubernetes/cdktf.json | 2 +- test/test-python-app/cdktf.json | 2 +- test/test-python-third-party-provider/cdktf.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/python/aws-eks/cdktf.json b/examples/python/aws-eks/cdktf.json index add1b20580..570b97b2f4 100644 --- a/examples/python/aws-eks/cdktf.json +++ b/examples/python/aws-eks/cdktf.json @@ -1,6 +1,6 @@ { "language": "python", - "app": "pipenv run ./main.py", + "app": "pipenv run python main.py", "terraformProviders": [ "aws@~> 2.55" ], diff --git a/examples/python/aws/cdktf.json b/examples/python/aws/cdktf.json index c65e212d9e..27c539b7de 100644 --- a/examples/python/aws/cdktf.json +++ b/examples/python/aws/cdktf.json @@ -1,6 +1,6 @@ { "language": "python", - "app": "pipenv run ./main.py", + "app": "pipenv run python main.py", "terraformProviders": ["aws@~> 2.0"], "terraformModules": ["terraform-aws-modules/vpc/aws"], "codeMakerOutput": "imports" diff --git a/examples/python/docker/cdktf.json b/examples/python/docker/cdktf.json index a47ece781b..d8e630f931 100644 --- a/examples/python/docker/cdktf.json +++ b/examples/python/docker/cdktf.json @@ -1,6 +1,6 @@ { "language": "python", - "app": "pipenv run ./main.py", + "app": "pipenv run python main.py", "terraformProviders": [ "terraform-providers/docker@~> 2.0" ], diff --git a/examples/python/kubernetes/cdktf.json b/examples/python/kubernetes/cdktf.json index 9010a00ab2..9ce82609a7 100644 --- a/examples/python/kubernetes/cdktf.json +++ b/examples/python/kubernetes/cdktf.json @@ -1,6 +1,6 @@ { "language": "python", - "app": "pipenv run ./main.py", + "app": "pipenv run python main.py", "terraformProviders": ["kubernetes@~> 1.11.3"], "codeMakerOutput": "imports" } diff --git a/test/test-python-app/cdktf.json b/test/test-python-app/cdktf.json index 71033340c4..e9055dac72 100644 --- a/test/test-python-app/cdktf.json +++ b/test/test-python-app/cdktf.json @@ -1,6 +1,6 @@ { "language": "python", - "app": "pipenv run ./main.py", + "app": "pipenv run python main.py", "terraformProviders": ["aws@~> 2.0"], "terraformModules": ["terraform-aws-modules/vpc/aws@2.39.0"], "codeMakerOutput": "imports" diff --git a/test/test-python-third-party-provider/cdktf.json b/test/test-python-third-party-provider/cdktf.json index a47ece781b..d8e630f931 100644 --- a/test/test-python-third-party-provider/cdktf.json +++ b/test/test-python-third-party-provider/cdktf.json @@ -1,6 +1,6 @@ { "language": "python", - "app": "pipenv run ./main.py", + "app": "pipenv run python main.py", "terraformProviders": [ "terraform-providers/docker@~> 2.0" ], From e61b9ec00b7250cf1595e4e36573f373d8cac28f Mon Sep 17 00:00:00 2001 From: Jon Steinich Date: Sat, 22 Aug 2020 13:17:57 -0500 Subject: [PATCH 10/15] windows package command --- package.json | 1 + tools/collect-dist.bat | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 tools/collect-dist.bat diff --git a/package.json b/package.json index fd1bc1f295..ff87fb441c 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "scripts": { "build": "lerna run --scope cdktf* build", "package": "lerna run package && tools/collect-dist.sh", + "package-windows": "lerna run package && tools\\collect-dist.bat", "examples:reinstall": "lerna run --parallel --scope @examples/* reinstall", "examples:build": "lerna run --parallel --scope @examples/* build", "examples:synth": "lerna run --parallel --scope @examples/* synth", diff --git a/tools/collect-dist.bat b/tools/collect-dist.bat new file mode 100644 index 0000000000..32b4dc2cd7 --- /dev/null +++ b/tools/collect-dist.bat @@ -0,0 +1,15 @@ +@echo off +setlocal EnableExtensions +setlocal EnableDelayedExpansion + +cd /D %~dp0\.. + +rmdir /Q /S dist +mkdir dist + +for /f %%f in ('yarn lerna ls -p') do ( + if exist "%%f\dist\" ( + echo "collecting from %%f\dist + xcopy /E %%f\dist\ dist\ + ) +) \ No newline at end of file From 5e6ab0122dc6dd4e61031df76ff295008dbadca4 Mon Sep 17 00:00:00 2001 From: Jon Steinich Date: Sat, 22 Aug 2020 14:23:28 -0500 Subject: [PATCH 11/15] run all win int tests that exist --- package.json | 2 +- test/test-all.bat | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/test-all.bat diff --git a/package.json b/package.json index ff87fb441c..ff5d9140b3 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "watch": "lerna run --parallel --stream --scope cdktf* watch-preserve-output", "link-packages": "lerna exec --scope cdktf* yarn link", "integration": "test/run-against-dist test/test-all.sh", - "integration-windows": "test\\run-against-dist.bat \"node test\\test-typescript-deploy\\test.js\"", + "integration-windows": "test\\run-against-dist.bat test\\test-all.bat", "release-github": "tools/release-github.sh", "build-docker-jsii": "docker build -t hashicorp/jsii-terraform .", "push-docker-jsii": "docker push hashicorp/jsii-terraform" diff --git a/test/test-all.bat b/test/test-all.bat new file mode 100644 index 0000000000..2397dfc941 --- /dev/null +++ b/test/test-all.bat @@ -0,0 +1,16 @@ +@echo off +setlocal EnableExtensions +setlocal EnableDelayedExpansion + +cd /D %~dp0 + +for /d %%d in ("test-*") do ( + if exist "%%d\" ( + if exist "%%d\test.js" ( + echo -------------------------------------------------------------------- + echo %%d + echo -------------------------------------------------------------------- + call node "%%d\test.js" + ) + ) +) \ No newline at end of file From fe2239c7af62de04ba75b72e0ac4f2b36517a49f Mon Sep 17 00:00:00 2001 From: Jon Steinich Date: Sat, 22 Aug 2020 15:23:25 -0500 Subject: [PATCH 12/15] run python integration test on windows --- test/test-all.bat | 1 + test/test-python-app/test.js | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 test/test-python-app/test.js diff --git a/test/test-all.bat b/test/test-all.bat index 2397dfc941..523678f0ad 100644 --- a/test/test-all.bat +++ b/test/test-all.bat @@ -11,6 +11,7 @@ for /d %%d in ("test-*") do ( echo %%d echo -------------------------------------------------------------------- call node "%%d\test.js" + IF !ERRORLEVEL! NEQ 0 exit /B 1 ) ) ) \ No newline at end of file diff --git a/test/test-python-app/test.js b/test/test-python-app/test.js new file mode 100644 index 0000000000..a043be3e7d --- /dev/null +++ b/test/test-python-app/test.js @@ -0,0 +1,42 @@ +const { execSync } = require('child_process'); +const os = require('os'); +const path = require('path'); +const fs = require('fs'); + +const env = Object.assign({}, process.env); +// Disable spinner even when we have a TTY +env['CI'] = '1'; + +const scriptdir = __dirname; + +const projectPath = path.join(os.tmpdir(), 'test'); +const folder = fs.mkdtempSync(projectPath); +process.chdir(folder); + +// initialize an empty project +execSync(`cdktf init --template python --project-name="python-test" --project-description="python test app" --local`, { stdio: 'inherit', env }); + +// put some code in it +fs.copyFileSync(path.join(scriptdir, 'main.py'), 'main.py'); +fs.copyFileSync(path.join(scriptdir, 'cdktf.json'), 'cdktf.json'); + +fs.rmdirSync('cdktf.out', { recursive: true }); + +// regenerate with module +execSync(`cdktf get`, { stdio: 'inherit', env }); + +// build +execSync('pipenv run python main.py', { stdio: 'inherit', env }) + +// get rid of downloaded Terraform providers, no point in diffing them +fs.rmdirSync('cdktf.out/.terraform', { recursive: true }); + +// show output +if (os.platform() === 'win32') { + execSync(`fc cdktf.out\\* ${scriptdir}\\expected\\*`, { stdio: 'inherit', env }); +} +else { + execSync(`diff cdktf.out ${scriptdir}/expected`, { stdio: 'inherit', env }); +} + +console.log('PASS'); \ No newline at end of file From f3c002887e4be996b398737f88fa3a4bfc34441e Mon Sep 17 00:00:00 2001 From: Jon Steinich Date: Sat, 22 Aug 2020 15:23:45 -0500 Subject: [PATCH 13/15] rollback python version to not require exact --- packages/cdktf-cli/templates/python/Pipfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cdktf-cli/templates/python/Pipfile b/packages/cdktf-cli/templates/python/Pipfile index 1543c8f0dd..68e00c2c02 100644 --- a/packages/cdktf-cli/templates/python/Pipfile +++ b/packages/cdktf-cli/templates/python/Pipfile @@ -4,4 +4,4 @@ url = "https://pypi.org/simple" verify_ssl = true [requires] -python_version = "3.7" \ No newline at end of file +python_version = "3" \ No newline at end of file From a09d018b44c1f653cc8fe1c957c7970c7db91b4f Mon Sep 17 00:00:00 2001 From: Jon Steinich Date: Sat, 22 Aug 2020 19:41:25 -0500 Subject: [PATCH 14/15] only upload dist from 1 job --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c43023fa30..e8f48b9c66 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,6 +31,7 @@ jobs: - name: create bundle run: yarn package - name: Upload dist + if: ${{ matrix.terraform == '0.12.29' }} uses: actions/upload-artifact@v2 with: name: dist From 8073738ad54bdd9f33649c6ff9bde1abb3bd9757 Mon Sep 17 00:00:00 2001 From: Jon Steinich Date: Sat, 22 Aug 2020 20:05:48 -0500 Subject: [PATCH 15/15] need pipenv for windows python test --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e8f48b9c66..372dabd0d1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,6 +77,8 @@ jobs: with: terraform_wrapper: false terraform_version: ${{ matrix.terraform }} + - name: Install pipenv + run: pip install pipenv - name: Download dist uses: actions/download-artifact@v2 with: