name:Node.jsTests# **What it does**: Runs our tests.# **Why we have it**: We want our tests to pass before merging code.# **Who does it impact**: Docs engineering, open-source engineering contributors.on:workflow_dispatch:pull_request:push:branches:-mainpermissions:contents:read# Needed for the 'trilom/file-changes-action' actionpull-requests:read# This allows a subsequently queued workflow run to interrupt previous runsconcurrency:group:'${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'cancel-in-progress:truejobs:test:# Run on self-hosted if the private repo or ubuntu-latest if the public repo# See pull # 17442 in the private repo for contextruns-on:${{fromJSON('["ubuntu-latest","self-hosted"]')[github.repository=='github/docs-internal']}}timeout-minutes:60strategy:fail-fast:falsematrix:# The same array lives in test-windows.yml, so make any updates there too.test-group:
[
content,
graphql,
meta,
rendering,
routing,
unit,
linting,
translations,
]
steps:# Each of these ifs needs to be repeated at each step to make sure the required check still runs# Even if if doesn't do anything-name:Checkoutrepouses:actions/checkout@v3with:# Not all test suites need the LFS files. So instead, we opt to# NOT clone them initially and instead, include them manually# only for the test groups that we know need the files.lfs:${{matrix.test-group=='content'}}# Enables cloning the Early Access repo later with the relevant personal access tokenpersist-credentials:'false'-name:Figureoutwhichdocs-early-accessbranchtocheckout,ifinternalrepoif:${{github.repository=='github/docs-internal'}}id:check-early-accessuses:actions/github-script@v6env:BRANCH_NAME:${{github.head_ref||github.ref_name}}with:github-token:${{secrets.DOCUBOT_REPO_PAT}}result-encoding:stringscript:|
// If being run from a PR, this becomes 'my-cool-branch'.
// If run on main, with the `workflow_dispatch` action for
// example, the value becomes 'main'.
const { BRANCH_NAME } = process.env
try {
const response = await github.repos.getBranch({
owner: 'github',
repo: 'docs-early-access',
BRANCH_NAME,
})
console.log(`Using docs-early-access branch called '${BRANCH_NAME}'.`)
return BRANCH_NAME
} catch (err) {
if (err.status === 404) {
console.log(`There is no docs-early-access branch called '${BRANCH_NAME}' so checking out 'main' instead.`)
return 'main'
}
throw err
}
-name:Checkoutdocs-early-accesstoo,ifinternalrepoif:${{github.repository=='github/docs-internal'}}uses:actions/checkout@v3with:repository:github/docs-early-accesstoken:${{secrets.DOCUBOT_REPO_PAT}}path:docs-early-accessref:${{steps.check-early-access.outputs.result}}-name:Mergedocs-early-accessrepo'sfoldersif:${{github.repository=='github/docs-internal'}}run:|
mv docs-early-access/assets assets/images/early-access
mv docs-early-access/content content/early-access
mv docs-early-access/data data/early-access
rm -r docs-early-access
# This is necessary when LFS files where cloned but does nothing# if actions/checkout was run with `lfs:false`.-name:CheckoutLFSobjectsrun:gitlfscheckout-name:Gatherfileschangeduses:trilom/file-changes-action@a6ca26c14274c33b15e6499323aac178af06ad4bid:get_diff_fileswith:# So that `steps.get_diff_files.outputs.files` becomes# a string like `foo.js path/bar.md`output:' '-name:Insightintochangedfilesrun:|# Must to do this because the list of files can be HUGE. Especially# in a repo-sync when there are lots of translation files involved.echo"${{ steps.get_diff_files.outputs.files }}">get_diff_files.txt-name:Setupnodeuses:actions/setup-node@v3with:node-version:16.14.xcache:npm-name:Installdependenciesrun:npmci-name:Cachenextjsbuilduses:actions/cache@v3with:path:.next/cachekey:${{runner.os}}-nextjs-${{hashFiles('package*.json')}}-name:Runbuildscriptrun:npmrunbuild-name:Runtestsenv:DIFF_FILE:get_diff_files.txtCHANGELOG_CACHE_FILE_PATH:tests/fixtures/changelog-feed.jsonrun:npmtest--tests/${{matrix.test-group}}/
-name:Figureoutwhichdocs-early-accessbranchtocheckout,ifinternalrepoif:${{github.repository=='github/docs-internal'}}id:check-early-accessuses:actions/github-script@v6env:BRANCH_NAME:${{github.head_ref||github.ref_name}}with:github-token:${{secrets.DOCUBOT_REPO_PAT}}result-encoding:stringscript:|
// If being run from a PR, this becomes 'my-cool-branch'.
// If run on main, with the `workflow_dispatch` action for
// example, the value becomes 'main'.
const { BRANCH_NAME } = process.env
try {
const response = await github.repos.getBranch({
owner: 'github',
repo: 'docs-early-access',
BRANCH_NAME,
})
console.log(`Using docs-early-access branch called '${BRANCH_NAME}'.`)
return BRANCH_NAME
} catch (err) {
if (err.status === 404) {
console.log(`There is no docs-early-access branch called '${BRANCH_NAME}' so checking out 'main' instead.`)
return 'main'
}
throw err
}
現在のリポジトリが github/docs-internal リポジトリである場合、この手順では run キーワードを使ってシェル コマンドを実行し、docs-early-access リポジトリのフォルダーをメイン リポジトリのフォルダーに移動します。
YAML
-name:CheckoutLFSobjectsrun:gitlfscheckout
この手順では、リポジトリから LFS オブジェクトをチェックアウトするコマンドを実行します。
YAML
-name:Gatherfileschangeduses:trilom/file-changes-action@a6ca26c14274c33b15e6499323aac178af06ad4bid:get_diff_fileswith:# So that `steps.get_diff_files.outputs.files` becomes# a string like `foo.js path/bar.md`output:' '