From f9793bd93b353f227d194b337712f9e58c017caf Mon Sep 17 00:00:00 2001 From: ChiragSharma Date: Thu, 19 Sep 2024 18:41:02 +0530 Subject: [PATCH 1/3] feat(nx-ci-cd): adding nx release in the monorepo --- .github/workflows/test-publish-package.yml | 118 +++++++++++++++++++++ nx.json | 43 +++++++- package.json | 3 +- 3 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test-publish-package.yml diff --git a/.github/workflows/test-publish-package.yml b/.github/workflows/test-publish-package.yml new file mode 100644 index 0000000000..7481989538 --- /dev/null +++ b/.github/workflows/test-publish-package.yml @@ -0,0 +1,118 @@ +name: Under Testing - Publish-packages + +on: + push: + branches: + - dev + workflow_call: + inputs: + branch: + type: string + description: "Branch Name on which this action checks out" + required: false + default: "dev" + +concurrency: ${{ github.workflow }}-${{ github.ref }} + +jobs: + ci-workflow: + uses: ./.github/workflows/ci.yml + packages: + name: packages + runs-on: ubuntu-latest + needs: [ ci-workflow ] + if: ${{ needs.ci-workflow.result=='success' }} + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18.12.1 + + - name: Install pnpm + uses: pnpm/action-setup@v2 + id: pnpm-install + with: + version: 8 + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install dependencies + shell: bash + run: pnpm install + + - name: Update Packages and Create Release + run: | + pnpm nx release --specifier prerelease --skip-publish + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + + publish_packages: + name: publish-packages + runs-on: ubuntu-latest + # needs: [ ci-workflow ] + # if: ${{ github.ref=='dev' || inputs.branch=='dev' }} + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: ${{ inputs.branch }} + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18.12.1 + + - name: Install pnpm + uses: pnpm/action-setup@v2 + id: pnpm-install + with: + version: 8 + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install dependencies + shell: bash + run: pnpm install + + # - name: Update Packages and Create Release + # run: | + # pnpm nx release publish --projects=packages/common,packages/react-pdf-toolkit,sdks/web-ui-sdk,sdks/workflow-browser-sdk,sdks/workflow-node-sdk + # env: + # GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + # NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Update Packages and Create Release + run: | + pnpm nx release publish --registry https://registry.npmjs.org + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/nx.json b/nx.json index 815af8b334..3b5b5dcfa5 100644 --- a/nx.json +++ b/nx.json @@ -33,5 +33,46 @@ "dependsOn": [{ "projects": "self", "target": "build" }] } }, - "defaultBase": "main" + "defaultBase": "main", + "release": { + "projectsRelationship": "independent", + "releaseTagPattern": "{projectName}@{version}", + "conventionalCommits": { + "types": { + "chore": { + "semverBump": "patch" + }, + "feat": { + "semverBump": "patch" + }, + "fix": { + "semverBump": "patch" + } + } + }, + "projects": [ + "packages/*", + "sdks/*", + "services/websocket-service", + "services/workflows-service", + "!private" + ], + "version": { + "conventionalCommits": true + }, + "changelog": { + "projectChangelogs": { + "renderOptions": { + "authors": true, + "mapAuthorsToGitHubUsernames": true, + "commitReferences": true, + "versionTitleDate": true + }, + "createRelease": "github" + }, + "workspaceChangelog": { + "createRelease": "github" + } + } + } } diff --git a/package.json b/package.json index 48951e4edd..43b513891c 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,8 @@ "inquirer": "^10.2.0", "lint-staged": "^11.2.6", "ngrok": "5.0.0-beta.2", - "nx": "15.0.2", + "@nx/js": "^19.5.7", + "nx": "^19.5.7", "prettier": "^2.8.7" }, "dependencies": { From ebec5a2cc1dfb81c2d48a628ba55499e563e4778 Mon Sep 17 00:00:00 2001 From: ChiragSharma Date: Fri, 20 Sep 2024 10:46:05 +0000 Subject: [PATCH 2/3] feat(ci-cd): adding conditions for package step success --- .github/workflows/test-publish-package.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-publish-package.yml b/.github/workflows/test-publish-package.yml index 7481989538..3093460eae 100644 --- a/.github/workflows/test-publish-package.yml +++ b/.github/workflows/test-publish-package.yml @@ -59,15 +59,15 @@ jobs: - name: Update Packages and Create Release run: | - pnpm nx release --specifier prerelease --skip-publish + pnpm nx release --skip-publish env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} publish_packages: name: publish-packages runs-on: ubuntu-latest - # needs: [ ci-workflow ] - # if: ${{ github.ref=='dev' || inputs.branch=='dev' }} + needs: [ packages ] + if: ${{ (github.ref=='dev' || inputs.branch=='dev') && needs.packages.result=='success' }} steps: - name: Checkout From 40207883e0f6c2b3c9f3bd5a5e6b11f21dc440f1 Mon Sep 17 00:00:00 2001 From: ChiragSharma Date: Thu, 26 Sep 2024 12:26:34 +0000 Subject: [PATCH 3/3] feat(nx): added the config to update dependent projects that are not mentioned in release --- nx.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nx.json b/nx.json index 3b5b5dcfa5..823cd70352 100644 --- a/nx.json +++ b/nx.json @@ -58,7 +58,10 @@ "!private" ], "version": { - "conventionalCommits": true + "conventionalCommits": true, + "generatorOptions": { + "updateDependents": "auto" + } }, "changelog": { "projectChangelogs": {