From 984d36f8819ceb4a924f8c0f536bd78219197393 Mon Sep 17 00:00:00 2001 From: mtahir-cloudkitect Date: Thu, 18 Apr 2024 08:21:30 -0700 Subject: [PATCH] feat: adding support for publishing to nuget --- .../release_cloudkitect-components.yml | 38 +++++++++++++++++++ .projenrc.ts | 5 +++ .../components/.github/workflows/build.yml | 32 ++++++++++++++++ .../components/.projen/tasks.json | 12 ++++++ packages/@cloudkitect/components/package.json | 5 +++ packages/@cloudkitect/components/project.json | 7 ++++ 6 files changed, 99 insertions(+) diff --git a/.github/workflows/release_cloudkitect-components.yml b/.github/workflows/release_cloudkitect-components.yml index 83a651e..8e83f6a 100644 --- a/.github/workflows/release_cloudkitect-components.yml +++ b/.github/workflows/release_cloudkitect-components.yml @@ -168,3 +168,41 @@ jobs: TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} run: npx -p publib@latest publib-pypi + release_nuget: + name: Publish to NuGet Gallery + needs: release + runs-on: ubuntu-latest + permissions: + contents: read + if: needs.release.outputs.tag_exists != 'true' && needs.release.outputs.latest_commit == github.sha + steps: + - uses: actions/setup-node@v4 + with: + node-version: 18.x + - uses: actions/setup-dotnet@v3 + with: + dotnet-version: 3.x + - name: Download build artifacts + uses: actions/download-artifact@v4 + with: + name: build-artifact + path: dist + - name: Restore build artifact permissions + run: cd dist && setfacl --restore=permissions-backup.acl + continue-on-error: true + - name: Setup pnpm + uses: pnpm/action-setup@v3 + with: + version: "8" + - name: Prepare Repository + run: mv dist .repo + - name: Install Dependencies + run: cd .repo && pnpm i --no-frozen-lockfile + - name: Create dotnet artifact + run: cd .repo && npx projen package:dotnet + - name: Collect dotnet Artifact + run: mv .repo/dist dist + - name: Release + env: + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + run: npx -p publib@latest publib-nuget diff --git a/.projenrc.ts b/.projenrc.ts index 4596d79..11f38a4 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -59,12 +59,17 @@ const components = new AwsCdkConstructLibrary({ distName: 'cloudkitect.components', module: 'cloudkitect.components' }, + publishToNuget: { + dotNetNamespace: 'CloudKitect.Components', + packageId: 'CloudKitect.Components' + } }); components.synth() const releaseYaml = project.tryFindObjectFile('.github/workflows/release_cloudkitect-components.yml'); releaseYaml!.addOverride('jobs.release_npm.steps.5.run', 'cd .repo && pnpm i --no-frozen-lockfile') releaseYaml!.addOverride('jobs.release_pypi.steps.6.run', 'cd .repo && pnpm i --no-frozen-lockfile') +releaseYaml!.addOverride('jobs.release_nuget.steps.6.run', 'cd .repo && pnpm i --no-frozen-lockfile') const patterns = new AwsCdkConstructLibrary({ ...subProjectSettings, diff --git a/packages/@cloudkitect/components/.github/workflows/build.yml b/packages/@cloudkitect/components/.github/workflows/build.yml index 3b877c0..70b9dd8 100644 --- a/packages/@cloudkitect/components/.github/workflows/build.yml +++ b/packages/@cloudkitect/components/.github/workflows/build.yml @@ -150,3 +150,35 @@ jobs: run: cd .repo && npx projen package:python - name: Collect python Artifact run: mv .repo/dist dist + package-dotnet: + needs: build + runs-on: ubuntu-latest + permissions: {} + if: "! needs.build.outputs.self_mutation_happened" + steps: + - uses: actions/setup-node@v4 + with: + node-version: 18.x + - uses: actions/setup-dotnet@v3 + with: + dotnet-version: 3.x + - name: Download build artifacts + uses: actions/download-artifact@v4 + with: + name: build-artifact + path: dist + - name: Restore build artifact permissions + run: cd dist && setfacl --restore=permissions-backup.acl + continue-on-error: true + - name: Setup pnpm + uses: pnpm/action-setup@v3 + with: + version: "8" + - name: Prepare Repository + run: mv dist .repo + - name: Install Dependencies + run: cd .repo && pnpm i --frozen-lockfile + - name: Create dotnet artifact + run: cd .repo && npx projen package:dotnet + - name: Collect dotnet Artifact + run: mv .repo/dist dist diff --git a/packages/@cloudkitect/components/.projen/tasks.json b/packages/@cloudkitect/components/.projen/tasks.json index 9a4c88e..bd02abc 100644 --- a/packages/@cloudkitect/components/.projen/tasks.json +++ b/packages/@cloudkitect/components/.projen/tasks.json @@ -116,6 +116,18 @@ }, { "spawn": "package:python" + }, + { + "spawn": "package:dotnet" + } + ] + }, + "package:dotnet": { + "name": "package:dotnet", + "description": "Create dotnet language bindings", + "steps": [ + { + "exec": "jsii-pacmak -v --pack-command 'pnpm pack' --target dotnet" } ] }, diff --git a/packages/@cloudkitect/components/package.json b/packages/@cloudkitect/components/package.json index 70d7b72..f8f3993 100644 --- a/packages/@cloudkitect/components/package.json +++ b/packages/@cloudkitect/components/package.json @@ -15,6 +15,7 @@ "eslint": "npx projen eslint", "package": "npx projen package", "package-all": "npx projen package-all", + "package:dotnet": "npx projen package:dotnet", "package:js": "npx projen package:js", "package:python": "npx projen package:python", "post-compile": "npx projen post-compile", @@ -127,6 +128,10 @@ "python": { "distName": "cloudkitect.components", "module": "cloudkitect.components" + }, + "dotnet": { + "namespace": "CloudKitect.Components", + "packageId": "CloudKitect.Components" } }, "tsc": { diff --git a/packages/@cloudkitect/components/project.json b/packages/@cloudkitect/components/project.json index 29b8ffd..ffc1802 100644 --- a/packages/@cloudkitect/components/project.json +++ b/packages/@cloudkitect/components/project.json @@ -135,6 +135,13 @@ "cwd": "packages/@cloudkitect/components" } }, + "package:dotnet": { + "executor": "nx:run-commands", + "options": { + "command": "pnpm exec projen package:dotnet", + "cwd": "packages/@cloudkitect/components" + } + }, "docgen": { "executor": "nx:run-commands", "options": {