Skip to content

Commit

Permalink
chore: dedicated step for build and analysis (#5496)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovflowd authored Jul 10, 2023
1 parent a99be64 commit 2208a72
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 141 deletions.
160 changes: 160 additions & 0 deletions .github/workflows/build-and-analysis.yml
Original file line number Diff line number Diff line change
@@ -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<<EOF" >> $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: '<!-- __NEXTJS_BUNDLE -->'

- 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
141 changes: 0 additions & 141 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ defaults:
permissions:
contents: read
actions: read
pull-requests: write

jobs:
lint:
Expand Down Expand Up @@ -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<<EOF" >> $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: '<!-- __NEXTJS_BUNDLE -->'

- 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

2 comments on commit 2208a72

@vercel
Copy link

@vercel vercel bot commented on 2208a72 Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 2208a72 Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nodejs-org-stories – ./

nodejs-org-stories-git-main-openjs.vercel.app
nodejs-org-stories-openjs.vercel.app
nodejs-org-storybook.vercel.app

Please sign in to comment.