From 30f57cfa1d81060b3457831062c708a714a9c796 Mon Sep 17 00:00:00 2001 From: Mohanad Abugharbia Date: Fri, 23 Feb 2024 21:04:05 +0100 Subject: [PATCH] Add Python packaging to projen config --- .github/workflows/build.yml | 28 ++++++++++++++++++++++++++++ .github/workflows/release.yml | 35 +++++++++++++++++++++++++++++++++++ .mergify.yml | 2 ++ .projen/tasks.json | 12 ++++++++++++ .projenrc.ts | 4 ++++ package.json | 8 +++++++- 6 files changed, 88 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bfc20b0e..04793d3c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -108,3 +108,31 @@ jobs: run: cd .repo && npx projen package:js - name: Collect js Artifact run: mv .repo/dist dist + package-python: + needs: build + runs-on: ubuntu-latest + permissions: {} + if: "! needs.build.outputs.self_mutation_happened" + steps: + - uses: actions/setup-node@v3 + with: + node-version: 18.0.0 + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - name: Download build artifacts + uses: actions/download-artifact@v3 + with: + name: build-artifact + path: dist + - name: Restore build artifact permissions + run: cd dist && setfacl --restore=permissions-backup.acl + continue-on-error: true + - name: Prepare Repository + run: mv dist .repo + - name: Install Dependencies + run: cd .repo && yarn install --check-files --frozen-lockfile + - name: Create python artifact + run: cd .repo && npx projen package:python + - name: Collect python Artifact + run: mv .repo/dist dist diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0f5ea151..dbb821dc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -107,3 +107,38 @@ jobs: NPM_REGISTRY: registry.npmjs.org NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: npx -p publib@latest publib-npm + release_pypi: + name: Publish to PyPI + needs: release + runs-on: ubuntu-latest + permissions: + contents: read + if: needs.release.outputs.latest_commit == github.sha + steps: + - uses: actions/setup-node@v3 + with: + node-version: 18.0.0 + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - name: Download build artifacts + uses: actions/download-artifact@v3 + with: + name: build-artifact + path: dist + - name: Restore build artifact permissions + run: cd dist && setfacl --restore=permissions-backup.acl + continue-on-error: true + - name: Prepare Repository + run: mv dist .repo + - name: Install Dependencies + run: cd .repo && yarn install --check-files --frozen-lockfile + - name: Create python artifact + run: cd .repo && npx projen package:python + - name: Collect python Artifact + run: mv .repo/dist dist + - name: Release + env: + TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} + TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} + run: npx -p publib@latest publib-pypi diff --git a/.mergify.yml b/.mergify.yml index 154b39fa..299617cc 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -8,6 +8,7 @@ queue_rules: - -label~=(do-not-merge) - status-success=build - status-success=package-js + - status-success=package-python pull_request_rules: - name: Automatic merge on approval and successful build actions: @@ -24,3 +25,4 @@ pull_request_rules: - -label~=(do-not-merge) - status-success=build - status-success=package-js + - status-success=package-python diff --git a/.projen/tasks.json b/.projen/tasks.json index f998c20d..e685bf57 100644 --- a/.projen/tasks.json +++ b/.projen/tasks.json @@ -211,6 +211,9 @@ "steps": [ { "spawn": "package:js" + }, + { + "spawn": "package:python" } ] }, @@ -223,6 +226,15 @@ } ] }, + "package:python": { + "name": "package:python", + "description": "Create python language bindings", + "steps": [ + { + "exec": "jsii-pacmak -v --target python" + } + ] + }, "post-compile": { "name": "post-compile", "description": "Runs after successful compilation", diff --git a/.projenrc.ts b/.projenrc.ts index b9e27a8e..18b4ecf5 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -71,6 +71,10 @@ const project = new awscdk.AwsCdkConstructLibrary({ ] /* Build dependencies for this module. */, // misc config sampleCode: false, // do not generate sample test files + publishToPypi: { + distName: 'cdk-nextjs-standalone', + module: 'cdk_nextjs_standalone', + }, }); project.bundler.addBundle('./src/lambdas/nextjs-bucket-deployment.ts', commonBundlingOptions); diff --git a/package.json b/package.json index 6ef1e032..2ad4540a 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "package": "npx projen package", "package-all": "npx projen package-all", "package:js": "npx projen package:js", + "package:python": "npx projen package:python", "post-compile": "npx projen post-compile", "post-upgrade": "npx projen post-upgrade", "pre-compile": "npx projen pre-compile", @@ -145,7 +146,12 @@ "stability": "stable", "jsii": { "outdir": "dist", - "targets": {}, + "targets": { + "python": { + "distName": "cdk-nextjs-standalone", + "module": "cdk_nextjs_standalone" + } + }, "tsc": { "outDir": "lib", "rootDir": "src"