diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c43023fa30..372dabd0d1 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 @@ -76,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: 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/package.json b/package.json index fd1bc1f295..ff5d9140b3 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", @@ -13,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/packages/cdktf-cli/templates/python/.hooks.sscaff.js b/packages/cdktf-cli/templates/python/.hooks.sscaff.js index 43aa64ba78..df5a2e3f77 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); @@ -29,8 +35,8 @@ exports.post = options => { execSync(`pipenv install ${pypi_cdktf}`, { stdio: 'inherit' }); chmodSync('main.py', '700'); - execSync(`${cli} get`, { stdio: 'inherit' }); - execSync(`pipenv run ./main.py`); + 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 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 diff --git a/packages/cdktf-cli/templates/python/cdktf.json b/packages/cdktf-cli/templates/python/cdktf.json index d3f20d177b..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 diff --git a/test/test-all.bat b/test/test-all.bat new file mode 100644 index 0000000000..523678f0ad --- /dev/null +++ b/test/test-all.bat @@ -0,0 +1,17 @@ +@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" + IF !ERRORLEVEL! NEQ 0 exit /B 1 + ) + ) +) \ No newline at end of file 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-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 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" ], 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