-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
245 lines (219 loc) · 10.1 KB
/
action.yml
File metadata and controls
245 lines (219 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
---
name: "Helm - Generate Chart Documentation"
description: |
Action to generate documentation for a Helm chart.
It will generate the documentation in the `docs/` directory of the chart.
Mainly using [losisin/helm-docs-github-action](https://github.com/losisin/helm-docs-github-action).
author: hoverkraft
branding:
icon: book-open
color: blue
inputs:
working-directory:
description: "Working directory"
required: false
default: "${{ github.workspace }}"
values-file:
description: |
Path to the values file to use for generating the documentation.
See https://github.com/losisin/helm-values-schema-json-action.
required: false
github-token:
description: |
GitHub Token to create and merge pull request.
Permissions:
- contents: write
- pull-requests: write
default: ${{ github.token }}
github-app-id:
description: |
GitHub App ID to generate GitHub token in place of github-token.
See https://github.com/actions/create-github-app-token.
required: false
github-app-key:
description: |
GitHub App private key to generate GitHub token in place of github-token.
See https://github.com/actions/create-github-app-token.
required: false
runs:
using: "composite"
steps:
- id: prepare-variables
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const { existsSync, realpathSync, writeFileSync } = require('node:fs');
const { basename, isAbsolute, join } = require('node:path');
let workingDirectory = ${{ toJson(inputs.working-directory) }};
if (!workingDirectory || !workingDirectory.length) {
return core.setFailed("Input 'working-directory' is required.");
}
if (!existsSync(workingDirectory)) {
return core.setFailed(`Working directory '${workingDirectory}' does not exist.`);
}
workingDirectory = realpathSync(workingDirectory);
core.setOutput("working-directory", workingDirectory);
core.setOutput("working-directory-name", basename(workingDirectory));
const filesPattern = join(workingDirectory, "**/*.md");;
core.setOutput("files-pattern", filesPattern);
let valuesFile = ${{ toJson(inputs.values-file) }};
if (valuesFile && valuesFile.length) {
if(isAbsolute(valuesFile)) {
if (!existsSync(valuesFile)) {
return core.setFailed(`The values file '${valuesFile}' does not exist.`);
}
} else {
valuesFile = join(workingDirectory, valuesFile);
if(!existsSync(valuesFile)) {
return core.setFailed(`The values file '${valuesFile}' does not exist in the working directory '${workingDirectory}'.`);
}
}
valuesFile = realpathSync(valuesFile);
core.setOutput("values-file", valuesFile);
}
// Generate textlint cache path
const textlintCachePath = join(process.env.RUNNER_TEMP, `.cache-textlint`);
core.setOutput("textlint-cache-path", textlintCachePath);
// Generate textlint config file if not exists
let textlintConfigPath = join(workingDirectory, ".textlintrc");
if (!existsSync(textlintConfigPath)) {
textlintConfigPath = join(process.env.RUNNER_TEMP, `${Date.now()}.textlintrc`);
const defaultConfig = {
"filters": {
"comments": true
},
"rules": {
"terminology": true
},
"plugins": {
"@textlint/markdown": true
}
};
writeFileSync(textlintConfigPath, JSON.stringify(defaultConfig, null, 2));
}
core.setOutput("textlint-config-path", textlintConfigPath);
// Generate prettier cache path
const prettierCachePath = join(process.env.RUNNER_TEMP, `.cache-prettier`);
core.setOutput("prettier-cache-path", prettierCachePath);
// Generate markdownlint config file if not exists
let markdownlintConfigPath = join(workingDirectory, ".markdownlint.json");
if (!existsSync(markdownlintConfigPath)) {
markdownlintConfigPath = join(process.env.RUNNER_TEMP, `${Date.now()}.markdownlint.json`);
const defaultConfig = {
"default": true,
"line-length": false,
"outputFormatters": [
[
"markdownlint-cli2-formatter-template",
{
"template": "::${errorSeverity:${errorSeverity}}${errorSeverity!error} " +
"file=${fileName},line=${lineNumber},${columnNumber:col=${columnNumber},}title=${ruleName}::${ruleDescription}"
}
]
]
};
writeFileSync(markdownlintConfigPath, JSON.stringify(defaultConfig, null, 2));
}
core.setOutput("markdownlint-config-path", markdownlintConfigPath);
- uses: hoverkraft-tech/ci-github-common/actions/checkout@5e8d0e6d1e76d8577a070db6d0128a91b1c9d5ad # 0.30.2
- uses: losisin/helm-docs-github-action@a57fae5676e4c55a228ea654a1bcaec8dd3cf5b5 # v1.6.2
with:
chart-search-root: ${{ steps.prepare-variables.outputs.working-directory }}
- if: ${{ steps.prepare-variables.outputs.values-file }}
uses: losisin/helm-values-schema-json-action@660c441a4a507436a294fc55227e1df54aca5407 # v2.3.1
with:
input: ${{ steps.prepare-variables.outputs.values-file }}
working-directory: ${{ steps.prepare-variables.outputs.working-directory }}
- name: Setup Node.js
uses: hoverkraft-tech/ci-github-nodejs/actions/setup-node@ce2bb8274a37c1219be2bcae2a1b2528c2c72957 # 0.19.0
with:
working-directory: ${{ github.action_path }}
- name: Cache textlint
id: cache-textlint
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: ${{ steps.prepare-variables.outputs.textlint-cache-path }}
key: ${{ runner.os }}-textlint-${{ hashFiles(steps.prepare-variables.outputs.textlint-config-path) }}
- name: Text lint and fix files
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
NODE_PATH: ${{ github.action_path }}/node_modules
WORKING_DIRECTORY: ${{ steps.prepare-variables.outputs.working-directory }}
FILES_PATTERN: ${{ steps.prepare-variables.outputs.files-pattern }}
CACHE_PATH: ${{ steps.prepare-variables.outputs.textlint-cache-path }}
CONFIG_PATH: ${{ steps.prepare-variables.outputs.textlint-config-path }}
with:
script: |
await exec.exec('npx', [
'textlint',
'--cache-location', process.env.CACHE_PATH,
'--fix',
'--config', process.env.CONFIG_PATH,
process.env.FILES_PATTERN,
], {
cwd: process.env.WORKING_DIRECTORY,
});
- name: Cache prettier
id: cache-prettier
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: ${{ steps.prepare-variables.outputs.prettier-cache-path }}
key: ${{ runner.os }}-prettier
- name: Prettify markdown and values file
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
NODE_PATH: ${{ github.action_path }}/node_modules
WORKING_DIRECTORY: ${{ steps.prepare-variables.outputs.working-directory }}
CACHE_PATH: ${{ steps.prepare-variables.outputs.prettier-cache-path }}
FILES_PATTERN: ${{ steps.prepare-variables.outputs.files-pattern }}
VALUES_FILE: ${{ steps.prepare-variables.outputs.values-file || '' }}
with:
script: |
await exec.exec('npx', [
'prettier',
'--cache-location', process.env.CACHE_PATH,
'--write',
process.env.FILES_PATTERN,
process.env.VALUES_FILE,
], {
cwd: process.env.WORKING_DIRECTORY,
});
- name: Lint Fix markdown files
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
NODE_PATH: ${{ github.action_path }}/node_modules
WORKING_DIRECTORY: ${{ steps.prepare-variables.outputs.working-directory }}
FILES_PATTERN: ${{ steps.prepare-variables.outputs.files-pattern }}
CONFIG_PATH: ${{ steps.prepare-variables.outputs.markdownlint-config-path }}
with:
script: |
await exec.exec('npx', [
'markdownlint-cli2',
'--fix',
'--config', process.env.CONFIG_PATH,
process.env.FILES_PATTERN,
], {
cwd: process.env.WORKING_DIRECTORY,
});
- name: Lint Fix markdown files
uses: DavidAnson/markdownlint-cli2-action@30a0e04f1870d58f8d717450cc6134995f993c63 # v21.0.0
with:
fix: true
config: ${{ steps.prepare-variables.outputs.markdownlint-config-path }}
globs: ${{ steps.prepare-variables.outputs.working-directory }}/**/*.md
- uses: actions/create-github-app-token@7e473efe3cb98aa54f8d4bac15400b15fad77d94 # v2.2.0
if: inputs.github-app-id
id: generate-token
with:
app-id: ${{ inputs.github-app-id }}
private-key: ${{ inputs.github-app-key }}
- uses: hoverkraft-tech/ci-github-common/actions/create-and-merge-pull-request@5e8d0e6d1e76d8577a070db6d0128a91b1c9d5ad # 0.30.2
with:
github-token: ${{ steps.generate-token.outputs.token || inputs.github-token }}
branch: docs/update-helm-chart-docs-${{ steps.prepare-variables.outputs.working-directory-name }}
title: "docs: update Helm chart documentation for ${{ steps.prepare-variables.outputs.working-directory-name }}"
body: |
This pull request updates the documentation for the Helm chart `${{ steps.prepare-variables.outputs.working-directory-name }}`.
commit-message: |
docs: update Helm chart documentation for ${{ steps.prepare-variables.outputs.working-directory-name }}
[skip ci]