Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
mirnawong1 committed Jun 17, 2024
1 parent 1c20c18 commit 2e7be86
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions .github/workflows/vale.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint and suggest
name: Lint and Suggest

on:
pull_request:
Expand All @@ -10,48 +10,45 @@ permissions:
pull-requests: write

jobs:
vale: # Vale linting job
vale:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history so we can access all commits
fetch-depth: 0

- name: Install Vale
uses: errata-ai/vale-action@v2

- name: Install jq
run: sudo apt-get install -y jq
with:
version: latest

- name: Get changed files
id: changed-files
run: |
BASE_SHA=$(git merge-base origin/${{ github.event.pull_request.base.ref }} ${{ github.sha }})
CHANGED_FILES=$(git diff --name-only $BASE_SHA ${{ github.sha }} -- '*.md')
echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV
echo "CHANGED_FILES=$(echo $CHANGED_FILES | jq -R -s -c 'split(\"\n\")[:-1]')" >> $GITHUB_ENV
echo "::set-output name=files::$(echo $CHANGED_FILES | jq -R -s -c 'split(\"\\n\")[:-1]')"
- name: Print Changed Files
run: echo $CHANGED_FILES

- name: Run Vale on changed files
run: |
for file in ${{ env.CHANGED_FILES }}; do
for file in $(echo ${{ steps.changed-files.outputs.files }} | jq -r '.[]'); do
echo "Running Vale on $file"
vale --output=JSON $file > "vale_output_${file//\//_}.json"
vale --output=edit $file > "vale_output_${file//\//_}_edit.md"
vale --output=JSON "$file" > "vale_output_${file//\//_}.json"
done
echo "Vale outputs:"
ls -l
- name: Simulate Vale changes
- name: Apply Vale suggestions
run: |
mkdir -p simulated_changes
mkdir -p suggested_changes
for file in $(echo ${{ steps.changed-files.outputs.files }} | jq -r '.[]'); do
cp "$file" "simulated_changes/$(basename "$file")"
vale --output=edit "simulated_changes/$(basename "$file")"
vale --output=line "$file" | grep -oP 'Consider changing.*' > suggested_changes/"$(basename "$file")".suggestions
done
- name: Upload Vale results
Expand All @@ -60,27 +57,27 @@ jobs:
name: vale-results
path: '*.json'

- name: Upload simulated changes
- name: Upload suggested changes
uses: actions/upload-artifact@v3
with:
name: simulated-changes
path: simulated_changes
name: suggested-changes
path: suggested_changes/

suggest:
runs-on: ubuntu-latest
needs: vale # This ensures the suggest job runs after the vale job
needs: vale

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Download simulated changes
- name: Download suggested changes
uses: actions/download-artifact@v3
with:
name: simulated-changes
name: suggested-changes

- name: List downloaded files
run: ls -l simulated_changes
run: ls -l suggested_changes

- name: Suggest changes
uses: parkerbxyz/suggest-changes@v1
Expand Down

0 comments on commit 2e7be86

Please sign in to comment.