Skip to content

Commit

Permalink
Feat: readme and package checker
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekcrm committed May 30, 2023
1 parent 8eb8bc5 commit 991d172
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/actions/check-package/action.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

TARGET_FOLDERS=("python" "javascript" "typescript" )
PACKAGE_FILE="package.json"
REPO_FOLDER="$PWD"

check_json_file_syntax() {
file="$1"

if [ ! -f "$file" ]; then
echo "Error: File $file does not exist."
return 1
fi

required_fields=("name" "description" "keywords" "repository")
missing_fields=()

for field in "${required_fields[@]}"; do
if ! jq --exit-status ".$field" "$file" >/dev/null 2>&1; then
missing_fields+=("$field")
fi
done

if [ ${#missing_fields[@]} -gt 0 ]; then
file=$(echo "$file" | sed 's/\/home\/runner\/work\/platform-samples\/platform-samples//')
echo "Warning: File $file does not contain the required fields:"
for field in "${missing_fields[@]}"; do
echo "- $field"
done

return 1
fi

return 0
}



check_package_files() {
local folder=$1
find "$folder" -maxdepth 2 -type f -iname "$PACKAGE_FILE" -print0 | while IFS= read -r -d '' file; do
check_json_file_syntax "$file"
done
}


check_package_files_in_folders() {
for folder in "${TARGET_FOLDERS[@]}"; do
folder_path="$REPO_FOLDER/$folder"
if [ -d "$folder_path" ]; then
check_package_files "$folder_path"
else
echo "Folder $folder not found in repo"
fi
done
}


check_package_files_in_folders
10 changes: 10 additions & 0 deletions .github/actions/check-package/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: 'Check package'
description: 'Check packaeg for specific fields'

runs:
using: 'composite'
steps:
- name: Check
run: bash ./.github/actions/check-package/action.sh
shell: bash

38 changes: 38 additions & 0 deletions .github/actions/check-readme/action.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

TARGET_FOLDERS=("python" "javascript" "typescript" )
README_FILE="README.md"
REPO_FOLDER="$PWD"

check_readme_syntax() {
content=$(cat "$file")
if [[ $content == *"#"* && $content != *"___"* ]]; then

file=$(echo "$file" | sed 's/\/home\/runner\/work\/platform-samples\/platform-samples//')
echo "Warning: syntax errorn in $file"
echo "You need to add a section that starts with # and ends with ___"
fi

}

check_readme_files() {
local folder=$1
find "$folder" -maxdepth 2 -type f -iname "$README_FILE" -print0 | while IFS= read -r -d '' file; do
check_readme_syntax "$file"
done
}


check_readme_files_in_folders() {
for folder in "${TARGET_FOLDERS[@]}"; do
folder_path="$REPO_FOLDER/$folder"
if [ -d "$folder_path" ]; then
check_readme_files "$folder_path"
else
echo "Folder $folder not found in repo"
fi
done
}

check_readme_files_in_folders

10 changes: 10 additions & 0 deletions .github/actions/check-readme/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: 'Check readme'
description: 'Check readme for # <content> ___ '

runs:
using: 'composite'
steps:
- name: Check
run: bash ./.github/actions/check-readme/action.sh
shell: bash

21 changes: 21 additions & 0 deletions .github/workflows/main-check-syntax.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Check readme files & packages in sequences"

on:
push:
branches:
- feat/check-readme

jobs:
check-syntax:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Check readme files
uses: ./.github/actions/check-readme

- name: Check packages files
uses: ./.github/actions/check-package



0 comments on commit 991d172

Please sign in to comment.