forked from medusajs/medusa
-
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.
docs: show latest version in docs + update automatically (medusajs#9753)
- Loading branch information
1 parent
669adbc
commit 04cec64
Showing
14 changed files
with
232 additions
and
1 deletion.
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,54 @@ | ||
name: Update Version in Docs | ||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
update-docs-version: | ||
runs-on: ubuntu-latest | ||
env: | ||
GH_TOKEN: ${{ secrets.REFERENCE_PAT }} | ||
steps: | ||
- name: Cancel Previous Runs | ||
uses: styfle/[email protected] | ||
with: | ||
access_token: ${{ github.token }} | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Node.js environment | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
cache: "yarn" | ||
|
||
- name: Install dependencies | ||
uses: ./.github/actions/cache-deps | ||
with: | ||
extension: docs-update-version | ||
|
||
- name: Install Workspace dependencies | ||
run: yarn install | ||
working-directory: www/utils | ||
|
||
- name: Build Workspace packages | ||
run: yarn build | ||
working-directory: www/utils | ||
|
||
- name: Update Docs Version | ||
run: yarn update:config-version | ||
working-directory: www/utils/packages/scripts | ||
|
||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v4 | ||
with: | ||
commit-message: "chore(docs): Update version in documentation (automated)" | ||
base: "develop" | ||
title: "chore(docs): Update version in documentation (automated)" | ||
labels: "type: chore" | ||
add-paths: www/packages/docs-ui/src/global-config.ts | ||
branch: "docs/update-config-version" | ||
branch-suffix: "timestamp" |
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
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
65 changes: 65 additions & 0 deletions
65
www/packages/docs-ui/src/components/MainNav/Version/index.tsx
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,65 @@ | ||
"use state" | ||
|
||
import React, { useEffect, useMemo, useState } from "react" | ||
import { useIsBrowser, useSiteConfig } from "../../../providers" | ||
import Link from "next/link" | ||
import { Tooltip } from "../../Tooltip" | ||
import clsx from "clsx" | ||
|
||
const LOCAL_STORAGE_SUFFIX = "-seen" | ||
|
||
export const MainNavVersion = () => { | ||
const { | ||
config: { version }, | ||
} = useSiteConfig() | ||
const [showNewBadge, setShowNewBadge] = useState(false) | ||
const { isBrowser } = useIsBrowser() | ||
const localStorageKey = useMemo( | ||
() => `${version.number}${LOCAL_STORAGE_SUFFIX}`, | ||
[version] | ||
) | ||
|
||
useEffect(() => { | ||
if (!isBrowser) { | ||
return | ||
} | ||
|
||
if (!localStorage.getItem(localStorageKey)) { | ||
setShowNewBadge(true) | ||
} | ||
}, [isBrowser, localStorageKey]) | ||
|
||
const afterHover = () => { | ||
if (!showNewBadge) { | ||
return | ||
} | ||
|
||
setShowNewBadge(false) | ||
localStorage.setItem(localStorageKey, "true") | ||
} | ||
|
||
return ( | ||
<> | ||
<Link href={version.releaseUrl} target="_blank"> | ||
<Tooltip html="View the release notes<br/>on GitHub"> | ||
<span | ||
className="relative text-compact-small-plus" | ||
onMouseOut={afterHover} | ||
> | ||
<span>v{version.number}</span> | ||
{showNewBadge && ( | ||
<span | ||
className={clsx( | ||
"bg-medusa-tag-blue-icon w-[10px] h-[10px]", | ||
"absolute -top-docs_0.25 -right-docs_0.5", | ||
"animate-pulse rounded-full" | ||
)} | ||
></span> | ||
)} | ||
</span> | ||
</Tooltip> | ||
</Link> | ||
<span className="text-compact-small">·</span> | ||
</> | ||
) | ||
} |
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,10 @@ | ||
/* eslint-disable comma-dangle */ | ||
/* eslint-disable prettier/prettier */ | ||
import { DocsConfig } from "types" | ||
|
||
export const globalConfig: Pick<DocsConfig, "version"> = { | ||
"version": { | ||
"number": "2.0", | ||
"releaseUrl": "https://github.com/medusajs/medusa/releases/tag/v2.0.0" | ||
} | ||
} |
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
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,81 @@ | ||
#!/usr/bin/env node | ||
|
||
import { Octokit } from "@octokit/core" | ||
import fs from "fs" | ||
import path from "path" | ||
import { fileURLToPath } from "url" | ||
|
||
const octokit = new Octokit({ | ||
auth: process.env.GH_TOKEN, | ||
}) | ||
|
||
type DocsConfig = { | ||
version: { | ||
number: string | ||
releaseUrl: string | ||
} | ||
} | ||
|
||
function getConfigPath() { | ||
const __filename = fileURLToPath(import.meta.url) | ||
const __dirname = path.dirname(__filename) | ||
return path.join( | ||
__dirname, | ||
"..", | ||
"..", | ||
"..", | ||
"..", | ||
"packages", | ||
"docs-ui", | ||
"src", | ||
"global-config.ts" | ||
) | ||
} | ||
|
||
const configFilePrefix = `/* eslint-disable comma-dangle */ | ||
/* eslint-disable prettier/prettier */ | ||
import { DocsConfig } from "types" | ||
export const globalConfig: Pick<DocsConfig, "version"> = ` | ||
|
||
async function main() { | ||
//retrieve the latest release | ||
const response = await octokit.request( | ||
"GET /repos/{owner}/{repo}/releases/latest", | ||
{ | ||
owner: "medusajs", | ||
repo: "medusa", | ||
sha: "develop", | ||
} | ||
) | ||
|
||
const version = response.data.tag_name.replace(/\.0$/, "").replace(/^v/, "") | ||
|
||
// get the existing version | ||
const configPath = getConfigPath() | ||
const configContent = fs | ||
.readFileSync(configPath, "utf-8") | ||
.replace(configFilePrefix, "") | ||
const oldConfig: DocsConfig = JSON.parse(configContent) | ||
|
||
if (oldConfig.version.number === version) { | ||
return | ||
} | ||
|
||
//add new announcement | ||
const config: DocsConfig = { | ||
version: { | ||
number: version, | ||
releaseUrl: response.data.html_url, | ||
}, | ||
} | ||
|
||
//write new config file | ||
fs.writeFileSync( | ||
configPath, | ||
`${configFilePrefix}${JSON.stringify(config, undefined, 2)}` | ||
) | ||
console.log(`Version in config has been updated.`) | ||
} | ||
|
||
void main() |
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