Grafsean/update openapi docs 1 #1742
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Documentation CI | |
on: | |
pull_request: | |
paths: ["docs/sources/**", "vale/**"] | |
workflow_dispatch: | |
jobs: | |
doc-validator: | |
if: ${{ github.repository == 'grafana/writers-toolkit' }} | |
runs-on: ubuntu-latest | |
container: | |
image: grafana/doc-validator:v5.2.0@sha256:71de7a0b0ff89ef849afc445aafc8f85abf022f8dce5bc9a92ff32fbddd332ab | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
persist-credentials: false | |
- name: Run doc-validator tool | |
run: > | |
doc-validator | |
'--skip-checks=^image.+$' | |
docs/sources | |
/docs/writers-toolkit | |
| grep -v sources/shared | |
| grep -v anchorize.inline | |
| reviewdog | |
-f=rdjsonl | |
--fail-on-error | |
--filter-mode=nofilter | |
--name=doc-validator | |
--reporter=github-pr-review | |
env: | |
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
prettier: | |
if: ${{ github.repository == 'grafana/writers-toolkit' }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
persist-credentials: false | |
- run: > | |
curl | |
--location | |
--output reviewdog.tar.gz | |
https://github.com/jdbaldry/reviewdog/releases/download/v0.18.0-rc.1/reviewdog_0.18.0-rc.1_Linux_x86_64.tar.gz | |
- run: | | |
tar zxf reviewdog.tar.gz reviewdog | |
sudo cp reviewdog /usr/local/bin/ | |
rm -f reviewdog.tar.gz | |
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 | |
with: | |
node-version: 20 | |
- run: npm install --no-save prettier | |
- run: > | |
reviewdog | |
--filter-mode=nofilter | |
--runners prettier | |
--tee | |
- run: > | |
git diff | |
| reviewdog | |
--f diff | |
--fail-on-error | |
--filter-mode nofilter | |
--reporter=github-pr-review | |
env: | |
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
test: | |
if: ${{ github.repository == 'grafana/writers-toolkit' }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
persist-credentials: false | |
- name: Build website | |
uses: grafana/writers-toolkit/build-website@4b1248585248751e3b12fd020cf7ac91540ca09c # build-website/v1.0.1 | |
with: | |
website_directory: docs/writers-toolkit | |
vale: | |
runs-on: ubuntu-latest | |
container: | |
image: grafana/vale:latest@sha256:55bf7dcba4ceac896b55225084bdb0b27e2e2f70c1398313bee13cb45eb60a95 | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
persist-credentials: false | |
- uses: ./vale-action | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
report-readability: | |
if: ${{ github.repository == 'grafana/writers-toolkit' }} | |
container: | |
image: grafana/vale:latest@sha256:55bf7dcba4ceac896b55225084bdb0b27e2e2f70c1398313bee13cb45eb60a95 | |
name: Report readability | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository with history | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
fetch-depth: 0 | |
persist-credentials: false | |
- name: Install Bash | |
run: apk add bash | |
- name: Run tool | |
env: | |
BASE_SHA: ${{ github.event.pull_request.base.sha }} | |
HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
run: | | |
(cd /etc/vale && vale sync) | |
git config --global --add safe.directory /__w/writers-toolkit/writers-toolkit | |
touch .output.txt | |
for file in $(git --no-pager diff --name-only --diff-filter=ACMRT "${BASE_SHA}" -- docs/sources); do | |
./scripts/readability "${file}" "${BASE_SHA}" ${HEAD_SHA} >> .output.txt | |
done | |
shell: bash | |
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
with: | |
script: | | |
const fs = require("fs"); | |
const measures = [ | |
"AutomatedReadability", | |
"ColemanLiau", | |
"FleschKincaid", | |
"FleschReadingEase", | |
"GunningFog ", | |
"LIX", | |
"SMOG", | |
]; | |
let body = "### Readability report\n"; | |
body += `| File | ${measures.join(" | ")} |\n`; | |
body += `| - |${" - |".repeat(measures.length)}\n`; | |
let i = 0; | |
const output = fs.readFileSync(".output.txt", "utf-8") | |
if (output !== "") { | |
output.split("\n").forEach((line) => { | |
// docs/sources/_index.md Grafana.ReadabilityAutomatedReadability 8.99 (Δ+0.84) aim for below 8. | |
const re = new RegExp( | |
"^(?<file>[^\t]+?)\t(?<rule>[^\t]+?)\t(?<score>[^\t]+?)\t(?<delta>[^\t]+?)\t(?<guide>[^\t]+?)$", | |
); | |
const result = re.exec(line); | |
if (result !== null) { | |
const { file, rule, score, delta, guide } = result.groups; | |
if (i === 0) { | |
body += `| ${file} |`; | |
} | |
let color = "green"; | |
const fl = parseFloat(delta.replace(new RegExp("\\(Δ(.+)\\)"), "$1")); | |
if ( | |
(rule !== "Grafana.ReadabilityFleschReadingEase" && fl > 0) || | |
(rule === "Grafana.ReadabilityFleschReadingEase" && fl < 0) | |
) { | |
color = "red"; | |
} | |
if (fl === 0) { | |
color = "black"; | |
} | |
body += " $${" + score + "\\space\\color{" + color + "}" + delta + "}$$ |"; | |
if (i === measures.length - 1) { | |
body += "\n"; | |
} | |
i = (i + 1) % measures.length; | |
} | |
}); | |
body += `<details> | |
<summary>View metric targets</summary> | |
| Metric | Range | Ideal score | | |
| --- | --- | --- | | |
| [AutomatedReadability](https://en.wikipedia.org/wiki/Automated_readability_index) | 6 (very easy read) to 14 (extremely difficult read) | 8 or less | | |
| [ColemanLiau](https://en.wikipedia.org/wiki/Coleman%E2%80%93Liau_index) | 6 (very easy read) to 17 (extremely difficult read) | 9 or less | | |
| [FleschKincaid](https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests) | 6 (very easy read) to 17 (extremely difficult read) | 8 or less | | |
| [FleschReadingEase](https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests) | 100 (very easy read) to 0 (extremely difficult read) | 70 or more | | |
| [GunningFog](https://en.wikipedia.org/wiki/Gunning_fog_index) | 6 (very easy read) to 17 (extremely difficult read) | 10 or less | | |
| [LIX](https://en.wikipedia.org/wiki/Lix_(readability_test)) | 20 (very easy read) to 60+ (extremely difficult read) | 35 or less | | |
| [SMOG](https://en.wikipedia.org/wiki/SMOG) | 6 (very easy read) to 17 (extremely difficult read) | 10 or less | | |
</details>`; | |
const {data: comments} = await github.rest.issues.listComments({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
const existing = comments.filter((comment) => comment.body.match(new RegExp("^### Readability report"))) | |
if (existing.length > 0) { | |
github.rest.issues.updateComment({ | |
comment_id: existing[0].id, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body, | |
}) | |
} else { | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body, | |
}) | |
} | |
} |