Skip to content

Commit 35a569b

Browse files
authored
Merge pull request #45699 from aireilly/adding-vale-errror-checking
Adding Vale error checking in the OCP docs travis build
2 parents 2edb33e + 624014d commit 35a569b

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

.travis.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ language: python
22
cache: pip
33
# env:
44
# - PR_AUTHOR=${TRAVIS_PULL_REQUEST_SLUG::-15}
5-
5+
git:
6+
depth: 1
67
jobs:
78
include:
89
- stage: build
10+
name: "Build openshift-enterprise distro"
911
before_install:
1012
- gem install asciidoctor
1113
- gem install asciidoctor-diagram
@@ -16,6 +18,7 @@ jobs:
1618
- python3 build.py --distro openshift-enterprise --product "OpenShift Container Platform" --version 4.11 --no-upstream-fetch && python3 makeBuild.py
1719
- # stage name not required, will continue to use `build`
1820
if: branch IN (main, enterprise-4.11, enterprise-4.12)
21+
name: "Build openshift-dedicated distro"
1922
before_install:
2023
- gem install asciidoctor
2124
- gem install asciidoctor-diagram
@@ -26,6 +29,7 @@ jobs:
2629
- python3 build.py --distro openshift-dedicated --product "OpenShift Dedicated" --version 4 --no-upstream-fetch && python3 makeBuild.py
2730
- # stage name not required, will continue to use `build`
2831
if: branch IN (main, enterprise-4.11, enterprise-4.12)
32+
name: "Build openshift-rosa distro"
2933
before_install:
3034
- gem install asciidoctor
3135
- gem install asciidoctor-diagram
@@ -34,11 +38,24 @@ jobs:
3438
- pip3 install aura.tar.gz
3539
script:
3640
- python3 build.py --distro openshift-rosa --product "Red Hat OpenShift Service on AWS" --version 4 --no-upstream-fetch && python3 makeBuild.py
41+
- stage: check-with-vale
42+
if: type IN (pull_request)
43+
name: "Run Vale against PR asciidoc files"
44+
before_script:
45+
- gem install asciidoctor
46+
script:
47+
- wget https://github.com/errata-ai/vale/releases/download/v2.20.1/vale_2.20.1_Linux_64-bit.tar.gz
48+
- mkdir bin && tar -xvzf vale_2.20.1_Linux_64-bit.tar.gz -C bin
49+
- export PATH=./bin:"$PATH"
50+
- vale sync # pull down VRH rules package
51+
- chmod +x ./scripts/check-with-vale.sh
52+
- ./scripts/check-with-vale.sh $TRAVIS_PULL_REQUEST $TRAVIS_PULL_REQUEST_SHA
3753
# Commenting out to disable auto-merging of PRs
3854
# - stage: automerge
3955
# if: env(PR_AUTHOR)=openshift-cherrypick-robot
4056
# script: bash ./automerge.sh
4157

4258
stages:
4359
- build
44-
# - automerge
60+
- check-with-vale
61+
#- automerge

.vale.ini

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
StylesPath = .vale/styles
2+
3+
MinAlertLevel = error
4+
5+
Packages = RedHat
6+
7+
#ignore files in dirs starting with `.` to avoid raising errors for `.vale/fixtures/*/testinvalid.adoc` files
8+
[[!.]*.adoc]
9+
BasedOnStyles = RedHat
10+
11+
#optional: pass doc attributes to asciidoctor before linting
12+
#[asciidoctor]
13+
#openshift-enterprise = YES

scripts/check-with-vale.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# list of *.adoc files ignoring files in /rest_api and generated files
6+
FILES=$(git diff-tree HEAD HEAD~1 --no-commit-id -r --name-only "*.adoc" ':(exclude)rest_api/*' ':(exclude)modules/example-content.adoc' ':(exclude)modules/oc-adm-by-example-content.adoc')
7+
8+
if [ -n "${FILES}" ]
9+
then
10+
echo "Validating language usage in added or modified asciidoc files with $(vale -v)"
11+
echo ""
12+
echo "==============================================================================================================================="
13+
echo "Read about the error terms that cause the build to fail at https://redhat-documentation.github.io/vale-at-red-hat/docs/reference-guide/termserrors/"
14+
echo "==============================================================================================================================="
15+
echo ""
16+
#clean out conditional markup
17+
sed -i -e 's/ifdef::.*\|ifndef::.*\|ifeval::.*\|endif::.*/ /' ${FILES}
18+
vale ${FILES} --minAlertLevel=error --glob='*.adoc' --no-exit
19+
#run again, and this time send to pipedream
20+
set -x
21+
PR_DATA=''
22+
if [ "$1" == false ] ; then
23+
PR_DATA='{"PR": [{"Number": "None", "SHA": "None"}],'
24+
else
25+
PR_DATA='{"PR": [{"Number": "'"$1"'", "SHA": "'"$2"'"}]',
26+
fi
27+
echo "${PR_DATA}" > vale_errors.json
28+
ERROR_DATA=$(vale ${FILES} --minAlertLevel=error --glob='*.adoc' --output=JSON --no-exit)
29+
echo "${ERROR_DATA:1}" >> vale_errors.json
30+
curl -H "Content-Type: text/json" --data "@vale_errors.json" https://eox4isrzuh8pnai.m.pipedream.net
31+
else
32+
echo "No asciidoc files added or modified."
33+
fi

0 commit comments

Comments
 (0)