Skip to content

Commit b43d9e7

Browse files
chore: Change doc version management (thomaspoignant#1880)
* chore: Change doc version management Signed-off-by: Thomas Poignant <[email protected]> * Change type of PR Signed-off-by: Thomas Poignant <[email protected]> * fix: getrepourl Signed-off-by: Thomas Poignant <[email protected]> * chore: Ignore sonarlint folder Signed-off-by: Thomas Poignant <[email protected]> --------- Signed-off-by: Thomas Poignant <[email protected]>
1 parent c982515 commit b43d9e7

File tree

12 files changed

+298
-102
lines changed

12 files changed

+298
-102
lines changed

.github/dependabot.yml

+14
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,17 @@ updates:
136136
- "automerge"
137137
commit-message:
138138
prefix: "chore"
139+
140+
141+
# Website CI scripts
142+
- package-ecosystem: gomod
143+
directory: "/website/.ci"
144+
schedule:
145+
interval: weekly
146+
time: "01:00"
147+
open-pull-requests-limit: 20
148+
labels:
149+
- "dependencies"
150+
- "automerge"
151+
commit-message:
152+
prefix: "chore"

.github/workflows/release.yml

+11-1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ jobs:
206206
working-directory: ./release/${{ env.WEBSITE_DIR }}
207207
run: npm run docusaurus docs:version ${{ github.ref_name }}
208208

209+
- name: Setup go
210+
uses: actions/setup-go@v5
211+
with:
212+
go-version-file: ./release/${{ env.WEBSITE_DIR }}/.ci/go.mod
213+
check-latest: true
214+
215+
- name: Clean up version.json
216+
working-directory: ./release/${{ env.WEBSITE_DIR }}/.ci
217+
run: go run versions.go
218+
209219
- name: Checkout main branch
210220
uses: actions/checkout@v4
211221
with:
@@ -277,7 +287,7 @@ jobs:
277287
uses: peter-evans/create-pull-request@v6
278288
with:
279289
branch: bump-relay-proxy-helm-chart-${{ github.ref_name }}
280-
title: "ci(helm): Bump relay-proxy helm chart version ${{ github.ref_name }}"
290+
title: "feat(helm): Bump relay-proxy helm chart version ${{ github.ref_name }}"
281291
body: Automated pull request to bump relay-proxy helm chart version ${{ github.ref_name }}
282292
commit-message: Bump relay-proxy helm chart version ${{ github.ref_name }}
283293
labels: automerge

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ go-feature-flag-relay-proxy/
4141
.aws-sam
4242

4343
node_modules/
44-
oryxBuildBinary
44+
oryxBuildBinary
45+
46+
./.sonarlint

.sonarlint/connectedMode.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"sonarCloudOrganization": "thomaspoignant",
3+
"projectKey": "thomaspoignant_go-feature-flag"
4+
}

website/.ci/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/thomaspoignant/go-feature-flag/website/.ci
2+
3+
go 1.22.0

website/.ci/versions.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"log"
7+
"os"
8+
)
9+
10+
func main() {
11+
versionFileLocation := "../versions.json"
12+
versionBakFileLocation := "../versions.json.bak"
13+
numberVersionToKeep := 8
14+
15+
content, err := os.ReadFile(versionFileLocation)
16+
if err != nil {
17+
log.Fatal("read json:", err)
18+
}
19+
20+
var versions []string
21+
err = json.Unmarshal(content, &versions)
22+
if err != nil {
23+
log.Fatal("unmarshal json:", err)
24+
}
25+
26+
output := make([]string, 0, numberVersionToKeep)
27+
for i := 0; i < numberVersionToKeep && i < len(versions); i++ {
28+
output = append(output, versions[i])
29+
}
30+
31+
outputStr, err := json.Marshal(output)
32+
if err != nil {
33+
log.Fatal("marshal json:", err)
34+
}
35+
36+
err = os.WriteFile(versionFileLocation, outputStr, 0644)
37+
if err != nil {
38+
log.Fatal(fmt.Sprintf("write json %s:", versionFileLocation), err)
39+
}
40+
err = os.WriteFile(versionBakFileLocation, content, 0644)
41+
if err != nil {
42+
log.Fatal(fmt.Sprintf("write json %s:", versionBakFileLocation), err)
43+
}
44+
45+
}

