Skip to content

ci: added windows to the ci #36

ci: added windows to the ci

ci: added windows to the ci #36

name: "Bundle Analysis"
on: # yamllint disable-line rule:truthy
# eslint-disable-next-line yml/no-empty-mapping-value
pull_request: # yamllint disable-line rule:empty-values
push:
branches:
- "main"
# eslint-disable-next-line yml/no-empty-mapping-value
workflow_dispatch: # yamllint disable-line rule:empty-values
defaults:
run:
working-directory: "./"
permissions:
contents: "read" # to fetch code (actions/checkout)
pull-requests: "write"
concurrency:
group: "ci-bundle-analysis-${{ github.ref }}-1"
cancel-in-progress: true
jobs:
files-changed:
name: "Detect what files changed"
runs-on: "ubuntu-22.04"
timeout-minutes: 3
# Map a step output to a job output
outputs:
nextra: "${{ steps.changes.outputs.nextra }}"
steps:
- name: "Harden Runner"
uses: "step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09" # v2.5.1
with:
egress-policy: "audit"
- name: "Git checkout"
uses: "actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744" # v3.6.0
env:
GIT_COMMITTER_NAME: "GitHub Actions Shell"
GIT_AUTHOR_NAME: "GitHub Actions Shell"
EMAIL: "github-actions[bot]@users.noreply.github.com"
- name: "Check for file changes"
uses: "dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50" # v2.11.1
id: "changes"
with:
token: "${{ github.token }}"
filters: ".github/file-filters.yml"
nextra-analyze-bundle:
if: "needs.files-changed.outputs.nextra == 'true'"
needs: "files-changed"
name: "Analyze Bundle (nextra)"
runs-on: "ubuntu-latest"
steps:
- name: "Harden Runner"
uses: "step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09" # v2.5.1
with:
egress-policy: "audit"
- name: "Git checkout"
uses: "actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744" # v3.6.0
env:
GIT_COMMITTER_NAME: "GitHub Actions Shell"
GIT_AUTHOR_NAME: "GitHub Actions Shell"
EMAIL: "github-actions[bot]@users.noreply.github.com"
- uses: "pnpm/action-setup@d882d12c64e032187b2edb46d3a0d003b7a43598" # v2.4.0
- name: "Set node version to 18"
uses: "actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d" # v3.8.1
with:
node-version: "18"
cache: "pnpm"
- name: "Install packages"
run: "pnpm install --frozen-lockfile"
env:
SKIP_CHECK: "true"
- name: "Restore Next.js Build"
uses: "actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8" # v3.3.1
id: "restore-build-cache"
env:
cache-name: "cache-next-build"
with:
# if you use a custom build directory, replace all instances of `.next` in this file with your build directory
# ex: if your app builds to `dist`, replace `.next` with `dist`
path: "examples/nextra/.next/cache"
# change this if you prefer a more strict cache
key: "${{ runner.os }}-build-${{ env.cache-name }}"
- name: "Build @visulima/nextra-theme-docs"
run: "pnpm run build:prod:nextra-theme-docs"
- name: "Build Next.js App"
# change this if your site requires a custom build command
run: "cd examples/nextra && ./node_modules/.bin/next build"
# Here's the first place where next-bundle-analysis' own script is used
# This step pulls the raw bundle stats for the current bundle
- name: "Analyze Bundle"
run: "cd examples/nextra && npx -p [email protected] report"
- name: "Upload Bundle"
uses: "actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce" # v3.1.2
with:
name: "bundle"
path: "examples/nextra/.next/analyze/__bundle_analysis.json"
- name: "Download Base Branch Bundle Stats"
uses: "dawidd6/action-download-artifact@246dbf436b23d7c49e21a7ab8204ca9ecd1fe615" # v2.27.0
if: "success() && github.event.number"
with:
workflow: "nextjs-bundle-analysis.yml"
branch: "${{ github.event.pull_request.base.ref }}"
path: "examples/nextra/.next/analyze/base"
# And here's the second place - this runs after we have both the current and
# base branch bundle stats, and will compare them to determine what changed.
# There are two configurable arguments that come from package.json:
#
# - budget: optional, set a budget (bytes) against which size changes are measured
# it's set to 350kb here by default, as informed by the following piece:
# https://infrequently.org/2021/03/the-performance-inequality-gap/
#
# - red-status-percentage: sets the percent size increase where you get a red
# status indicator, defaults to 20%
#
# Either of these arguments can be changed or removed by editing the `nextBundleAnalysis`
# entry in your package.json file.
- name: "Compare With Base Branch Bundle"
if: "success() && github.event.number"
run: "ls -laR examples/nextra/.next/analyze/base && cd examples/nextra && npx -p [email protected] compare"
- name: "Get Comment body"
id: "get-comment-body"
if: "success() && github.event.number"
run: |
echo 'body<<EOF' >> $GITHUB_OUTPUT
echo '' >> $GITHUB_OUTPUT
echo '## Size changes' >> $GITHUB_OUTPUT
echo '' >> $GITHUB_OUTPUT
echo '<details>' >> $GITHUB_OUTPUT
echo '' >> $GITHUB_OUTPUT
cat examples/nextra/.next/analyze/__bundle_analysis_comment.txt >> $GITHUB_OUTPUT
echo '' >> $GITHUB_OUTPUT
echo '</details>' >> $GITHUB_OUTPUT
echo '' >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: "Comment"
uses: "marocchino/sticky-pull-request-comment@efaaab3fd41a9c3de579aba759d2552635e590fd" # v2.8.0
if: "success() && github.event.number"
with:
header: "next-bundle-analysis"
message: "${{ steps.get-comment-body.outputs.body }}"
# This check runs once all dependant jobs have passed
# It symbolizes that all required Frontend checks have succesfully passed (Or skipped)
# This check is the only required Github check
test-required-check:
needs: ["files-changed", "nextra-analyze-bundle"]
name: "Check Bundle Analysis Run"
# This is necessary since a failed/skipped dependent job would cause this job to be skipped
if: "always()"
runs-on: "ubuntu-22.04"
steps:
# If any jobs we depend on fail, we will fail since this is a required check
# NOTE: A timeout is considered a failure
- name: "Harden Runner"
uses: "step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09" # v2.5.1
with:
egress-policy: "audit"
- name: "Check for failures"
if: "contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')"
run: |
echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1