forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: dedicated step for build and analysis (nodejs#5496)
- Loading branch information
1 parent
477ba59
commit 34130e7
Showing
2 changed files
with
160 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters