diff --git a/.github/workflows/build-and-analysis.yml b/.github/workflows/build-and-analysis.yml new file mode 100644 index 0000000000000..9b7f4276dd05e --- /dev/null +++ b/.github/workflows/build-and-analysis.yml @@ -0,0 +1,160 @@ +name: Build and Analysis Checks + +on: + push: + branches: + - main + pull_request_target: + branches: + - main + workflow_dispatch: + +defaults: + run: + working-directory: ./ + +permissions: + contents: read + actions: read + pull-requests: write + +jobs: + build: + name: Build on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + + steps: + - name: 'Use GNU tar instead BSD tar' + if: matrix.os == 'windows-latest' + shell: cmd + run: echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%" + + - name: Git Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: Restore Cache + uses: actions/cache/restore@v3 + with: + path: | + ~/.npm + .next/cache + node_modules/.cache + key: cache-${{ hashFiles('package-lock.json') }}- + restore-keys: cache- + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + cache: 'npm' + + - name: Install NPM packages + run: npm ci --no-audit --no-fund --omit=dev + + - name: Build Next.js + run: npx turbo build + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} + NODE_OPTIONS: '--max_old_space_size=4096' + NEXT_TELEMETRY_DISABLED: 1 + + - name: Analyse Build + run: npx -p nextjs-bundle-analysis report + + - name: Upload Build Analysis + uses: actions/upload-artifact@v3 + with: + name: bundle-analysis + path: .next/analyze/__bundle_analysis.json + + - name: Save Cache + uses: actions/cache/save@v3 + with: + path: | + ~/.npm + .next/cache + node_modules/.cache + key: cache-${{ hashFiles('package-lock.json') }} + + analysis: + name: Analysis + runs-on: ubuntu-latest + needs: build + + steps: + - name: Git Checkout + uses: actions/checkout@v3 + + - name: Restore Cache + uses: actions/cache/restore@v3 + with: + path: | + ~/.npm + .next/cache + node_modules/.cache + key: cache-${{ hashFiles('package-lock.json') }}- + restore-keys: cache- + + - name: Download PR Bundle Analysis + uses: actions/download-artifact@v3 + with: + name: bundle-analysis + path: .next/analyze + + - name: Copy PR Bundle Analysis (Fallback) + run: | + mkdir -p .next/analyze/base/bundle/ + cp .next/analyze/__bundle_analysis.json .next/analyze/base/bundle/__bundle_analysis.json + + - name: Download Base Bundle Analysis + uses: dawidd6/action-download-artifact@v2 + if: success() && github.event.number + with: + name: bundle-analysis + branch: ${{ github.event.pull_request.base.ref }} + path: .next/analyze/base/bundle + if_no_artifact_found: warn + + - name: Compare with base branch bundle + if: success() && github.event.number + run: ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare + + - name: Get Comment Body + id: get-comment-body + if: success() && github.event.number + run: | + echo "body<> $GITHUB_OUTPUT + echo "$(cat .next/analyze/__bundle_analysis_comment.txt)" >> $GITHUB_OUTPUT + echo EOF >> $GITHUB_OUTPUT + + - name: Find Comment + uses: peter-evans/find-comment@v2 + if: success() && github.event.number + id: find-comment-id + with: + issue-number: ${{ github.event.number }} + body-includes: '' + + - name: Create Comment + uses: peter-evans/create-or-update-comment@v2 + if: success() && github.event.number && steps.find-comment-id.outputs.comment-id == 0 + with: + issue-number: ${{ github.event.number }} + body: ${{ steps.get-comment-body.outputs.body }} + + - name: Update Comment + uses: peter-evans/create-or-update-comment@v2 + if: success() && github.event.number && steps.find-comment-id.outputs.comment-id != 0 + with: + issue-number: ${{ github.event.number }} + body: ${{ steps.get-comment-body.outputs.body }} + comment-id: ${{ steps.find-comment-id.outputs.comment-id }} + edit-mode: replace diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 3563c63f4b54f..b2aa3ba2a312f 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -11,7 +11,6 @@ defaults: permissions: contents: read actions: read - pull-requests: write jobs: lint: @@ -105,143 +104,3 @@ jobs: env: TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} TURBO_TEAM: ${{ secrets.TURBO_TEAM }} - - build: - name: Build on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest] - - steps: - - name: 'Use GNU tar instead BSD tar' - if: matrix.os == 'windows-latest' - shell: cmd - run: echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%" - - - name: Git Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 2 - - - name: Restore Cache - uses: actions/cache/restore@v3 - with: - path: | - ~/.npm - .next/cache - node_modules/.cache - key: cache-${{ hashFiles('package-lock.json') }}- - restore-keys: cache- - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version-file: '.nvmrc' - cache: 'npm' - - - name: Install NPM packages - run: npm ci --no-audit --no-fund --omit=dev - - - name: Build Next.js - run: npx turbo build - env: - TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} - TURBO_TEAM: ${{ secrets.TURBO_TEAM }} - NODE_OPTIONS: '--max_old_space_size=4096' - NEXT_TELEMETRY_DISABLED: 1 - - - name: Analyse Build - run: npx -p nextjs-bundle-analysis report - - - name: Upload Build Analysis - uses: actions/upload-artifact@v3 - with: - name: bundle-analysis - path: .next/analyze/__bundle_analysis.json - - - name: Save Cache - uses: actions/cache/save@v3 - with: - path: | - ~/.npm - .next/cache - node_modules/.cache - key: cache-${{ hashFiles('package-lock.json') }} - - analysis: - name: Analysis - runs-on: ubuntu-latest - needs: build - - steps: - - name: Git Checkout - uses: actions/checkout@v3 - - - name: Restore Cache - uses: actions/cache/restore@v3 - with: - path: | - ~/.npm - .next/cache - node_modules/.cache - key: cache-${{ hashFiles('package-lock.json') }}- - restore-keys: cache- - - - name: Download PR Bundle Analysis - uses: actions/download-artifact@v3 - with: - name: bundle-analysis - path: .next/analyze - - - name: Copy PR Bundle Analysis (Fallback) - run: | - mkdir -p .next/analyze/base/bundle/ - cp .next/analyze/__bundle_analysis.json .next/analyze/base/bundle/__bundle_analysis.json - - - name: Download Base Bundle Analysis - uses: dawidd6/action-download-artifact@v2 - if: success() && github.event.number - with: - name: bundle-analysis - branch: ${{ github.event.pull_request.base.ref }} - path: .next/analyze/base/bundle - if_no_artifact_found: warn - - - name: Compare with base branch bundle - if: success() && github.event.number - run: ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare - - - name: Get Comment Body - id: get-comment-body - if: success() && github.event.number - run: | - echo "body<> $GITHUB_OUTPUT - echo "$(cat .next/analyze/__bundle_analysis_comment.txt)" >> $GITHUB_OUTPUT - echo EOF >> $GITHUB_OUTPUT - - - name: Find Comment - uses: peter-evans/find-comment@v2 - if: success() && github.event.number - id: find-comment-id - with: - issue-number: ${{ github.event.number }} - body-includes: '' - - - name: Create Comment - uses: peter-evans/create-or-update-comment@v2 - if: success() && github.event.number && steps.find-comment-id.outputs.comment-id == 0 - with: - issue-number: ${{ github.event.number }} - body: ${{ steps.get-comment-body.outputs.body }} - - - name: Update Comment - uses: peter-evans/create-or-update-comment@v2 - if: success() && github.event.number && steps.find-comment-id.outputs.comment-id != 0 - with: - issue-number: ${{ github.event.number }} - body: ${{ steps.get-comment-body.outputs.body }} - comment-id: ${{ steps.find-comment-id.outputs.comment-id }} - edit-mode: replace