1
0
mirror of synced 2025-12-30 03:01:36 -05:00

include docs-early-access in link checker (#27747)

This commit is contained in:
Peter Bengtsson
2022-10-28 18:24:19 +02:00
committed by GitHub
parent ef4045ee07
commit bcbfdc934a
4 changed files with 94 additions and 38 deletions

View File

@@ -0,0 +1,38 @@
#!/usr/bin/env node
import { getOctokit } from '@actions/github'
import { setOutput } from '@actions/core'
async function main() {
// TODO Is there a lib function for this?
const { BRANCH_NAME, GITHUB_TOKEN } = process.env
if (!BRANCH_NAME) throw new Error("'BRANCH_NAME' env var not set")
if (!GITHUB_TOKEN) throw new Error("'GITHUB_TOKEN' env var not set")
const OUTPUT_KEY = 'branch'
// 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 github = getOctokit(GITHUB_TOKEN)
try {
await github.rest.repos.getBranch({
owner: 'github',
repo: 'docs-early-access',
branch: BRANCH_NAME,
})
console.log(`Using docs-early-access branch called '${BRANCH_NAME}'.`)
setOutput(OUTPUT_KEY, 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.`
)
setOutput(OUTPUT_KEY, 'main')
} else {
throw err
}
}
}
main()

View File

@@ -33,6 +33,27 @@ jobs:
- name: Install dependencies
run: npm ci
- name: Figure out which docs-early-access branch to checkout, if internal repo
if: ${{ github.repository == 'github/docs-internal' }}
id: check-early-access
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }}
run: node .github/actions-scripts/what-docs-early-access-branch.js
- name: Check out docs-early-access too, if internal repo
if: ${{ github.repository == 'github/docs-internal' }}
uses: actions/checkout@dcd71f646680f2efd8db4afa5ad64fdcba30e748
with:
repository: github/docs-early-access
token: ${{ secrets.DOCUBOT_REPO_PAT }}
path: docs-early-access
ref: ${{ steps.check-early-access.outputs.branch }}
- name: Merge docs-early-access repo's folders
if: ${{ github.repository == 'github/docs-internal' }}
run: .github/actions-scripts/merge-early-access.sh
- name: Run link checker
env:
LEVEL: 'critical'

View File

@@ -40,6 +40,27 @@ jobs:
- name: Install
run: npm ci
- name: Figure out which docs-early-access branch to checkout, if internal repo
if: ${{ github.repository == 'github/docs-internal' }}
id: check-early-access
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }}
run: node .github/actions-scripts/what-docs-early-access-branch.js
- name: Check out docs-early-access too, if internal repo
if: ${{ github.repository == 'github/docs-internal' }}
uses: actions/checkout@dcd71f646680f2efd8db4afa5ad64fdcba30e748
with:
repository: github/docs-early-access
token: ${{ secrets.DOCUBOT_REPO_PAT }}
path: docs-early-access
ref: ${{ steps.check-early-access.outputs.branch }}
- name: Merge docs-early-access repo's folders
if: ${{ github.repository == 'github/docs-internal' }}
run: .github/actions-scripts/merge-early-access.sh
# TODO: When we want to fix redirects on changed files we can uncomment everything below
# Creates file "${{ env.HOME }}/files.json", among others
# - name: Gather files changed

View File

@@ -77,35 +77,22 @@ jobs:
# ->> Do we really need this? actions/checkout doesn't use it for the nested example:
# https://github.com/actions/checkout#checkout-multiple-repos-nested
- name: Setup node
uses: actions/setup-node@17f8bd926464a1afa4c6a11669539e9c1ba77048
with:
node-version: '16.17.0'
cache: npm
- name: Install dependencies
run: npm ci
- name: Figure out which docs-early-access branch to checkout, if internal repo
if: ${{ github.repository == 'github/docs-internal' }}
id: check-early-access
uses: actions/github-script@d556feaca394842dc55e4734bf3bb9f685482fa0
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
with:
github-token: ${{ secrets.DOCUBOT_REPO_PAT }}
result-encoding: string
script: |
// 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.rest.repos.getBranch({
owner: 'github',
repo: 'docs-early-access',
branch: 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_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }}
run: node .github/actions-scripts/what-docs-early-access-branch.js
- name: Check out docs-early-access too, if internal repo
if: ${{ github.repository == 'github/docs-internal' }}
@@ -114,15 +101,13 @@ jobs:
repository: github/docs-early-access
token: ${{ secrets.DOCUBOT_REPO_PAT }}
path: docs-early-access
ref: ${{ steps.check-early-access.outputs.result }}
ref: ${{ steps.check-early-access.outputs.branch }}
- name: Merge docs-early-access repo's folders
if: ${{ 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
.github/actions-scripts/merge-early-access.sh
rm -fr docs-early-access
# This is necessary when LFS files where cloned but does nothing
# if actions/checkout was run with `lfs:false`.
@@ -162,15 +147,6 @@ jobs:
echo __ format, write to get_diff_files.txt __
echo $DIFF | tr '\n' ' ' > get_diff_files.txt
- name: Setup node
uses: actions/setup-node@17f8bd926464a1afa4c6a11669539e9c1ba77048
with:
node-version: '16.17.0'
cache: npm
- name: Install dependencies
run: npm ci
- name: Cache nextjs build
uses: actions/cache@48af2dc4a9e8278b89d7fa154b955c30c6aaab09
with: