From a532efe3e18817a46fbcdc032cab6b4ec27fc1e6 Mon Sep 17 00:00:00 2001 From: devanshkansagra Date: Tue, 3 Sep 2024 14:28:10 +0530 Subject: [PATCH 1/7] Implemented workflow to deploy preview of pr changes --- .github/workflows/cd-pr.yml | 40 ++++++++++++++ .github/workflows/ci-pr.yml | 103 ++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 .github/workflows/cd-pr.yml create mode 100644 .github/workflows/ci-pr.yml diff --git a/.github/workflows/cd-pr.yml b/.github/workflows/cd-pr.yml new file mode 100644 index 000000000..8fa1d63ac --- /dev/null +++ b/.github/workflows/cd-pr.yml @@ -0,0 +1,40 @@ +name: Deploy the Pull Request Changes to GitHub pages + +on: + workflow_run: + workflows: ["Continuous Integration of Pull Request"] + types: + - completed + +permissions: + contents: write + pages: write + id-token: write + +env: + STORYBOOK_RC_HOST: "https://demo.qa.rocket.chat" + +jobs: + deploy: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + + steps: + - uses: actions/download-artifact@v4 + with: + name: github-pages + path: build/ + github-token: ${{github.token}} + repository: ${{github.repository}} + run-id: ${{github.event.workflow_run.id}} + + - name: Deploy to GitHub Pages + uses: crazy-max/ghaction-github-pages@v2 + with: + target_branch: gh-deploy + build_dir: build/ + commit_message: "Deploy to Github Pages" + jekyll: false + keep_history: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml new file mode 100644 index 000000000..75b839ac8 --- /dev/null +++ b/.github/workflows/ci-pr.yml @@ -0,0 +1,103 @@ +name: Continuous Integration of Pull Request + +on: + pull_request: + types: + - opened + - reopened + - synchronize + +permissions: + contents: write + pages: write + id-token: write + +concurrency: + group: ${{github.workflow}}-${{github.ref}} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "16.19.0" + + - name: Install Dependencies + run: yarn + + - name: Filter the packages + uses: dorny/paths-filter@v3 + id: changes + with: + filters: | + react: + - 'packages/react/**' + ui-elements: + - 'packages/ui-elements/**' + layout_editor: + - 'packages/layout_editor/**' + docs: + - 'packages/docs/**' + + - name: Create Build Directory + run: mkdir -p build/pulls/${{github.event.number}} + + - name: Build Storybook + if: steps.changes.outputs.react == 'true' + run: yarn build:storybook + working-directory: packages/react + + - name: Prepare Build for Storybook + if: steps.changes.outputs.react == 'true' + run: mv -v packages/react/storybook-static/* build/pulls/${{github.event.number}}/ + + - name: Build UI-Elements + if: steps.changes.outputs.ui-elements == 'true' + run: yarn build:storybook + working-directory: packages/ui-elements + + - name: Prepare Build for UI-Elements + if: steps.changes.outputs.ui-elements == 'true' + run: mv -v packages/ui-elements/storybook-static/* build/pulls/${{github.event.number}}/ + + - name: Setup Node.js 18 for Docs + if: steps.changes.outputs.docs == 'true' + uses: actions/setup-node@v4 + with: + node-version: "18.x" + + - name: "Install dependencies for docs" + if: steps.changes.outputs.docs == 'true' + run: yarn install + working-directory: packages/docs/ + + - name: Build Docs + if: steps.changes.outputs.docs == 'true' + run: yarn build + working-directory: packages/docs + + - name: Prepare Build for Docs + if: steps.changes.outputs.docs == 'true' + run: mv -v packages/docs/build/* build/pulls/${{github.event.number}}/ + + - name: Build Layout Editor + if: steps.changes.outputs.layout_editor == 'true' + run: yarn build + working-directory: packages/layout_editor + + - name: Prepare Build for Layout Editor + if: steps.changes.outputs.layout_editor == 'true' + run: mv -v packages/layout_editor/dist/* build/pulls/${{github.event.number}}/ + + - name: Upload Artifacts + uses: actions/upload-artifact@v2 + with: + name: github-pages + path: build/ From 26458326e8b13e9105fbbfbfdaf708db1d3a5bf3 Mon Sep 17 00:00:00 2001 From: devanshkansagra Date: Wed, 4 Sep 2024 14:23:43 +0530 Subject: [PATCH 2/7] Temporarily removed docs and layout_editor from preview deployment --- .github/workflows/ci-pr.yml | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml index 75b839ac8..f16182383 100644 --- a/.github/workflows/ci-pr.yml +++ b/.github/workflows/ci-pr.yml @@ -41,10 +41,6 @@ jobs: - 'packages/react/**' ui-elements: - 'packages/ui-elements/**' - layout_editor: - - 'packages/layout_editor/**' - docs: - - 'packages/docs/**' - name: Create Build Directory run: mkdir -p build/pulls/${{github.event.number}} @@ -67,34 +63,6 @@ jobs: if: steps.changes.outputs.ui-elements == 'true' run: mv -v packages/ui-elements/storybook-static/* build/pulls/${{github.event.number}}/ - - name: Setup Node.js 18 for Docs - if: steps.changes.outputs.docs == 'true' - uses: actions/setup-node@v4 - with: - node-version: "18.x" - - - name: "Install dependencies for docs" - if: steps.changes.outputs.docs == 'true' - run: yarn install - working-directory: packages/docs/ - - - name: Build Docs - if: steps.changes.outputs.docs == 'true' - run: yarn build - working-directory: packages/docs - - - name: Prepare Build for Docs - if: steps.changes.outputs.docs == 'true' - run: mv -v packages/docs/build/* build/pulls/${{github.event.number}}/ - - - name: Build Layout Editor - if: steps.changes.outputs.layout_editor == 'true' - run: yarn build - working-directory: packages/layout_editor - - - name: Prepare Build for Layout Editor - if: steps.changes.outputs.layout_editor == 'true' - run: mv -v packages/layout_editor/dist/* build/pulls/${{github.event.number}}/ - name: Upload Artifacts uses: actions/upload-artifact@v2 From f9df020f673f7332bd928a830d2211a60e6cab43 Mon Sep 17 00:00:00 2001 From: devanshkansagra Date: Wed, 4 Sep 2024 19:51:49 +0530 Subject: [PATCH 3/7] Fixed: deploy previews on multi-package updates --- .github/workflows/ci-pr.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml index f16182383..26c1b3109 100644 --- a/.github/workflows/ci-pr.yml +++ b/.github/workflows/ci-pr.yml @@ -61,7 +61,13 @@ jobs: - name: Prepare Build for UI-Elements if: steps.changes.outputs.ui-elements == 'true' - run: mv -v packages/ui-elements/storybook-static/* build/pulls/${{github.event.number}}/ + run: | + if [ '$(ls -A build/pulls/${{github.event.number}})/' ]; then + mkdir -p build/pulls/${{github.event.number}}/ui-elements + mv -v packages/ui-elements/storybook-static/* build/pulls/${{github.event.number}}/ui-elements + else + mv -v packages/ui-elements/storybook-static/* build/pulls/${{github.event.number}}/ + fi - name: Upload Artifacts From 1b507d9f12e3cca411cc247505d85d702bbe27fc Mon Sep 17 00:00:00 2001 From: devanshkansagra Date: Mon, 9 Sep 2024 20:27:36 +0530 Subject: [PATCH 4/7] Fixed a minor script issue in the previous commit --- .github/workflows/ci-pr.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml index 26c1b3109..e80b500b9 100644 --- a/.github/workflows/ci-pr.yml +++ b/.github/workflows/ci-pr.yml @@ -62,13 +62,12 @@ jobs: - name: Prepare Build for UI-Elements if: steps.changes.outputs.ui-elements == 'true' run: | - if [ '$(ls -A build/pulls/${{github.event.number}})/' ]; then - mkdir -p build/pulls/${{github.event.number}}/ui-elements - mv -v packages/ui-elements/storybook-static/* build/pulls/${{github.event.number}}/ui-elements - else - mv -v packages/ui-elements/storybook-static/* build/pulls/${{github.event.number}}/ - fi - + if [ -z "$(ls -A build/pulls/${{github.event.number}})" ]; then + mv -v packages/ui-elements/storybook-static/* build/pulls/${{github.event.number}}/ + else + mkdir -p build/pulls/${{github.event.number}}/ui-elements + mv -v packages/ui-elements/storybook-static/* build/pulls/${{github.event.number}}/ui-elements/ + fi - name: Upload Artifacts uses: actions/upload-artifact@v2 From 89cd72ac62a81864f333e4e3457c7018802f3987 Mon Sep 17 00:00:00 2001 From: Devansh Date: Sat, 14 Sep 2024 23:37:16 +0530 Subject: [PATCH 5/7] Removed the cd-pr.yml file and added new action to deploy pr-previews --- .github/workflows/cd-pr.yml | 40 ------------------------------- .github/workflows/ci-pr.yml | 47 ++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 61 deletions(-) delete mode 100644 .github/workflows/cd-pr.yml diff --git a/.github/workflows/cd-pr.yml b/.github/workflows/cd-pr.yml deleted file mode 100644 index 8fa1d63ac..000000000 --- a/.github/workflows/cd-pr.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Deploy the Pull Request Changes to GitHub pages - -on: - workflow_run: - workflows: ["Continuous Integration of Pull Request"] - types: - - completed - -permissions: - contents: write - pages: write - id-token: write - -env: - STORYBOOK_RC_HOST: "https://demo.qa.rocket.chat" - -jobs: - deploy: - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} - - steps: - - uses: actions/download-artifact@v4 - with: - name: github-pages - path: build/ - github-token: ${{github.token}} - repository: ${{github.repository}} - run-id: ${{github.event.workflow_run.id}} - - - name: Deploy to GitHub Pages - uses: crazy-max/ghaction-github-pages@v2 - with: - target_branch: gh-deploy - build_dir: build/ - commit_message: "Deploy to Github Pages" - jekyll: false - keep_history: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml index e80b500b9..0774f0dbb 100644 --- a/.github/workflows/ci-pr.yml +++ b/.github/workflows/ci-pr.yml @@ -1,25 +1,23 @@ -name: Continuous Integration of Pull Request - +name: Deploy PR previews +concurrency: preview-${{ github.ref }} on: pull_request: types: - opened - reopened - synchronize - -permissions: - contents: write - pages: write - id-token: write - -concurrency: - group: ${{github.workflow}}-${{github.ref}} - cancel-in-progress: true + - closed jobs: build: runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + pages: write + id-token: write + steps: - name: Checkout code uses: actions/checkout@v2 @@ -43,7 +41,7 @@ jobs: - 'packages/ui-elements/**' - name: Create Build Directory - run: mkdir -p build/pulls/${{github.event.number}} + run: mkdir -p build/ - name: Build Storybook if: steps.changes.outputs.react == 'true' @@ -52,7 +50,7 @@ jobs: - name: Prepare Build for Storybook if: steps.changes.outputs.react == 'true' - run: mv -v packages/react/storybook-static/* build/pulls/${{github.event.number}}/ + run: mv -v packages/react/storybook-static/* build/ - name: Build UI-Elements if: steps.changes.outputs.ui-elements == 'true' @@ -62,15 +60,22 @@ jobs: - name: Prepare Build for UI-Elements if: steps.changes.outputs.ui-elements == 'true' run: | - if [ -z "$(ls -A build/pulls/${{github.event.number}})" ]; then - mv -v packages/ui-elements/storybook-static/* build/pulls/${{github.event.number}}/ + if [ -z "$(ls -A build/)" ]; then + mv -v packages/ui-elements/storybook-static/* build/ else - mkdir -p build/pulls/${{github.event.number}}/ui-elements - mv -v packages/ui-elements/storybook-static/* build/pulls/${{github.event.number}}/ui-elements/ + mkdir -p build/ui-elements + mv -v packages/ui-elements/storybook-static/* build/ui-elements/ fi - - name: Upload Artifacts - uses: actions/upload-artifact@v2 + - uses: rossjrw/pr-preview-action@v1 + with: + source-dir: build + preview-branch: gh-deploy + umbrella-dir: pulls + action: auto + + - uses: rossjrw/pr-preview-action@v1 + if: github.event.action == 'closed' || github.event.pull_request.merged == true with: - name: github-pages - path: build/ + source-dir: build + action: remove From 8514fed6fa7a35b049bc63c06a3b9f0d18b997b6 Mon Sep 17 00:00:00 2001 From: Devansh Date: Mon, 30 Sep 2024 22:26:45 +0530 Subject: [PATCH 6/7] Added layout_editor and docs for pr-deployment --- .github/workflows/ci-pr.yml | 65 +++++++++++++++++++++++++-- packages/docs/docusaurus.config.js | 2 +- packages/layout_editor/vite.config.ts | 2 +- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml index 0774f0dbb..04ba3d7c2 100644 --- a/.github/workflows/ci-pr.yml +++ b/.github/workflows/ci-pr.yml @@ -39,26 +39,30 @@ jobs: - 'packages/react/**' ui-elements: - 'packages/ui-elements/**' + layout_editor: + - 'packages/layout_editor/**' + docs: + - 'packages/docs/**' - name: Create Build Directory run: mkdir -p build/ - name: Build Storybook - if: steps.changes.outputs.react == 'true' + if: steps.changes.outputs.react == 'true' && github.event.action != 'closed' run: yarn build:storybook working-directory: packages/react - name: Prepare Build for Storybook - if: steps.changes.outputs.react == 'true' + if: steps.changes.outputs.react == 'true' && github.event.action != 'closed' run: mv -v packages/react/storybook-static/* build/ - name: Build UI-Elements - if: steps.changes.outputs.ui-elements == 'true' + if: steps.changes.outputs.ui-elements == 'true' && github.event.action != 'closed' run: yarn build:storybook working-directory: packages/ui-elements - name: Prepare Build for UI-Elements - if: steps.changes.outputs.ui-elements == 'true' + if: steps.changes.outputs.ui-elements == 'true' && github.event.action != 'closed' run: | if [ -z "$(ls -A build/)" ]; then mv -v packages/ui-elements/storybook-static/* build/ @@ -67,6 +71,59 @@ jobs: mv -v packages/ui-elements/storybook-static/* build/ui-elements/ fi + - name: Build Layout Editor + if: steps.changes.outputs.layout_editor == 'true' && github.event.action != 'closed' + run: | + if [ -z "$(ls -A build/)" ]; then + export BASE_URL=/EmbeddedChat/pulls/pr-${{ github.event.number }}/ + else + export BASE_URL=/EmbeddedChat/pulls/pr-${{ github.event.number }}/layout_editor/ + fi + yarn build + working-directory: packages/layout_editor + + - name: Prepare build for Layout_editor + if: steps.changes.outputs.layout_editor == 'true' && github.event.action != 'closed' + run: | + if [ -z "$(ls -A build/)" ]; then + mv -v packages/layout_editor/dist/* build/ + else + mkdir -p build/layout_editor + mv -v packages/layout_editor/dist/* build/layout_editor/ + fi + + - name: Setup Node.js for Docs + if: steps.changes.outputs.docs == 'true' && github.event.action != 'closed' + uses: actions/setup-node@v4 + with: + node-version: "18.x" + + - name: "Install dependencies for docs" + if: steps.changes.outputs.docs == 'true' && github.event.action != 'closed' + run: yarn install + working-directory: packages/docs/ + + - name: Build Docs + if: steps.changes.outputs.docs == 'true' && github.event.action != 'closed' + run: | + if [ -z "$(ls -A build/)" ]; then + export BASEURL=/EmbeddedChat/pulls/pr-${{ github.event.number }}/ + else + export BASEURL=/EmbeddedChat/pulls/pr-${{ github.event.number }}/docs + fi + yarn build + working-directory: packages/docs + + - name: Prepare build for Docs + if: steps.changes.outputs.docs == 'true' && github.event.action != 'closed' + run: | + if [ -z "$(ls -A build/)" ]; then + mv -v packages/docs/build/* build/ + else + mkdir -p build/docs + mv -v packages/docs/build/* build/docs/ + fi + - uses: rossjrw/pr-preview-action@v1 with: source-dir: build diff --git a/packages/docs/docusaurus.config.js b/packages/docs/docusaurus.config.js index f9073bfa8..2879f3e0b 100644 --- a/packages/docs/docusaurus.config.js +++ b/packages/docs/docusaurus.config.js @@ -17,7 +17,7 @@ const config = { url: "https://rocketchat.github.io/", // Set the // pathname under which your site is served // For GitHub pages deployment, it is often '//' - baseUrl: "/EmbeddedChat/docs/", + baseUrl: process.env.BASEURL || "/EmbeddedChat/docs/", // GitHub pages deployment config. // If you aren't using GitHub pages, you don't need these. diff --git a/packages/layout_editor/vite.config.ts b/packages/layout_editor/vite.config.ts index 2b9daff2d..8785d1a22 100644 --- a/packages/layout_editor/vite.config.ts +++ b/packages/layout_editor/vite.config.ts @@ -11,5 +11,5 @@ export default defineConfig({ }, }), ], - base: "/EmbeddedChat/layout_editor" + base: process.env.BASE_URL || '/EmbeddedChat/layout_editor', }); From a70f026c5eeaf55fb4815fe15f0028aa3d43bf0f Mon Sep 17 00:00:00 2001 From: Devansh Date: Mon, 30 Sep 2024 22:40:59 +0530 Subject: [PATCH 7/7] Added necessary permissions --- .github/workflows/deploy.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3099455b0..15fbf08c2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -5,17 +5,19 @@ on: branches: - develop -permissions: - contents: write - pages: write - id-token: write - env: STORYBOOK_RC_HOST: "https://demo.qa.rocket.chat" jobs: build-and-deploy: runs-on: ubuntu-latest + + permissions: + contents: write + pull-requests: write + pages: write + id-token: write + environment: name: github-pages url: "https://rocketchat.github.io/EmbeddedChat/"