[pt-br] sync translated content #66436
This file contains hidden or 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
| # 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 | |
| jobs: | |
| tests: | |
| if: github.repository == 'mdn/translated-content' | |
| runs-on: ubuntu-latest | |
| # Set the permissions to `read-all`, preventing the workflow from | |
| # any accidental write access to the repository. | |
| permissions: read-all | |
| env: | |
| BASE_SHA: ${{ github.event.pull_request.base.sha }} | |
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
| # If we don't do this the built files may 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 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| persist-credentials: false | |
| - name: Get changed files | |
| id: check | |
| run: | | |
| # Use the GitHub API to get the list of changed files | |
| DIFF_DOCUMENTS=$(gh api repos/{owner}/{repo}/compare/${BASE_SHA}...${HEAD_SHA} \ | |
| --jq '.files | .[] | select(.status|IN("added", "modified", "renamed", "copied", "changed")) | .filename') | |
| FILTERED_MD_FILES=$(echo "$DIFF_DOCUMENTS" | egrep -i "^files/.*\.md$" || true) | |
| FILTERED_IMAGE_FILES=$(echo "$DIFF_DOCUMENTS" | egrep -i "^files/.*\.(png|jpeg|jpg|gif|svg|webp)$" || true) | |
| HAS_MD_FILES=false | |
| HAS_IMAGE_FILES=false | |
| # Check if we actually have content (not just empty strings) | |
| if [ -n "${FILTERED_MD_FILES// /}" ]; then # Remove all spaces and check if anything remains | |
| HAS_MD_FILES=true | |
| EOF_MD="$(openssl rand -hex 8)" | |
| echo "GIT_DIFF_CONTENT<<${EOF_MD}" >> "$GITHUB_OUTPUT" | |
| echo "${FILTERED_MD_FILES}" >> "$GITHUB_OUTPUT" | |
| echo "${EOF_MD}" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "GIT_DIFF_CONTENT=" >> "$GITHUB_OUTPUT" | |
| fi | |
| if [ -n "${FILTERED_IMAGE_FILES// /}" ]; then # Remove all spaces and check if anything remains | |
| HAS_IMAGE_FILES=true | |
| EOF_IMG="$(openssl rand -hex 8)" | |
| echo "GIT_DIFF_FILES<<${EOF_IMG}" >> "$GITHUB_OUTPUT" | |
| echo "${FILTERED_IMAGE_FILES}" >> "$GITHUB_OUTPUT" | |
| echo "${EOF_IMG}" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "GIT_DIFF_FILES=" >> "$GITHUB_OUTPUT" | |
| fi | |
| # Set the boolean outputs | |
| echo "HAS_MD_FILES=${HAS_MD_FILES}" >> "$GITHUB_OUTPUT" | |
| echo "HAS_IMAGE_FILES=${HAS_IMAGE_FILES}" >> "$GITHUB_OUTPUT" | |
| if [ "${HAS_MD_FILES}" = "true" ] || [ "${HAS_IMAGE_FILES}" = "true" ]; then | |
| echo "HAS_FILES=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "HAS_FILES=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Checkout (content) | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| if: steps.check.outputs.HAS_FILES == 'true' | |
| with: | |
| repository: mdn/content | |
| path: mdn/content | |
| persist-credentials: false | |
| - name: Setup Node.js environment | |
| if: steps.check.outputs.HAS_FILES == 'true' | |
| uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 | |
| with: | |
| node-version-file: mdn/content/.nvmrc | |
| cache: yarn | |
| cache-dependency-path: mdn/content/yarn.lock | |
| - name: Install all yarn packages | |
| if: steps.check.outputs.HAS_FILES == 'true' | |
| 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: Build changed content | |
| id: build-content | |
| if: steps.check.outputs.HAS_MD_FILES == 'true' | |
| env: | |
| GIT_DIFF_CONTENT: ${{ steps.check.outputs.GIT_DIFF_CONTENT }} | |
| # Used by the `rari` cli to avoid rate limiting issues | |
| # when fetching the latest releases info from the GitHub API. | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| 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" | |
| BUILD_LIVE_SAMPLES_BASE_URL: https://live.mdnyalp.dev | |
| BUILD_LEGACY_LIVE_SAMPLES_BASE_URL: https://live-samples.mdn.allizom.net | |
| # TODO: This should be implicit when `CI=true` | |
| BUILD_NO_PROGRESSBAR: true | |
| FRED_WRITER_MODE: true | |
| FRED_PLAYGROUND_BASE_HOST: mdnyalp.dev | |
| # rari | |
| LIVE_SAMPLES_BASE_URL: https://live.mdnyalp.dev | |
| INTERACTIVE_EXAMPLES_BASE_URL: https://interactive-examples.mdn.allizom.net | |
| working-directory: ${{ github.workspace }}/mdn/content | |
| run: | | |
| mkdir -p $BUILD_OUT_ROOT | |
| # The reason this script isn't in `package.json` is because | |
| # you don't need that script as a writer. It's only used in CI | |
| # and it can't use the default CONTENT_ROOT that gets set in | |
| # package.json. | |
| # Read into array, one filename per line | |
| readarray -t files_to_build <<< "$GIT_DIFF_CONTENT" | |
| ARGS=() | |
| for file in "${files_to_build[@]}"; do | |
| file_without_prefix="${file#files/}" | |
| ARGS+=("-f" "$CONTENT_TRANSLATED_ROOT/$file_without_prefix") | |
| done | |
| yarn rari build --no-basic --json-issues --data-issues "${ARGS[@]}" | |
| # Workaround, as fred-ssr doesn't copy assets. | |
| cp -vR node_modules/@mdn/fred/out/. "$BUILD_OUT_ROOT" | |
| yarn fred-ssr | |
| echo "Disk usage size of the build" | |
| du -sh $BUILD_OUT_ROOT | |
| # Save the PR number into the build | |
| echo ${{ github.event.number }} > ${BUILD_OUT_ROOT}/NR | |
| # Download 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/${BASE_SHA}...${HEAD_SHA}.diff -O ${BUILD_OUT_ROOT}/DIFF | |
| - name: Show final disk usage size of build | |
| if: steps.check.outputs.HAS_MD_FILES == 'true' | |
| run: du -sh $BUILD_OUT_ROOT | |
| - uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | |
| if: steps.check.outputs.HAS_MD_FILES == 'true' | |
| with: | |
| name: build | |
| path: ${{ env.BUILD_OUT_ROOT }} | |
| - name: Check changed files | |
| if: steps.check.outputs.HAS_IMAGE_FILES == 'true' | |
| env: | |
| CONTENT_ROOT: ${{ github.workspace }}/mdn/content/files | |
| CONTENT_TRANSLATED_ROOT: ${{ github.workspace }}/files | |
| GIT_DIFF_FILES: ${{ steps.check.outputs.GIT_DIFF_FILES }} | |
| working-directory: ${{ github.workspace }}/mdn/content | |
| run: | | |
| readarray -t files_to_check <<< "$GIT_DIFF_FILES" | |
| echo "${files_to_check[@]}" | |
| ARGS=() | |
| for file in "${files_to_check[@]}"; do | |
| file_without_prefix="${file#files/}" | |
| ARGS+=("$CONTENT_TRANSLATED_ROOT/$file_without_prefix") | |
| done | |
| yarn filecheck "${ARGS[@]}" |