Skip to content

Commit 8027afe

Browse files
committed
chore: fix lint issues
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent 073052e commit 8027afe

9 files changed

Lines changed: 186 additions & 92 deletions

File tree

.github/actions/generate-docs/__tests__/homepage-projects-updater.test.js

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import path from "node:path";
2+
import fs from "node:fs";
3+
import mockFs from "mock-fs";
24
import { describe, expect, it, vi } from "vitest";
35

46
process.env.GITHUB_REPOSITORY_OWNER ??= "hoverkraft-tech";
@@ -7,6 +9,25 @@ process.env.GITHUB_REPOSITORY ??= "hoverkraft-tech/public-docs";
79
const { HomepageProjectsUpdater } = await import(
810
"../lib/homepage/homepage-projects-updater.js"
911
);
12+
const { ConstDeclarationUpdater } = await import(
13+
"../lib/builders/const-declaration-updater.js"
14+
);
15+
16+
const homepagePath = path.join(
17+
process.cwd(),
18+
"application/src/pages/index.tsx",
19+
);
20+
const repositories = [
21+
{
22+
name: "compose-action",
23+
html_url: "https://github.com/hoverkraft-tech/compose-action",
24+
stargazers_count: 210,
25+
language: "TypeScript",
26+
description:
27+
"This action runs your docker-compose file and clean up before action finished",
28+
topics: ["continuous-integration", "docker-compose", "github-actions"],
29+
},
30+
];
1031

