Skip to content

Remove unused assets #28066

Remove unused assets

Remove unused assets #28066

Workflow file for this run

# This is more or less a copy of
# https://github.com/mdn/content/blob/main/.github/workflows/pr-test.yml
# but done in a way that it first checks out mdn/translated-content (or
# fork of) and _then_ checks out mdn/content which has the relevant
# CI related tooling.
name: PR Test
on:
pull_request:
branches:
- main
paths:
- .nvmrc
- ".github/workflows/pr-test.yml"
- "files/**"
jobs:
tests:
runs-on: ubuntu-latest
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
steps:
- uses: actions/checkout@v3
# Needed otherswise it will check out a merge commit which means
# you can't get a `git diff` for this PR compared to its base.
# with:
# ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/checkout@v3
with:
repository: mdn/content
path: mdn/content
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
cache: "yarn"
cache-dependency-path: mdn/content/yarn.lock
- name: Install all yarn packages
working-directory: ${{ github.workspace }}/mdn/content
run: |
yarn --frozen-lockfile
env:
# https://github.com/microsoft/vscode-ripgrep#github-api-limit-note
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get changed files
run: |
# Use the GitHub API to get the list of changed files
# documenation: https://docs.github.com/rest/commits/commits#compare-two-commits
DIFF_DOCUMENTS=$(gh api repos/{owner}/{repo}/compare/${{ env.BASE_SHA }}...${{ env.HEAD_SHA }} \
--jq '.files | .[] | select(.status|IN("added", "modified", "renamed", "copied", "changed")) | .filename')
# filter out files that are not markdown files
GIT_DIFF_CONTENT=$(echo "${DIFF_DOCUMENTS}" | egrep -i "^files/.*\.md$" | xargs)
echo "GIT_DIFF_CONTENT=${GIT_DIFF_CONTENT}" >> $GITHUB_ENV
# filter out files that are not attachments
# note that we should get the absolute path of the changed attachments
GIT_DIFF_FILES=$(echo "${DIFF_DOCUMENTS}" | egrep -i "^files/.*\.(png|jpeg|jpg|gif|svg|webp)$" | xargs readlink -e | xargs)
echo "GIT_DIFF_FILES=${GIT_DIFF_FILES}" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build changed content
if: ${{ env.GIT_DIFF_CONTENT }}
env:
CONTENT_ROOT: ${{ github.workspace }}/mdn/content/files
CONTENT_TRANSLATED_ROOT: ${{ github.workspace }}/files
# This is so that if there's a single 'unsafe_html' flaw, it
# completely fails the build.
# But all other flaws should be 'warn' so that we can include
# information about the flaws when we analyze the built PR.
BUILD_FLAW_LEVELS: "unsafe_html: error, *:warn"
# Because we build these pages in a way that you get a toolbar,
# so the flaws can be displayed, but we don't want any of the
# other toolbar features like "Fix fixable flaws" or "Quick-edit"
# we set this to disable that stuff.
REACT_APP_CRUD_MODE_READONLY: true
BUILD_LIVE_SAMPLES_BASE_URL: https://live.mdnyalp.dev
BUILD_LEGACY_LIVE_SAMPLES_BASE_URL: https://live-samples.mdn.allizom.net
# In these builds we never care for or need the ability to sign in.
# This environment variable will disable that functionality entirely.
REACT_APP_DISABLE_AUTH: true
# TODO: This should be implicit when `CI=true`
BUILD_NO_PROGRESSBAR: true
# Playground
REACT_APP_PLAYGROUND_BASE_HOST: mdnyalp.dev
# If we don't do this the built files will end up in
# `node_modules/@mdn/yari/client/build/` and we don't want that
# to get pushed into the cache.
BUILD_OUT_ROOT: /tmp/build
working-directory: ${{ github.workspace }}/mdn/content
run: |
mkdir -p $BUILD_OUT_ROOT
# Don't use `yarn build` (from mdn/content) because that one hardcodes
# the BUILD_OUT_ROOT and CONTENT_ROOT env vars.
node node_modules/@mdn/yari/build/cli.js ${{ env.GIT_DIFF_CONTENT }}
echo "Disk usage size of build/"
du -sh $BUILD_OUT_ROOT
# Save the PR number into the build
echo ${{ github.event.number }} > $BUILD_OUT_ROOT/NR
- name: Download the diff file
if: ${{ env.GIT_DIFF_CONTENT }}
env:
# This must match what we set in the "Build changed content" step above
BUILD_OUT_ROOT: /tmp/build
run: |
# Save the raw diff blob and store that inside the ./build/
# directory.
# The purpose of this is for the PR Review Companion to later
# be able to use this raw diff file for the benefit of analyzing.
wget https://github.com/${{ github.repository }}/compare/${{ env.BASE_SHA }}...${{ env.HEAD_SHA }}.diff -O $BUILD_OUT_ROOT/DIFF
- name: Merge static assets with built documents
if: ${{ env.GIT_DIFF_CONTENT }}
env:
# This must match what we set in the "Build changed content" step above
BUILD_OUT_ROOT: /tmp/build
run: |
rsync -a ${{ github.workspace }}/mdn/content/node_modules/@mdn/yari/client/build/ $BUILD_OUT_ROOT/
# Now that build/ directory contains everything you need to deploy
# that as a site. HTML, static assets, images, etc.
# However, that Yari static files is very heavy and it's in large
# part due to the .map files.
# In fact, as of March 2021, the client/build/static directory
# is 2.3MB but only 864KB without all the .map files.
# Let's delete those this time because this isn't the right time
# to debug JS or CSS.
find $BUILD_OUT_ROOT/static -type f -name "*.map" | xargs rm
- uses: actions/upload-artifact@v3
if: ${{ env.GIT_DIFF_CONTENT }}
env:
# This must match what we set in the "Build changed content" step above
BUILD_OUT_ROOT: /tmp/build
with:
name: build
path: ${{ env.BUILD_OUT_ROOT }}
- name: Check changed files
if: ${{ env.GIT_DIFF_FILES }}
env:
CONTENT_ROOT: ${{ github.workspace }}/mdn/content/files
CONTENT_TRANSLATED_ROOT: ${{ github.workspace }}/files
working-directory: ${{ github.workspace }}/mdn/content
run: |
echo ${{ env.GIT_DIFF_FILES }}
yarn filecheck ${{ env.GIT_DIFF_FILES }}