website/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"write-translations": "docusaurus write-translations",
1414
"write-heading-ids": "docusaurus write-heading-ids",
1515
"lint": "eslint \"**/*.js\"",
16-
"eslint:fix": "eslint \"**/*.js\" --fix",
17-
"generate:versionsArchived": "node src/tool/generate_versionArchived.js"
16+
"eslint:fix": "eslint \"**/*.js\" --fix"
1817
},
1918
"dependencies": {
2019
"@docusaurus/core": "^3.0.1",

website/src/pages/versions.jsx

+117-43
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect, useState } from "react";
22
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
33
import Link from '@docusaurus/Link';
44
import Translate from '@docusaurus/Translate';
@@ -8,7 +8,9 @@ import {
88
} from '@docusaurus/plugin-content-docs/client';
99
import Layout from '@theme/Layout';
1010
import Heading from '@theme/Heading';
11+
1112
const docsPluginId = undefined; // Default docs plugin instance
13+
const baseGithubLinkDoc = 'https://github.com/thomaspoignant/go-feature-flag/tree/main/website/versioned_docs/version-';
1214

1315
function DocumentationLabel() {
1416
return (
@@ -24,19 +26,122 @@ function ReleaseNotesLabel() {
2426
);
2527
}
2628

27-
export default function Version() {
29+
30+
// getVersionedDocs is getting all the GO Feature Flag Versions directly from Github release.
31+
async function getVersionedDocs(owner, repo, path) {
32+
const apiUrl = `https://api.github.com/repos/${owner}/${repo}/contents/${path}`;
33+
const response = await fetch(apiUrl);
34+
35+
if (!response.ok) {
36+
throw new Error(`GitHub API responded with status code: ${response.status}`);
37+
}
38+
39+
const directoryListing = await response.json();
40+
const versionDirectories = directoryListing
41+
.filter(item => item.type === 'dir' && item.name.startsWith('version-'))
42+
.map(item => {
43+
const version = item.name.replace('version-', '')
44+
return {
45+
version,
46+
link: item.html_url,
47+
}
48+
})
49+
// Custom sort in descending order by version numbers
50+
.sort((a, b) => {
51+
const versionA = a.version.substring(1).split('.').map(Number); // Exclude 'v' and parse numbers
52+
const versionB = b.version.substring(1).split('.').map(Number);
53+
for (let i = 0; i < Math.max(versionA.length, versionB.length); i++) {
54+
if ((versionA[i] || 0) > (versionB[i] || 0)) return -1;
55+
if ((versionA[i] || 0) < (versionB[i] || 0)) return 1;
56+
}
57+
return 0;
58+
});
59+
60+
return versionDirectories;
61+
}
62+
63+
64+
// This component is displaying all the versions of GO Feature Flag from GitHub release.
65+
const VersionList = () => {
66+
const [versions, setVersions] = useState([]);
67+
const docusaurusVersions = useVersions(docsPluginId);
68+
69+
useEffect(() => {
70+
const fetchVersions = async () => {
71+
try {
72+
const versionData = await getVersionedDocs('thomaspoignant', 'go-feature-flag', 'website/versioned_docs');
73+
setVersions(versionData);
74+
} catch (error) {
75+
console.error(error);
76+
}
77+
};
78+
79+
fetchVersions();
80+
}, []);
81+
82+
function isDocusaurusVersion(version) {
83+
return docusaurusVersions.some(docusaurusVersion => docusaurusVersion.name === version);
84+
}
85+
86+
function getDocusaurusVersionLink(version) {
87+
return docusaurusVersions.find(docusaurusVersion => docusaurusVersion.name === version).path;
88+
}
89+
2890
const {
29-
siteConfig: {organizationName, projectName},
91+
siteConfig: { organizationName, projectName }
3092
} = useDocusaurusContext();
93+
94+
return (
95+
<div className="margin-bottom--lg">
96+
<Heading as="h3" id="archive">
97+
<Translate id="versionsPage.archived.title">
98+
All available Versions
99+
</Translate>
100+
</Heading>
101+
<p>
102+
<Translate id="versionsPage.archived.description">
103+
Here you can find documentation for previous versions of GO Feature Flag.
104+
</Translate>
105+
</p>
106+
<table>
107+
<tbody>
108+
{versions.map((version, index) => (
109+
<tr key={version.version}>
110+
<th>{version.version}</th>
111+
<td>
112+
{isDocusaurusVersion(version.version) ?
113+
<Link to={getDocusaurusVersionLink(version.version)}><DocumentationLabel /></Link> :
114+
<Link to={version.link}><DocumentationLabel />&nbsp;
115+
<i className="fa fa-external-link" aria-hidden="true"></i>
116+
</Link>}
117+
</td>
118+
<td>
119+
<Link href={`${getRepoURL(organizationName, projectName)}/releases/tag/${version.version}`}>
120+
<ReleaseNotesLabel />
121+
</Link>
122+
</td>
123+
</tr>
124+
))}
125+
</tbody>
126+
</table>
127+
</div>);
128+
};
129+
130+
131+
const getRepoURL= (organizationName, projectName) =>{
132+
return `https://github.com/${organizationName}/${projectName}`;
133+
}
134+
135+
export default function Version() {
31136
const versions = useVersions(docsPluginId);
32137
const latestVersion = useLatestVersion(docsPluginId);
33138
const currentVersion = versions.find(
34-
(version) => version.name === 'current',
35-
);
36-
const pastVersions = versions.filter(
37-
(version) => version !== latestVersion && version.name !== 'current',
139+
(version) => version.name === "current"
38140
);
39-
const repoUrl = `https://github.com/${organizationName}/${projectName}`;
141+
142+
const {
143+
siteConfig: { organizationName, projectName }
144+
} = useDocusaurusContext();
40145

41146
return (
42147
<Layout
@@ -70,7 +175,7 @@ export default function Version() {
70175
</Link>
71176
</td>
72177
<td>
73-
<Link to={`${repoUrl}/releases/tag/${latestVersion.name}`}>
178+
<Link to={`${getRepoURL(organizationName,projectName)}/releases/tag/${latestVersion.name}`}>
74179
<ReleaseNotesLabel />
75180
</Link>
76181
</td>
@@ -79,6 +184,7 @@ export default function Version() {
79184
</table>
80185
</div>
81186

187+
82188
{currentVersion !== latestVersion && (
83189
<div className="margin-bottom--lg">
84190
<Heading as="h3" id="latest">
@@ -107,40 +213,8 @@ export default function Version() {
107213
</div>
108214
)}
109215

110-
{(pastVersions.length > 0) && (
111-
<div className="margin-bottom--lg">
112-
<Heading as="h3" id="archive">
113-
<Translate id="versionsPage.archived.title">
114-
Past versions
115-
</Translate>
116-
</Heading>
117-
<p>
118-
<Translate id="versionsPage.archived.description">
119-
Here you can find documentation for previous versions of
120-
GO Feature Flag.
121-
</Translate>
122-
</p>
123-
<table>
124-
<tbody>
125-
{pastVersions.map((version) => (
126-
<tr key={version.name}>
127-
<th>{version.label}</th>
128-
<td>
129-
<Link to={version.path}>
130-
<DocumentationLabel />
131-
</Link>
132-
</td>
133-
<td>
134-
<Link href={`${repoUrl}/releases/tag/${version.name}`}>
135-
<ReleaseNotesLabel />
136-
</Link>
137-
</td>
138-
</tr>
139-
))}
140-
</tbody>
141-
</table>
142-
</div>
143-
)}
216+
217+
<VersionList />
144218
</main>
145219
</Layout>
146220
);

website/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {translate} from '@docusaurus/Translate';
99
import {useLocation} from '@docusaurus/router';
1010
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
1111
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
12-
import semver from 'semver';
12+
import semver from "semver";
1313

1414
const maxVersionToDisplayPerMajor = 4;
1515
const getVersionMainDoc = version =>
@@ -111,3 +111,4 @@ function getListVersionsToDisplay(versionToCheck) {
111111
}
112112
return Array.from(latestMinorVersions.values()).map(v => v.toString());
113113
}
114+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from 'react';
2+
import clsx from 'clsx';
3+
import Translate from '@docusaurus/Translate';
4+
import Heading from '@theme/Heading';
5+
import Link from "@docusaurus/Link";
6+
export default function NotFoundContent({className}) {
7+
return (
8+
<main className={clsx('container margin-vert--xl', className)}>
9+
<div className="row">
10+
<div className="col col--6 col--offset-3">
11+
<Heading as="h1" className="hero__title">
12+
<Translate
13+
id="theme.NotFound.title"
14+
description="The title of the 404 page">
15+
Page Not Found
16+
</Translate>
17+
</Heading>
18+
<p>
19+
<Translate
20+
id="theme.NotFound.p1"
21+
description="The first paragraph of the 404 page">
22+
We could not find what you were looking for.
23+
</Translate>
24+
</p>
25+
<p>
26+
The version you are looking for may not be available.<br />
27+
Please check <Link to="/versions">the version page</Link> to find
28+
the documentation associated to the version you are using.
29+
</p>
30+
<p>
31+
<Translate
32+
id="theme.NotFound.p2"
33+
description="The 2nd paragraph of the 404 page">
34+
Please contact the owner of the site that linked you to the
35+
original URL and let them know their link is broken.
36+
</Translate>
37+
</p>
38+
39+
</div>
40+
</div>
41+
</main>
42+
);
43+
}

0 commit comments

Comments
 (0)