diff --git a/.github/workflows/main-tests.yml b/.github/workflows/main-tests.yml new file mode 100644 index 00000000..8153e219 --- /dev/null +++ b/.github/workflows/main-tests.yml @@ -0,0 +1,67 @@ +name: Main Tests + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + test-commits: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Create test list file + run: echo "isaacs/github" > test_list.txt + + - name: Run main.py and save output (commits) + run: python main.py --commits -l test_list.txt -o output_commits.csv -t ${{ secrets.GITHUB_TOKEN }} + - name: Compare output with reference CSV (commits) + run: | + if [ ! -f output_commits.csv ]; then + echo 'output_commits.csv not found, skipping compare.' + exit 1 + fi + python compare_csv.py output_commits.csv .github/workflows/reference_commits.csv + + - name: Run main.py and save output (contributors) + run: python main.py --contributors -l test_list.txt -o output_contributors.csv -t ${{ secrets.GITHUB_TOKEN }} + - name: Compare output with reference CSV (contributors) + run: | + if [ ! -f output_contributors.csv ]; then + echo 'output_contributors.csv not found, skipping compare.' + exit 1 + fi + python compare_csv.py output_contributors.csv .github/workflows/reference_contributors.csv + + - name: Run main.py and save output (issues) + run: python main.py --issues -l test_list.txt -o output_issues.csv -t ${{ secrets.GITHUB_TOKEN }} + - name: Compare output with reference CSV (issues) + run: | + if [ ! -f output_issues.csv ]; then + echo 'output_issues.csv not found, skipping compare.' + exit 1 + fi + python compare_csv.py output_issues.csv .github/workflows/reference_issues.csv + + - name: Run main.py and save output (pulls) + run: python main.py -p -l test_list.txt -o output_pulls.csv -t ${{ secrets.GITHUB_TOKEN }} + - name: Compare output with reference CSV (pulls) + run: | + if [ ! -f output_pulls.csv ]; then + echo 'output_pulls.csv not found, skipping compare.' + exit 1 + fi + python compare_csv.py output_pulls.csv .github/workflows/reference_pulls.csv + diff --git a/compare_csv.py b/compare_csv.py new file mode 100644 index 00000000..c999f222 --- /dev/null +++ b/compare_csv.py @@ -0,0 +1,43 @@ +import csv +import sys + + +def compare_csv_files(actual_path, expected_path): + with open(actual_path, newline='', encoding='utf-8') as actual_file, \ + open(expected_path, newline='', encoding='utf-8') as expected_file: + actual_reader = csv.DictReader(actual_file) + expected_reader = csv.DictReader(expected_file) + + actual_rows = list(actual_reader) + expected_rows = list(expected_reader) + + common_fields = set(actual_reader.fieldnames) & set(expected_reader.fieldnames) + if not common_fields: + print('Нет общих столбцов для сравнения!') + sys.exit(1) + + def rows_to_set(rows): + return set(tuple(row[field] for field in sorted(common_fields)) for row in rows) + + actual_set = rows_to_set(actual_rows) + expected_set = rows_to_set(expected_rows) + + if actual_set != expected_set: + print('Файлы отличаются по общим столбцам:') + print('Только в output.csv:') + for row in actual_set - expected_set: + print(row) + print('Только в reference.csv:') + for row in expected_set - actual_set: + print(row) + sys.exit(1) + else: + print('Файлы совпадают по общим столбцам.') + + +if __name__ == "__main__": + if len(sys.argv) != 3: + print(f"Usage: python {sys.argv[0]} ") + sys.exit(1) + compare_csv_files(sys.argv[1], sys.argv[2]) +