Skip to content

Commit f60987b

Browse files
committed
fix(helm/generate-docs): lint generated files
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent dfb9f58 commit f60987b

File tree

7 files changed

+138
-29
lines changed

7 files changed

+138
-29
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
]
2121
}
2222
}
23-
}
23+
}

actions/helm/generate-docs/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Mainly using [losisin/helm-docs-github-action](https://github.com/losisin/helm-d
3535
## Usage
3636

3737
```yaml
38-
- uses: hoverkraft-tech/ci-github-container/actions/helm/generate-docs@f9e149b6cdfa8443994994f10085691a57b8cf0e # 0.27.1
38+
- uses: hoverkraft-tech/ci-github-container/actions/helm/generate-docs@4f29319e02dd65152386c436e8c3136f380a0e71 # 0.28.0
3939
with:
4040
# Working directory
4141
# Default: `${{ github.workspace }}`
@@ -68,19 +68,19 @@ Mainly using [losisin/helm-docs-github-action](https://github.com/losisin/helm-d
6868
6969
## Inputs
7070
71-
| **Input** | **Description** | **Required** | **Default** |
72-
| ----------------------- | ------------------------------------------------------------------------- | ------------ | ------------------------- |
73-
| **`working-directory`** | Working directory | **false** | `${{ github.workspace }}` |
74-
| **`values-file`** | Path to the values file to use for generating the documentation. | **false** | - |
75-
| | See <https://github.com/losisin/helm-values-schema-json-action>. | | |
76-
| **`github-token`** | GitHub Token to create and merge pull request. | **false** | `${{ github.token }}` |
77-
| | Permissions: | | |
78-
| | - contents: write | | |
79-
| | - pull-requests: write | | |
80-
| **`github-app-id`** | GitHub App ID to generate GitHub token in place of github-token. | **false** | - |
81-
| | See <https://github.com/actions/create-github-app-token>. | | |
82-
| **`github-app-key`** | GitHub App private key to generate GitHub token in place of github-token. | **false** | - |
83-
| | See <https://github.com/actions/create-github-app-token>. | | |
71+
| **Input** | **Description** | **Required** | **Default** |
72+
| ----------------------- | ------------------------------------------------------------------------- | ------------ | --------------------------- |
73+
| **`working-directory`** | Working directory | **false** | `$\{\{ github.workspace }}` |
74+
| **`values-file`** | Path to the values file to use for generating the documentation. | **false** | - |
75+
| | See <https://github.com/losisin/helm-values-schema-json-action>. | | |
76+
| **`github-token`** | GitHub Token to create and merge pull request. | **false** | `$\{\{ github.token }}` |
77+
| | Permissions: | | |
78+
| | - contents: write | | |
79+
| | - pull-requests: write | | |
80+
| **`github-app-id`** | GitHub App ID to generate GitHub token in place of github-token. | **false** | - |
81+
| | See <https://github.com/actions/create-github-app-token>. | | |
82+
| **`github-app-key`** | GitHub App private key to generate GitHub token in place of github-token. | **false** | - |
83+
| | See <https://github.com/actions/create-github-app-token>. | | |
8484

8585
<!-- inputs:end -->
8686

actions/helm/generate-docs/action.yml

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ runs:
4444
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
4545
with:
4646
script: |
47-
const { existsSync, realpathSync } = require('node:fs');
47+
const { existsSync, realpathSync, writeFileSync } = require('node:fs');
4848
const { basename, isAbsolute, join } = require('node:path');
4949
5050
let workingDirectory = ${{ toJson(inputs.working-directory) }};
@@ -77,6 +77,38 @@ runs:
7777
core.setOutput("values-file", valuesFile);
7878
}
7979
80+
// Generate markdownlint config file if not exists
81+
let markdownlintConfigPath = join(workingDirectory, ".markdownlint.json");
82+
if (!existsSync(markdownlintConfigPath)) {
83+
markdownlintConfigPath = join(process.env.RUNNER_TEMP, `${Date.now()}.markdownlint.json`);
84+
85+
const defaultConfig = {
86+
"default": true,
87+
"line-length": false
88+
};
89+
writeFileSync(markdownlintConfigPath, JSON.stringify(defaultConfig, null, 2));
90+
}
91+
core.setOutput("markdownlint-config-path", markdownlintConfigPath);
92+
93+
// Generate textlint config file if not exists
94+
let textlintConfigPath = join(workingDirectory, ".textlintrc");
95+
if (!existsSync(textlintConfigPath)) {
96+
textlintConfigPath = join(process.env.RUNNER_TEMP, `${Date.now()}.textlintrc`);
97+
const defaultConfig = {
98+
"filters": {
99+
"comments": true
100+
},
101+
"rules": {
102+
"terminology": true
103+
},
104+
"plugins": {
105+
"@textlint/markdown": true
106+
}
107+
};
108+
writeFileSync(textlintConfigPath, JSON.stringify(defaultConfig, null, 2));
109+
}
110+
core.setOutput("textlint-config-path", textlintConfigPath);
111+
80112
- uses: hoverkraft-tech/ci-github-common/actions/checkout@5f11437c716059f30c635f90055060e4ef8b31a0 # 0.28.0
81113

82114
- uses: losisin/helm-docs-github-action@a57fae5676e4c55a228ea654a1bcaec8dd3cf5b5 # v1.6.2
@@ -89,13 +121,58 @@ runs:
89121
input: ${{ steps.prepare-variables.outputs.values-file }}
90122
working-directory: ${{ steps.prepare-variables.outputs.working-directory }}
91123

92-
- name: Prettify code
93-
uses: creyD/prettier_action@8c18391fdc98ed0d884c6345f03975edac71b8f0 # v4.6
124+
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
125+
126+
- id: npm-cache-dir
127+
shell: bash
128+
run: echo "dir=$(npm config get cache)" >> "$GITHUB_OUTPUT"
129+
130+
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
131+
id: npm-cache
132+
with:
133+
path: ${{ steps.npm-cache-dir.outputs.dir }}
134+
key: ${{ runner.os }}-node-${{ github.run_id }}
135+
restore-keys: |
136+
${{ runner.os }}-node-
137+
138+
- shell: bash
139+
run: npm install -g prettier textlint @textlint/textlint-plugin-markdown textlint-filter-rule-comments textlint-rule-terminology
140+
141+
- name: Cache textlint
142+
id: cache-textlint
143+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
144+
with:
145+
path: ${{ runner.temp }}/.cache-textlint
146+
key: ${{ runner.os }}-textlint-${{ hashFiles(steps.prepare-variables.outputs.textlint-config-path) }}
147+
148+
- name: Text lint and fix markdown files
149+
shell: bash
150+
working-directory: ${{ steps.prepare-variables.outputs.working-directory }}
151+
run: npx textlint --cache-location ${{ runner.temp }}/.cache-textlint --fix --config ${{ steps.prepare-variables.outputs.textlint-config-path }} ${{ steps.prepare-variables.outputs.working-directory }}/**/*.md
152+
153+
- name: Lint Fix markdown files
154+
uses: DavidAnson/markdownlint-cli2-action@992badcdf24e3b8eb7e87ff9287fe931bcb00c6e # v20.0.0
94155
with:
95-
prettier_options: --write ${{ steps.prepare-variables.outputs.working-directory }}/**/*.md ${{ steps.prepare-variables.outputs.values-file }}
96-
no_commit: true
97-
working_directory: ${{ steps.prepare-variables.outputs.working-directory }}
98-
clean_node_folder: true
156+
fix: true
157+
config: ${{ steps.prepare-variables.outputs.markdownlint-config-path }}
158+
globs: ${{ steps.prepare-variables.outputs.working-directory }}/**/*.md
159+
160+
- name: Cache prettier
161+
id: cache-prettier
162+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
163+
with:
164+
path: ${{ runner.temp }}/.cache-prettier
165+
key: ${{ runner.os }}-prettier
166+
167+
- name: Prettify markdown and values file
168+
shell: bash
169+
working-directory: ${{ steps.prepare-variables.outputs.working-directory }}
170+
run: |
171+
# First run
172+
npx prettier --cache-location ${{ runner.temp }}/.cache-prettier --write ${{ steps.prepare-variables.outputs.working-directory }}/**/*.md ${{ steps.prepare-variables.outputs.values-file || '' }}
173+
174+
# Second run to ensure idempotency
175+
npx prettier --cache-location ${{ runner.temp }}/.cache-prettier --write ${{ steps.prepare-variables.outputs.working-directory }}/**/*.md ${{ steps.prepare-variables.outputs.values-file || '' }}
99176
100177
- uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4
101178
if: inputs.github-app-id

actions/helm/generate-docs/package-lock.json

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"prettier": "^3.6.2"
4+
}
5+
}

tests/charts/application/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ A Helm chart for Kubernetes
66

77
## Requirements
88

9-
| Repository | Name | Version |
10-
| ---------------------------------- | ----- | ------- |
11-
| https://charts.bitnami.com/bitnami | mysql | 14.0.3 |
9+
| Repository | Name | Version |
10+
| ------------------------------------ | ----- | ------- |
11+
| <https://charts.bitnami.com/bitnami> | MySQL | 14.0.3 |
1212

1313
## Values
1414

tests/charts/umbrella-application/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ An umbrella Helm chart for Kubernetes
66

77
## Requirements
88

9-
| Repository | Name | Version |
10-
| ---------------------------------- | --------------- | ------- |
11-
| file://./charts/app | app | 0.0.0 |
12-
| https://charts.bitnami.com/bitnami | database(mysql) | 14.0.3 |
9+
| Repository | Name | Version |
10+
| ------------------------------------ | --------------- | ------- |
11+
| file://./charts/app | app | 0.0.0 |
12+
| <https://charts.bitnami.com/bitnami> | database(MySQL) | 14.0.3 |
1313

1414
## Values
1515

0 commit comments

Comments
 (0)