-
-
Notifications
You must be signed in to change notification settings - Fork 973
docs: link to next docs and vice versa #1438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
4bc31d4
docs: show next version as special one
ST-DDT d1edeb6
test: add test to ensure the version history is consistent
ST-DDT 724a47b
Merge branch 'next' into docs/next-version-number
ST-DDT 97bfd0e
chore: derive isNext from current branch name
ST-DDT 20a15c4
test: also check the first entry
ST-DDT febf1fc
Merge branch 'next' into docs/next-version-number
ST-DDT 3c0b3b4
docs: automatically generate links to other versions
ST-DDT f54a7cc
chore: apply suggestions
ST-DDT df1c768
chore: use semver methods
ST-DDT a1368a8
chore: checkout all branches
ST-DDT f023b09
chore: don't try
ST-DDT 471e7c7
chore: don't log in the script
ST-DDT a83de7e
chore: add hint regarding detch depth
ST-DDT e8a7f74
docs: take deployment context into account
ST-DDT a71eeb2
chore: remove debug code
ST-DDT b95c4fa
Merge branch 'next' into docs/next-version-number
ST-DDT 7c38801
chore: apply suggestions
ST-DDT 2018e44
chore: merge next
ST-DDT dc3baaf
chore: merge upstream
ST-DDT 93df944
chore: hope that netlify supports this syntax
ST-DDT 98ebed3
revert: chore: hope that netlify supports this syntax
ST-DDT fd652d9
Merge branch 'next' into docs/next-version-number
ST-DDT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,9 @@ jobs: | |
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
# Required for docs/versions tests | ||
fetch-depth: 0 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/[email protected] | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,58 @@ | ||
import { execSync } from 'node:child_process'; | ||
import * as semver from 'semver'; | ||
import { version } from '../../package.json'; | ||
|
||
export const currentVersion = `v${version}`; | ||
function readBranchName(): string { | ||
return ( | ||
execSync('git branch --show-current').toString('utf8').trim() || 'unknown' | ||
); | ||
} | ||
|
||
function readOtherLatestReleaseTagNames(): string[] { | ||
const currentMajorVersion = semver.major(version); | ||
const latestReleaseTagNames = execSync('git tag -l') | ||
.toString('utf8') | ||
.split('\n') | ||
.filter((tag) => semver.valid(tag)) | ||
.reduce<Record<number, string[]>>((acc, tag) => { | ||
const majorVersion = semver.major(tag); | ||
// Only consider tags for our deployed website versions, | ||
// excluding the current major version. | ||
if (majorVersion >= 6 && majorVersion !== currentMajorVersion) { | ||
(acc[majorVersion] = acc[majorVersion] || []).push(tag); | ||
} | ||
return acc; | ||
}, {}); | ||
return Object.entries(latestReleaseTagNames) | ||
.map(([major, tags]) => semver.maxSatisfying(tags, `^${major}`)) | ||
.sort(semver.rcompare); | ||
} | ||
|
||
// Set by netlify | ||
const { | ||
CONTEXT: deployContext = 'local', | ||
BRANCH: branchName = readBranchName(), | ||
} = process.env; | ||
|
||
const hiddenLink = | ||
deployContext === 'production' | ||
? 'https://fakerjs.dev/' | ||
: `https://${branchName}.fakerjs.dev/`; | ||
const otherVersions = readOtherLatestReleaseTagNames(); | ||
const isReleaseBranch = /^v\d+$/.test(branchName); | ||
|
||
export const currentVersion = isReleaseBranch ? `v${version}` : branchName; | ||
export const oldVersions = [ | ||
{ version: 'v6.3.1', link: 'https://v6.fakerjs.dev/' }, | ||
]; | ||
{ | ||
version: 'latest', | ||
link: 'https://fakerjs.dev/', | ||
}, | ||
{ | ||
version: 'next', | ||
link: 'https://next.fakerjs.dev/', | ||
}, | ||
...otherVersions.map((version) => ({ | ||
version, | ||
link: `https://v${semver.major(version)}.fakerjs.dev/`, | ||
})), | ||
].filter(({ link }) => link !== hiddenLink); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { major as semverMajor } from 'semver'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { oldVersions } from '../../docs/.vitepress/versions'; | ||
import { version } from '../../package.json'; | ||
|
||
describe('docs versions', () => { | ||
describe('oldVersions', () => { | ||
it('should have a complete set of oldVersions', () => { | ||
const versionText = `v${version}`; | ||
|
||
expect(oldVersions.length).toBeGreaterThanOrEqual(2); | ||
const currentMajorVersion = semverMajor(versionText); | ||
|
||
expect(oldVersions[0]).toEqual({ | ||
version: 'latest', | ||
link: 'https://fakerjs.dev/', | ||
}); | ||
expect(oldVersions[1]).toEqual({ | ||
version: 'next', | ||
link: 'https://next.fakerjs.dev/', | ||
}); | ||
|
||
for (let i = 2; i < oldVersions.length; i++) { | ||
const oldMajorVersion = semverMajor(oldVersions[i].version); | ||
expect(oldMajorVersion).toBe(currentMajorVersion - i + 1); | ||
} | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.