diff --git a/.github/actions/check-package/action.sh b/.github/actions/check-package/action.sh new file mode 100644 index 0000000..0268eb9 --- /dev/null +++ b/.github/actions/check-package/action.sh @@ -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 diff --git a/.github/actions/check-package/action.yml b/.github/actions/check-package/action.yml new file mode 100644 index 0000000..3362b1e --- /dev/null +++ b/.github/actions/check-package/action.yml @@ -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 + diff --git a/.github/actions/check-readme/action.sh b/.github/actions/check-readme/action.sh new file mode 100644 index 0000000..bdb8bb6 --- /dev/null +++ b/.github/actions/check-readme/action.sh @@ -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 + diff --git a/.github/actions/check-readme/action.yml b/.github/actions/check-readme/action.yml new file mode 100644 index 0000000..4c241af --- /dev/null +++ b/.github/actions/check-readme/action.yml @@ -0,0 +1,10 @@ +name: 'Check readme' +description: 'Check readme for # ___ ' + +runs: + using: 'composite' + steps: + - name: Check + run: bash ./.github/actions/check-readme/action.sh + shell: bash + diff --git a/.github/workflows/main-check-syntax.yml b/.github/workflows/main-check-syntax.yml new file mode 100644 index 0000000..a295c75 --- /dev/null +++ b/.github/workflows/main-check-syntax.yml @@ -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 + + +