Skip to content

update actions

update actions #34

Workflow file for this run

name: Check Typos in Pull Request
on: [pull_request]
jobs:
check-typos:
permissions: write-all
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Set up Python
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.14.0-alpha.1'
# Step 3: Install the typos checker
- name: Install typos
run: |
python3 -m pip install --upgrade pip
pip install typos
# Step 4: Get the list of changed files
- name: Get changed files
id: changed-files
run: |
set -e
echo "Listing changed files..."
git fetch --all
base_commit=$(git rev-parse origin/${{ github.base_ref }})
current_commit=$(git rev-parse HEAD)
echo "Base commit: $base_commit"
echo "Current commit: $current_commit"
changed_files=$(git diff --name-only $base_commit $current_commit || true)
echo "Changed files: $changed_files"
if [ -z "$changed_files" ]; then
echo "CHANGED_FILES=false" >> $GITHUB_ENV
else
echo "CHANGED_FILES=true" >> $GITHUB_ENV
echo "$changed_files" | tr ' ' '\n' > changed_files.txt
echo "CHANGED_FILE_LIST=changed_files.txt" >> $GITHUB_ENV
fi
# Step 5: Check if files have changed
- name: Check if files have changed
id: check-files
run: |
if [ "${{ env.CHANGED_FILES }}" == "true" ]; then
echo "Files have changed."
echo "RUN_SCRIPTS=true" >> $GITHUB_ENV
else
echo "No files changed."
echo "RUN_SCRIPTS=false" >> $GITHUB_ENV
fi
- name: Set up Node.js
uses: actions/setup-node@v3
with:

Check failure on line 65 in .github/workflows/typos-check.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/typos-check.yml

Invalid workflow file

You have an error in your yaml syntax on line 65
node-version: '18
- name: Check typos in changed files and comment on PR
if: ${{ env.RUN_SCRIPTS == 'true' }}
run: |
set -e
echo "Checking typos in changed files..."
# Loop through each changed file
while IFS= read -r file; do
echo "Checking typos in $file"
# Run typos checker and capture output, including errors
typos_output=$(typos "$file" --format brief 2>&1) || true
# Check if typos output exists
if [[ -n "$typos_output" ]]; then
echo "Typos found in $file:"
echo "$typos_output"
# Parse the typos output line by line
while IFS= read -r line; do
echo "line: $line"
if [[ $line =~ ^(.*):([0-9]+):([0-9]+):\ \`([^\`]+)\`\ \-\>\ \`([^\`]+)\`$ ]]; then
file_path="${BASH_REMATCH[1]}"
line_number="${BASH_REMATCH[2]}"
char_index="${BASH_REMATCH[3]}"
typo="${BASH_REMATCH[4]}"
suggestion="${BASH_REMATCH[5]}"
# Pass environment variables to Node.js script
echo "Commenting on PR for typo in file $file_path, line $line_number"
echo "Typo: $typo, Suggestion: $suggestion"
# Run the Node.js script with the environment variables
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
OWNER=${{ github.repository_owner }}
REPO=${{ github.repository }}
PULL_NUMBER=${{ github.event.pull_request.number }}
COMMIT_ID=${{ github.sha }}
BODY="hihi"
PATH="$file_path"
POSITION="$line_number"
COMMENT="$suggestion"
node request-review.js GITHUB_TOKEN OWNER REPO PULL_NUMBER COMMIT_ID BODY PATH POSITION COMMENT
fi
done <<< "$typos_output"
else
echo "No typos found in $file."
fi
done < ${{ env.CHANGED_FILE_LIST }}