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) }};
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
0 commit comments