Skip to content

Commit 89ed51a

Browse files
committed
Added Vale check action for CI testing(DO NOT MERGE)
1 parent 7ecde15 commit 89ed51a

File tree

5 files changed

+489
-9
lines changed

5 files changed

+489
-9
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
name: Lint with Vale on pull requests
3+
on:
4+
pull_request:
5+
paths:
6+
- "**.adoc"
7+
- "**.md"
8+
- content/learn/**
9+
- content/patterns/**
10+
- content/contribute/**
11+
- modules/**
12+
jobs:
13+
vale-lint:
14+
name: Linting with Vale
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
pull-requests: write
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v5
22+
with:
23+
fetch-depth: 3
24+
- name: Install dependencies
25+
run: >
26+
sudo DEBIAN_FRONTEND=noninteractive apt-get update
27+
28+
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends --no-upgrade asciidoctor jq
29+
- name: Install Vale
30+
run: >
31+
wget -O vale.tar.gz
32+
https://github.com/errata-ai/vale/releases/download/v3.12.0/vale_3.12.0_Linux_64-bit.tar.gz
33+
34+
tar -xzf vale.tar.gz
35+
36+
sudo mv vale /usr/local/bin/
37+
38+
vale --version
39+
- name: Run Vale linting script
40+
env:
41+
GITHUB_REPOSITORY: ${{ github.repository }}
42+
PR_NUMBER: ${{ github.event.pull_request.number }}
43+
run: >
44+
set +e
45+
46+
./.github/workflows/scripts/lintwithvale.sh \
47+
"${{ github.event.pull_request.base.sha }}" \
48+
"${{ github.event.pull_request.head.sha }}" || {
49+
echo "⚠️ Vale linting script encountered an error, but workflow will continue."
50+
}
51+
52+
exit 0
53+
- name: Prepare and post/update PR comment
54+
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.VALE_GITHUB_TOKEN }}
57+
REPO: ${{ github.repository }}
58+
PR_NUMBER: ${{ github.event.pull_request.number }}
59+
BOT_USERNAME: ocpdocs-previewbot
60+
run: |
61+
set -e
62+
echo "Reading summary JSON..."
63+
if [ ! -f vale_summary.json ]; then
64+
echo "No vale_summary.json produced; skipping comment."
65+
exit 0
66+
fi
67+
cat vale_summary.json
68+
HAS_ERRORS=$(jq -r '.has_errors' vale_summary.json)
69+
ERROR_COUNT=$(jq -r '.error_count' vale_summary.json)
70+
71+
# Find existing comment id (authored by bot and heading match)
72+
EXISTING_ID=$(curl -s -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
73+
"https://api.github.com/repos/$REPO/issues/$PR_NUMBER/comments?per_page=100" | \
74+
jq -r --arg bot "$BOT_USERNAME" '[.[] | select(.user.login==$bot) | select(.body | startswith("### 📝 Vale Linting Results"))][0].id')
75+
echo "Existing comment id: ${EXISTING_ID:-none}"
76+
77+
if [ "$HAS_ERRORS" = "true" ]; then
78+
if [ -n "$EXISTING_ID" ] && [ "$EXISTING_ID" != "null" ]; then
79+
COMMENT_FILE=vale_comment_errors_updated.md
80+
else
81+
COMMENT_FILE=vale_comment_errors_new.md
82+
fi
83+
if [ ! -f "$COMMENT_FILE" ]; then
84+
echo "Expected $COMMENT_FILE not found; skipping."; exit 0
85+
fi
86+
BODY=$(jq -Rs . < "$COMMENT_FILE")
87+
if [ -n "$EXISTING_ID" ] && [ "$EXISTING_ID" != "null" ]; then
88+
echo "Updating existing Vale comment with $ERROR_COUNT errors"
89+
curl -s -X PATCH \
90+
-H "Authorization: token $GITHUB_TOKEN" \
91+
-H "Accept: application/vnd.github.v3+json" \
92+
-H "Content-Type: application/json" \
93+
-d "{\"body\": $BODY}" \
94+
"https://api.github.com/repos/$REPO/issues/comments/$EXISTING_ID" > /dev/null || true
95+
else
96+
echo "Creating new Vale comment with $ERROR_COUNT errors"
97+
curl -s -X POST \
98+
-H "Authorization: token $GITHUB_TOKEN" \
99+
-H "Accept: application/vnd.github.v3+json" \
100+
-H "Content-Type: application/json" \
101+
-d "{\"body\": $BODY}" \
102+
"https://api.github.com/repos/$REPO/issues/$PR_NUMBER/comments" > /dev/null || true
103+
fi
104+
else
105+
# No errors: only update an existing comment if present
106+
if [ -n "$EXISTING_ID" ] && [ "$EXISTING_ID" != "null" ]; then
107+
if [ -f vale_comment_clean_updated.md ]; then
108+
BODY=$(jq -Rs . < vale_comment_clean_updated.md)
109+
echo "Updating existing Vale comment to clean state"
110+
curl -s -X PATCH \
111+
-H "Authorization: token $GITHUB_TOKEN" \
112+
-H "Accept: application/vnd.github.v3+json" \
113+
-H "Content-Type: application/json" \
114+
-d "{\"body\": $BODY}" \
115+
"https://api.github.com/repos/$REPO/issues/comments/$EXISTING_ID" > /dev/null || true
116+
else
117+
echo "Clean updated comment file missing; skipping update."
118+
fi
119+
else
120+
echo "No existing comment and no errors => skipping comment creation (per requirements)."
121+
fi
122+
fi
123+
- name: Workflow summary
124+
if: always()
125+
run: >
126+
echo "✅ Vale linting workflow completed"
127+
128+
echo "📋 This workflow is configured to always pass, regardless of linting results"
129+
130+
echo "🔍 Check the previous step logs for Vale linting details"
131+
132+
echo "💬 For PR comment see earlier steps."

0 commit comments

Comments
 (0)