Skip to content

Commit 04b56a6

Browse files
committed
run vale in docker
Signed-off-by: CrazyMax <[email protected]>
1 parent c69c0b5 commit 04b56a6

File tree

4 files changed

+79
-14
lines changed

4 files changed

+79
-14
lines changed

.github/workflows/build.yml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,40 +68,43 @@ jobs:
6868
AWS_CLOUDFRONT_ID: 0123456789ABCD
6969
AWS_LAMBDA_FUNCTION: DockerDocsRedirectFunction-dummy
7070

71-
vale:
72-
if: ${{ github.event_name == 'pull_request' }}
73-
runs-on: ubuntu-24.04
74-
steps:
75-
- uses: actions/checkout@v4
76-
- uses: errata-ai/vale-action@reviewdog
77-
env:
78-
PIP_BREAK_SYSTEM_PACKAGES: 1
79-
with:
80-
files: content
81-
8271
validate:
8372
runs-on: ubuntu-24.04
8473
strategy:
8574
fail-fast: false
8675
matrix:
8776
target:
8877
- lint
78+
- vale
8979
- test
9080
- unused-media
9181
- test-go-redirects
9282
- dockerfile-lint
9383
- path-warnings
9484
- validate-vendor
9585
steps:
86+
-
87+
name: Checkout
88+
uses: actions/checkout@v4
9689
-
9790
name: Set up Docker Buildx
9891
uses: docker/setup-buildx-action@v3
9992
-
10093
name: Validate
10194
uses: docker/bake-action@v6
10295
with:
96+
source: .
10397
files: |
10498
docker-bake.hcl
10599
targets: ${{ matrix.target }}
106-
set: |
107-
*.args.BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
100+
-
101+
name: Install reviewdog
102+
if: ${{ matrix.target == 'vale' && github.event_name == 'pull_request' }}
103+
uses: reviewdog/action-setup@e04ffabe3898a0af8d0fb1af00c188831c4b5893 # v1.3.2
104+
-
105+
name: Run reviewdog for vale
106+
if: ${{ matrix.target == 'vale' && github.event_name == 'pull_request' }}
107+
run: |
108+
cat ./tmp/vale.out | reviewdog -f=rdjsonl -name=vale -reporter=github-pr-annotations -fail-on-error=false -filter-mode=added -level=info
109+
env:
110+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.vale-rdjsonl.tmpl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{{- /* Range over the linted files */ -}}
2+
3+
{{- range .Files}}
4+
5+
{{- $path := .Path -}}
6+
7+
{{- /* Range over the file's alerts */ -}}
8+
9+
{{- range .Alerts -}}
10+
11+
{{- $error := "" -}}
12+
{{- if eq .Severity "error" -}}
13+
{{- $error = "ERROR" -}}
14+
{{- else if eq .Severity "warning" -}}
15+
{{- $error = "WARNING" -}}
16+
{{- else -}}
17+
{{- $error = "INFO" -}}
18+
{{- end}}
19+
20+
{{- /* Variables setup */ -}}
21+
22+
{{- $line := printf "%d" .Line -}}
23+
{{- $col := printf "%d" (index .Span 0) -}}
24+
{{- $check := printf "%s" .Check -}}
25+
{{- $message := printf "%s" .Message -}}
26+
27+
{{- /* Output */ -}}
28+
29+
{"message": "[{{ $check }}] {{ $message | jsonEscape }}", "location": {"path": "{{ $path }}", "range": {"start": {"line": {{ $line }}, "column": {{ $col }}}}}, "severity": "{{ $error }}"}
30+
{{end -}}
31+
{{end -}}

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
ARG ALPINE_VERSION=3.21
55
ARG GO_VERSION=1.24
66
ARG HTMLTEST_VERSION=0.17.0
7+
ARG VALE_VERSION=3.11.2
78
ARG HUGO_VERSION=0.141.0
89
ARG NODE_VERSION=22
910
ARG PAGEFIND_VERSION=1.3.0
@@ -67,6 +68,23 @@ COPY --from=build /project/public ./public
6768
ADD .htmltest.yml .htmltest.yml
6869
RUN htmltest
6970

71+
# vale
72+
FROM jdkato/vale:v${VALE_VERSION} AS vale-run
73+
WORKDIR /src
74+
ARG GITHUB_ACTIONS
75+
RUN --mount=type=bind,target=.,rw <<EOT
76+
set -e
77+
mkdir /out
78+
args=""
79+
[ "$GITHUB_ACTIONS" = "true" ] && args="--output=.vale-rdjsonl.tmpl"
80+
set -x
81+
vale sync
82+
vale $args content/ | tee /out/vale.out
83+
EOT
84+
85+
FROM scratch AS vale
86+
COPY --from=vale-run /out/vale.out /
87+
7088
# update-modules downloads and vendors Hugo modules
7189
FROM build-base AS update-modules
7290
# MODULE is the Go module path and version of the module to update

docker-bake.hcl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ variable "DRY_RUN" {
1414
default = null
1515
}
1616

17+
variable "GITHUB_ACTIONS" {
18+
default = null
19+
}
20+
1721
group "default" {
1822
targets = ["release"]
1923
}
@@ -36,7 +40,7 @@ target "release" {
3640
}
3741

3842
group "validate" {
39-
targets = ["lint", "test", "unused-media", "test-go-redirects", "dockerfile-lint", "path-warnings", "validate-vendor"]
43+
targets = ["lint", "vale", "test", "unused-media", "test-go-redirects", "dockerfile-lint", "path-warnings", "validate-vendor"]
4044
}
4145

4246
target "test" {
@@ -51,6 +55,15 @@ target "lint" {
5155
provenance = false
5256
}
5357

58+
target "vale" {
59+
target = "vale"
60+
args = {
61+
GITHUB_ACTIONS = GITHUB_ACTIONS
62+
}
63+
output = ["./tmp"]
64+
provenance = false
65+
}
66+
5467
target "unused-media" {
5568
target = "unused-media"
5669
output = ["type=cacheonly"]

0 commit comments

Comments
 (0)