1- # This is a github actions workflow that retrieves the modified hips and runs a validator script against them written in Node.
21name : Validate HIP
3- on : [pull_request]
2+
3+ on :
4+ pull_request :
45
56permissions :
67 contents : read
@@ -26,26 +27,25 @@ jobs:
2627 - name : Use Node.js
2728 uses : actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
2829 with :
29- node-version : " 12.x "
30+ node-version : " 20 "
3031
31- - name : Install jq
32- run : sudo apt-get install jq
32+ - name : Test HIP validator
33+ run : npm test
3334
3435 - name : Validate HIPs
3536 env :
36- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
37- VERTESIA_API_KEY : ${{ secrets.VERTESIA_API_KEY }}
37+ BASE_SHA : ${{ github.event.pull_request.base.sha }}
3838 run : |
39- PR_NUMBER=${{ github.event.pull_request.number }}
40- REPO=${{ github.repository }}
41- PR_DATA=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$REPO/pulls/$PR_NUMBER/files" )
42- MD_FILES=$(echo "$PR_DATA" | jq -r '.[] | select(.filename | test(".md$")) | select(.status != "removed") | .filename')
43-
44- for FILE in $MD_FILES; do
45- FULL_PATH="${{ github.workspace }}/$FILE"
46- if [[ -f "$FULL_PATH" ]] ; then
47- node "${{ github.workspace }}/scripts/validateHIP.js" "$FULL_PATH "
48- else
49- echo "Skipping $FILE (not found on disk)"
50- fi
51- done
39+ git cat-file -e "${BASE_SHA}^{commit}"
40+
41+ HIP_FILES=( )
42+ while IFS= read -r -d '' FILE; do
43+ HIP_FILES+=("$FILE")
44+ done < <(git diff --name-only --diff-filter=ACMR -z "$BASE_SHA" -- ':(glob)HIP/*.md')
45+
46+ if (( ${#HIP_FILES[@]} == 0 )) ; then
47+ echo "No added or modified HIP files to validate. "
48+ exit 0
49+ fi
50+
51+ node scripts/validateHIP.js --base-ref "$BASE_SHA" "${HIP_FILES[@]}"
0 commit comments