1132
describe("HomepageProjectsUpdater", () => {
1233
it("formats the homepage file after updating featured projects", async () => {
@@ -16,22 +37,6 @@ describe("HomepageProjectsUpdater", () => {
1637
const formatter = {
1738
format: vi.fn().mockResolvedValue(undefined),
1839
};
19-
const homepagePath = path.join(
20-
process.cwd(),
21-
"application/src/pages/index.tsx",
22-
);
23-
const repositories = [
24-
{
25-
name: "compose-action",
26-
html_url: "https://github.com/hoverkraft-tech/compose-action",
27-
stargazers_count: 210,
28-
language: "TypeScript",
29-
description:
30-
"This action runs your docker-compose file and clean up before action finished",
31-
topics: ["continuous-integration", "docker-compose", "github-actions"],
32-
},
33-
];
34-
3540
const updater = new HomepageProjectsUpdater({
3641
homepagePath,
3742
constDeclarationUpdater,
@@ -41,8 +46,9 @@ describe("HomepageProjectsUpdater", () => {
4146
await updater.update(repositories);
4247

4348
expect(constDeclarationUpdater.update).toHaveBeenCalledWith(homepagePath, [
44-
{
49+
expect.objectContaining({
4550
name: "projects",
51+
serialize: expect.any(Function),
4652
value: [
4753
{
4854
accent: "primary",
@@ -60,7 +66,7 @@ describe("HomepageProjectsUpdater", () => {
6066
url: "https://github.com/hoverkraft-tech/compose-action",
6167
},
6268
],
63-
},
69+
}),
6470
]);
6571
expect(formatter.format).toHaveBeenCalledWith(homepagePath);
6672
});
@@ -72,10 +78,6 @@ describe("HomepageProjectsUpdater", () => {
7278
const formatter = {
7379
format: vi.fn().mockResolvedValue(undefined),
7480
};
75-
const homepagePath = path.join(
76-
process.cwd(),
77-
"application/src/pages/index.tsx",
78-
);
7981
const updater = new HomepageProjectsUpdater({
8082
homepagePath,
8183
constDeclarationUpdater,
@@ -96,4 +98,36 @@ describe("HomepageProjectsUpdater", () => {
9698

9799
expect(formatter.format).not.toHaveBeenCalled();
98100
});
101+
102+
it("writes homepage projects using lint-compatible TSX style", async () => {
103+
const homepageContent = fs.readFileSync(homepagePath, "utf8");
104+
105+
mockFs({
106+
[homepagePath]: homepageContent,
107+
});
108+
109+
try {
110+
const formatter = {
111+
format: vi.fn().mockResolvedValue(undefined),
112+
};
113+
const updater = new HomepageProjectsUpdater({
114+
homepagePath,
115+
constDeclarationUpdater: new ConstDeclarationUpdater(),
116+
formatter,
117+
});
118+
119+
await updater.update(repositories);
120+
121+
const updatedHomepage = fs.readFileSync(homepagePath, "utf8");
122+
123+
expect(updatedHomepage).toContain('name: "compose-action"');
124+
expect(updatedHomepage).toContain(
125+
'tags: ["continuous-integration", "docker-compose", "github-actions"]',
126+
);
127+
expect(updatedHomepage).not.toContain("name: 'compose-action'");
128+
expect(updatedHomepage).not.toContain("'continuous-integration'");
129+
} finally {
130+
mockFs.restore();
131+
}
132+
});
99133
});

.github/actions/generate-docs/lib/homepage/homepage-projects-updater.js

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ class HomepageProjectsUpdater {
3131
const projectsModel = this.buildProjectsModel(featured);
3232
const hasChanges = await this.constDeclarationUpdater.update(
3333
this.homepagePath,
34-
[{ name: "projects", value: projectsModel }],
34+
[
35+
{
36+
name: "projects",
37+
value: projectsModel,
38+
serialize: serializeHomepageProjects,
39+
},
40+
],
3541
);
3642

3743
if (hasChanges) {
@@ -79,6 +85,69 @@ class HomepageProjectsUpdater {
7985
}
8086
}
8187

88+
function serializeHomepageProjects(projects) {
89+
if (!Array.isArray(projects) || projects.length === 0) {
90+
return "[]";
91+
}
92+
93+
const body = projects
94+
.map((project) => serializeHomepageProject(project, 1))
95+
.join(",\n");
96+
97+
return `\n${body}\n`;
98+
}
99+
100+
function serializeHomepageProject(project, indentLevel) {
101+
const indent = " ".repeat(indentLevel);
102+
const propertyIndent = " ".repeat(indentLevel + 1);
103+
104+
return [
105+
`${indent}{`,
106+
`${propertyIndent}name: ${serializeHomepageString(project.name)},`,
107+
`${propertyIndent}icon: ${serializeHomepageString(project.icon)},`,
108+
`${propertyIndent}url: ${serializeHomepageString(project.url)},`,
109+
`${propertyIndent}stars: ${String(project.stars ?? 0)},`,
110+
`${propertyIndent}language: ${serializeHomepageString(project.language)},`,
111+
serializeHomepageDescription(project.description, propertyIndent),
112+
`${propertyIndent}tags: ${serializeHomepageInlineStringArray(project.tags)},`,
113+
`${propertyIndent}accent: ${serializeHomepageString(project.accent)},`,
114+
`${indent}}`,
115+
].join("\n");
116+
}
117+
118+
function serializeHomepageDescription(description, indent) {
119+
const normalizedDescription = description ?? "";
120+
const serialized = serializeHomepageString(normalizedDescription);
121+
const singleLine = `${indent}description: ${serialized},`;
122+
123+
if (singleLine.length <= 80) {
124+
return singleLine;
125+
}
126+
127+
return `${indent}description:\n${indent} ${serialized},`;
128+
}
129+
130+
function serializeHomepageInlineStringArray(values) {
131+
if (!Array.isArray(values) || values.length === 0) {
132+
return "[]";
133+
}
134+
135+
return `[${values.map((value) => serializeHomepageString(value)).join(", ")}]`;
136+
}
137+
138+
function serializeHomepageString(value) {
139+
return `"${escapeHomepageString(String(value ?? ""))}"`;
140+
}
141+
142+
function escapeHomepageString(value) {
143+
return value
144+
.replace(/\\/g, "\\\\")
145+
.replace(/\n/g, "\\n")
146+
.replace(/\r/g, "\\r")
147+
.replace(/\t/g, "\\t")
148+
.replace(/"/g, '\\"');
149+
}
150+
82151
module.exports = {
83152
HomepageProjectsUpdater,
84153
};

application/docs/projects/ci-cd-tools/docker-base-images/actions/should-build-images/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ Check if some files have changed requiring the build of the given images.
5858
5959
## Inputs
6060
61-
| **Input** | **Description** | **Required** | **Default** |
62-
| -------------- | ----------------------------------------------------------------------------------------------------------------- | ------------ | ----------- |
63-
| **`images`** | Image names located in the 'images' folder. | **true** | - |
64-
| | Formatted as a JSON array. | | |
65-
| | Example: `["php-8", "nodejs-24"]` | | |
61+
| **Input** | **Description** | **Required** | **Default** |
62+
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ----------- |
63+
| **`images`** | Image names located in the 'images' folder. | **true** | - |
64+
| | Formatted as a JSON array. | | |
65+
| | Example: `["php-8", "nodejs-24"]` | | |
6666
| **`base-sha`** | Specify a different base commit SHA used for comparing changes. See [https://github.com/tj-actions/changed-files](https://github.com/tj-actions/changed-files) | **false** | - |
6767

6868
<!-- inputs:end -->

application/docs/projects/ci-cd-tools/docker-base-images/github/workflows/continuous-integration.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,17 @@ jobs:
172172
173173
### Workflow Call Inputs
174174
175-
| **Input** | **Description** | **Required** | **Type** | **Default** |
176-
| --------------------------- | -------------------------------------------------------------------------------------------- | ------------ | ---------- | -------------------------------- |
177-
| **`runs-on`** | JSON array of runner(s) to use. | **false** | **string** | `["ubuntu-latest"]` |
178-
| | See [https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job](https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job). | | | |
179-
| **`oci-registry`** | OCI registry where to pull and push images. | **false** | **string** | `ghcr.io` |
180-
| **`oci-registry-username`** | Username used to log against the OCI registry. | **false** | **string** | `${{ github.repository_owner }}` |
181-
| | See [https://github.com/docker/login-action#usage](https://github.com/docker/login-action#usage). | | | |
182-
| **`platforms`** | JSON array of platforms to build images for by default. | **false** | **string** | `["linux/amd64","linux/arm64"]` |
183-
| | Can be overridden per image with `images/<image>/build.json` or an image object in `images`. | | | |
184-
| | See [https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images](https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images). | | | |
185-
| **`test-image-tag`** | Tag of the published `testcontainers-node` runner image to use for tests. | **false** | **string** | `latest` |
175+
| **Input** | **Description** | **Required** | **Type** | **Default** |
176+
| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ---------- | -------------------------------- |
177+
| **`runs-on`** | JSON array of runner(s) to use. | **false** | **string** | `["ubuntu-latest"]` |
178+
| | See [https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job](https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job). | | | |
179+
| **`oci-registry`** | OCI registry where to pull and push images. | **false** | **string** | `ghcr.io` |
180+
| **`oci-registry-username`** | Username used to log against the OCI registry. | **false** | **string** | `${{ github.repository_owner }}` |
181+
| | See [https://github.com/docker/login-action#usage](https://github.com/docker/login-action#usage). | | | |
182+
| **`platforms`** | JSON array of platforms to build images for by default. | **false** | **string** | `["linux/amd64","linux/arm64"]` |
183+
| | Can be overridden per image with `images/<image>/build.json` or an image object in `images`. | | | |
184+
| | See [https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images](https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images). | | | |
185+
| **`test-image-tag`** | Tag of the published `testcontainers-node` runner image to use for tests. | **false** | **string** | `latest` |
186186
187187
<!-- inputs:end -->
188188
@@ -204,9 +204,9 @@ jobs:
204204
205205
## Outputs
206206
207-
| **Output** | **Description** |
208-
| ------------------ | ------------------------------------------------------------------------------------------------------------------------ |
209-
| **`built-images`** | Built images data. |
207+
| **Output** | **Description** |
208+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
209+
| **`built-images`** | Built images data. |
210210
| | See [https://github.com/hoverkraft-tech/ci-github-container/blob/main/.github/workflows/docker-build-images.md#outputs](https://github.com/hoverkraft-tech/ci-github-container/blob/main/.github/workflows/docker-build-images.md#outputs). |
211211
212212
<!-- outputs:end -->

application/docs/projects/ci-cd-tools/docker-base-images/github/workflows/prepare-release.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ jobs:
7777
7878
### Workflow Call Inputs
7979
80-
| **Input** | **Description** | **Required** | **Type** | **Default** |
81-
| ------------- | ---------------------------------------------------------------------------------- | ------------ | ---------- | ------------------- |
82-
| **`runs-on`** | JSON array of runner(s) to use. | **false** | **string** | `["ubuntu-latest"]` |
80+
| **Input** | **Description** | **Required** | **Type** | **Default** |
81+
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ---------- | ------------------- |
82+
| **`runs-on`** | JSON array of runner(s) to use. | **false** | **string** | `["ubuntu-latest"]` |
8383
| | See [https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job](https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job). | | | |
8484

8585
<!-- inputs:end -->

application/docs/projects/ci-cd-tools/docker-base-images/github/workflows/prune-pull-requests-images-tags.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ jobs:
8181
8282
### Workflow Call Inputs
8383
84-
| **Input** | **Description** | **Required** | **Type** | **Default** |
85-
| ------------- | ---------------------------------------------------------------------------------- | ------------ | ---------- | ------------------- |
86-
| **`runs-on`** | JSON array of runner(s) to use. | **false** | **string** | `["ubuntu-latest"]` |
84+
| **Input** | **Description** | **Required** | **Type** | **Default** |
85+
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ---------- | ------------------- |
86+
| **`runs-on`** | JSON array of runner(s) to use. | **false** | **string** | `["ubuntu-latest"]` |
8787
| | See [https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job](https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job). | | | |
8888

8989
<!-- inputs:end -->

0 commit comments

Comments
 (0)