forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request github#30187 from github/repo-sync
Repo sync
- Loading branch information
Showing
6 changed files
with
189 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: Move content script test | ||
|
||
# **What it does**: Tests the `npm run move-content` script | ||
# **Why we have it**: To be sure it continues to work as expected | ||
# **Who does it impact**: Docs team. | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- src/content-render/scripts/move-content.js | ||
- 'src/frame/lib/**/*.js' | ||
- .github/workflows/move-content.yml | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
move-content-test: | ||
if: github.repository == 'github/docs-internal' || github.repository == 'github/docs' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repo | ||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 | ||
|
||
- uses: ./.github/actions/node-npm-setup | ||
|
||
- name: Set up a dummy git user | ||
run: | | ||
# These must be set to something before running the move-content | ||
# script because it depends on executing `git mv ...` | ||
# and `git commit ...` | ||
git config --global user.name any-body | ||
git config --global user.email "[email protected]" | ||
- name: Move hello-world.md to hello-wurld.md | ||
env: | ||
ROOT: src/fixtures/fixtures | ||
run: | | ||
npm run move-content -- \ | ||
src/fixtures/fixtures/content/get-started/quickstart/hello-world.md \ | ||
src/fixtures/fixtures/content/get-started/quickstart/hello-wurld.md | ||
node src/content-render/scripts/test-moved-content.js \ | ||
src/fixtures/fixtures/content/get-started/quickstart/hello-world.md \ | ||
src/fixtures/fixtures/content/get-started/quickstart/hello-wurld.md | ||
# TODO: Add tests that inspects the git log | ||
git log | head -n 100 | ||
- name: Move code-security/getting-started to code-security/got-started | ||
env: | ||
ROOT: src/fixtures/fixtures | ||
run: | | ||
npm run move-content -- \ | ||
src/fixtures/fixtures/content/code-security/getting-started \ | ||
src/fixtures/fixtures/content/code-security/got-started | ||
node src/content-render/scripts/test-moved-content.js \ | ||
src/fixtures/fixtures/content/code-security/getting-started \ | ||
src/fixtures/fixtures/content/code-security/got-started | ||
# TODO: Add tests that inspects the git log | ||
git log | head -n 100 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import assert from 'node:assert/strict' | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
import { program } from 'commander' | ||
|
||
import readFrontmatter from '#src/frame/lib/read-frontmatter.js' | ||
|
||
const ROOT = process.env.ROOT || '.' | ||
const CONTENT_ROOT = path.resolve(path.join(ROOT, 'content')) | ||
|
||
program | ||
.description('Test that a file correctly got moved') | ||
.arguments('old', 'old file or folder name') | ||
.arguments('new', 'new file or folder name') | ||
.parse(process.argv) | ||
|
||
main(program.args) | ||
|
||
async function main(nameTuple) { | ||
const [before, after] = nameTuple | ||
assert(!fs.existsSync(before), `File or folder ${before} exists`) | ||
assert(fs.existsSync(after), `File or folder ${after} exists`) | ||
if (after.endsWith('.md')) { | ||
const fileContent = fs.readFileSync(after, 'utf-8') | ||
const { data } = readFrontmatter(fileContent) | ||
const oldHref = makeHref(CONTENT_ROOT, before) | ||
assert(data.redirect_from.includes(oldHref), `Redirect from ${oldHref} not found`) | ||
{ | ||
const parentIndexMd = path.join(path.dirname(after), 'index.md') | ||
const fileContent = fs.readFileSync(parentIndexMd, 'utf-8') | ||
const { data } = readFrontmatter(fileContent) | ||
const afterShortname = '/' + after.split('/').slice(-1)[0].replace(/\.md$/, '') | ||
assert(data.children.includes(afterShortname), `Child ${afterShortname} not found`) | ||
} | ||
} else { | ||
const fileContent = fs.readFileSync(path.join(after, 'index.md'), 'utf-8') | ||
const { data } = readFrontmatter(fileContent) | ||
const oldHref = makeHref(CONTENT_ROOT, before) | ||
assert(data.redirect_from.includes(oldHref), `Redirect from ${oldHref} not found`) | ||
{ | ||
const parentIndexMd = path.join(path.dirname(after), 'index.md') | ||
const fileContent = fs.readFileSync(parentIndexMd, 'utf-8') | ||
const { data } = readFrontmatter(fileContent) | ||
const afterShortname = '/' + after.split('/').slice(-1) | ||
assert(data.children.includes(afterShortname), `Child ${afterShortname} not found`) | ||
} | ||
} | ||
} | ||
|
||
function makeHref(root, filePath) { | ||
const nameSplit = path.relative(root, filePath).split(path.sep) | ||
if (nameSplit.slice(-1)[0] === 'index.md') { | ||
nameSplit.pop() | ||
} else { | ||
nameSplit.push(nameSplit.pop().replace(/\.md$/, '')) | ||
} | ||
return '/' + nameSplit.join('/') | ||
} |
This file contains 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