From d83c38365096bb1689f68d7ce6df5dd350c0623c Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Thu, 14 Dec 2023 21:16:58 +0200 Subject: [PATCH 1/7] ci: add preview link --- .github/workflows/preview.yml | 68 +++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/preview.yml diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml new file mode 100644 index 00000000..803d02cc --- /dev/null +++ b/.github/workflows/preview.yml @@ -0,0 +1,68 @@ +name: Preview +on: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Run install + uses: borales/actions-yarn@v4 + with: + cmd: install + - name: Build + run: yarn build + - name: Build Storybook + run: yarn build-storybook -o dist/storybook + - name: upload artifact + uses: actions/upload-artifact@v2 + with: + name: dist + path: dist + deploy-to-s3: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Download artifact + uses: actions/download-artifact@v2 + with: + name: dist + path: dist + - uses: shallwefootball/s3-upload-action@master + name: Upload trace to S3 + if: always() + id: s3-trace + continue-on-error: true + with: + aws_key_id: ${{ secrets.AWS_KEY_ID }} + aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}} + aws_bucket: noam-gaash.co.il + source_dir: dist + destination_dir: ${{ github.run_id }}/open-bus/${{ github.sha }} + - name: find comment + uses: peter-evans/find-comment@v1 + if: github.event_name == 'pull_request' + id: fc + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: 'Preview' + - name: update comment + uses: peter-evans/create-or-update-comment@v1 + if: steps.fc.outputs.comment-id + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + body: | + Preview: https://noam-gaash.co.il/${{ github.run_id }}/open-bus/${{ github.sha }}/index.html + - name: create comment + uses: peter-evans/create-or-update-comment@v1 + if: steps.fc.outputs.comment-id == '' + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + Preview: https://noam-gaash.co.il/${{ github.run_id }}/open-bus/${{ github.sha }}/index.html From 80fd019422ebc8dd6904a0faed23c47ea7af0409 Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Thu, 14 Dec 2023 21:25:02 +0200 Subject: [PATCH 2/7] perf: build storybook and react concurrently --- .github/workflows/preview.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 803d02cc..7243198e 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -16,6 +16,22 @@ jobs: cmd: install - name: Build run: yarn build + - name: upload artifact + uses: actions/upload-artifact@v2 + with: + name: dist + path: dist + build-storybook: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Run install + uses: borales/actions-yarn@v4 + with: + cmd: install - name: Build Storybook run: yarn build-storybook -o dist/storybook - name: upload artifact @@ -24,7 +40,7 @@ jobs: name: dist path: dist deploy-to-s3: - needs: build + needs: [build, build-storybook] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 From f9c193e2c33627528d12bd974c54f32c027219ef Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Thu, 14 Dec 2023 21:25:57 +0200 Subject: [PATCH 3/7] fix: url --- .github/workflows/preview.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 7243198e..ae321786 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -74,11 +74,11 @@ jobs: with: comment-id: ${{ steps.fc.outputs.comment-id }} body: | - Preview: https://noam-gaash.co.il/${{ github.run_id }}/open-bus/${{ github.sha }}/index.html + Preview: https://s3.amazonaws.com/noam-gaash.co.il/${{ github.run_id }}/open-bus/${{ github.sha }}/index.html - name: create comment uses: peter-evans/create-or-update-comment@v1 if: steps.fc.outputs.comment-id == '' with: issue-number: ${{ github.event.pull_request.number }} body: | - Preview: https://noam-gaash.co.il/${{ github.run_id }}/open-bus/${{ github.sha }}/index.html + Preview: https://s3.amazonaws.com/noam-gaash.co.il/${{ github.run_id }}/open-bus/${{ github.sha }}/index.html From 10deef67a1799a92a53be29e262ff2d87fb3695a Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Thu, 14 Dec 2023 21:35:55 +0200 Subject: [PATCH 4/7] fix: edit mode --- .github/workflows/preview.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index ae321786..ff3fb8b2 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -73,6 +73,7 @@ jobs: if: steps.fc.outputs.comment-id with: comment-id: ${{ steps.fc.outputs.comment-id }} + edit-mode: replace body: | Preview: https://s3.amazonaws.com/noam-gaash.co.il/${{ github.run_id }}/open-bus/${{ github.sha }}/index.html - name: create comment From cb50715d5155cea100fab584da17b1ce2e2e09fc Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Thu, 14 Dec 2023 21:40:50 +0200 Subject: [PATCH 5/7] fix: base url --- .github/workflows/preview.yml | 3 +++ vite.config.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index ff3fb8b2..25badcfa 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -2,6 +2,9 @@ name: Preview on: pull_request: +env: + ASSET_URL: https://s3.amazonaws.com/noam-gaash.co.il/${{ github.run_id }}/open-bus/${{ github.sha }} + jobs: build: runs-on: ubuntu-latest diff --git a/vite.config.ts b/vite.config.ts index ae259285..e4ff9d1b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,8 +1,11 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react-swc' +const ASSET_URL = process.env.ASSET_URL || '' + // https://vitejs.dev/config/ export default defineConfig({ + base: ASSET_URL, plugins: [react()], resolve: { alias: { From 6806e37d390970bbfbed8770521418a6cb3f48b1 Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Thu, 14 Dec 2023 21:42:55 +0200 Subject: [PATCH 6/7] perf: cache yarn --- .github/workflows/preview.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 25badcfa..87588b02 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -13,6 +13,7 @@ jobs: - uses: actions/setup-node@v3 with: node-version: 18 + cache: 'yarn' - name: Run install uses: borales/actions-yarn@v4 with: @@ -31,6 +32,7 @@ jobs: - uses: actions/setup-node@v3 with: node-version: 18 + cache: 'yarn' - name: Run install uses: borales/actions-yarn@v4 with: From 1b3396c40c20296fcea681d50cb4cbb75208d40e Mon Sep 17 00:00:00 2001 From: Noam Gaash Date: Thu, 14 Dec 2023 21:45:15 +0200 Subject: [PATCH 7/7] ci: add storybook link --- .github/workflows/preview.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 87588b02..a87976db 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -81,6 +81,7 @@ jobs: edit-mode: replace body: | Preview: https://s3.amazonaws.com/noam-gaash.co.il/${{ github.run_id }}/open-bus/${{ github.sha }}/index.html + Preview Storybook: https://s3.amazonaws.com/noam-gaash.co.il/${{ github.run_id }}/open-bus/${{ github.sha }}/storybook/index.html - name: create comment uses: peter-evans/create-or-update-comment@v1 if: steps.fc.outputs.comment-id == '' @@ -88,3 +89,4 @@ jobs: issue-number: ${{ github.event.pull_request.number }} body: | Preview: https://s3.amazonaws.com/noam-gaash.co.il/${{ github.run_id }}/open-bus/${{ github.sha }}/index.html + Preview Storybook: https://s3.amazonaws.com/noam-gaash.co.il/${{ github.run_id }}/open-bus/${{ github.sha }}/storybook/index.html