diff --git a/.github/workflows/data_tests.yml b/.github/workflows/data_tests.yml
index d3f2938..42bca84 100644
--- a/.github/workflows/data_tests.yml
+++ b/.github/workflows/data_tests.yml
@@ -29,7 +29,7 @@ jobs:
uses: actions/checkout@v3
with:
repository: openelections/openelections-data-tests
- ref: v2.1.0
+ ref: v2.2.0
path: data_tests
- name: Run data tests
diff --git a/.github/workflows/data_tests_changed_files.yml b/.github/workflows/data_tests_changed_files.yml
new file mode 100644
index 0000000..285269b
--- /dev/null
+++ b/.github/workflows/data_tests_changed_files.yml
@@ -0,0 +1,65 @@
+name: Data Tests (Changed Files)
+
+on:
+ pull_request:
+
+jobs:
+ data_tests:
+ name: Data tests
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ test: [duplicate_entries, file_format, missing_values, vote_breakdown_totals]
+
+ env:
+ LOG_FILE: ${{ github.workspace }}/${{ matrix.test }}.txt
+
+ steps:
+ - name: Save the pull request number in an artifact
+ shell: bash
+ run: echo ${{ github.event.number }} > pull_request_number.txt
+
+ - name: Set up Python
+ uses: actions/setup-python@v4
+ with:
+ python-version: 3.x
+
+ - name: Check out data
+ uses: actions/checkout@v3
+ with:
+ path: data
+ fetch-depth: 0
+
+ - name: Check out data tests
+ uses: actions/checkout@v3
+ with:
+ repository: openelections/openelections-data-tests
+ ref: v2.2.0
+ path: data_tests
+
+ - name: Get changed *.csv files
+ id: changed-files
+ uses: tj-actions/changed-files@v35
+ with:
+ path: data
+ files: |
+ **/*.csv
+
+ - name: Run data tests
+ if: "${{ steps.changed-files.outputs.added_files != '' }}"
+ run: python3 ${{ github.workspace }}/data_tests/run_tests.py --files ${{ steps.changed-files.outputs.added_files }} --group-failures --log-file=${{ env.LOG_FILE }} --truncate-log-file ${{ matrix.test }} ${{ github.workspace }}/data
+
+ - name: Upload the pull request number
+ uses: actions/upload-artifact@v3
+ if: failure()
+ with:
+ name: pull_request_number
+ path: ./pull_request_number.txt
+
+ - name: Upload error logs
+ uses: actions/upload-artifact@v3
+ if: failure()
+ with:
+ name: ${{ matrix.test }}
+ path: ${{ env.LOG_FILE }}
diff --git a/.github/workflows/pull_request_comment.yml b/.github/workflows/pull_request_comment.yml
new file mode 100644
index 0000000..9da0e37
--- /dev/null
+++ b/.github/workflows/pull_request_comment.yml
@@ -0,0 +1,56 @@
+name: Comment on Pull Request
+
+on:
+ workflow_run:
+ workflows: [Data Tests (Changed Files)]
+ types:
+ - completed
+
+jobs:
+ comment:
+ name: Comment on pull request
+ runs-on: ubuntu-latest
+ if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure'
+ strategy:
+ fail-fast: false
+ matrix:
+ test: [duplicate_entries, file_format, missing_values, vote_breakdown_totals]
+
+ steps:
+ - name: Download artifacts
+ uses: dawidd6/action-download-artifact@v2
+ with:
+ run_id: ${{ github.event.workflow_run.id }}
+
+ - name: Read pull request number
+ id: pull_request_number_reader
+ uses: juliangruber/read-file-action@v1
+ with:
+ path: ./pull_request_number/pull_request_number.txt
+
+ - name: Check for failures
+ id: check_failures
+ uses: andstor/file-existence-action@v2
+ with:
+ files: ./${{ matrix.test }}/${{ matrix.test }}.txt
+
+ - name: Read failure logs
+ if: steps.check_failures.outputs.files_exists == 'true'
+ id: failure_reader
+ uses: juliangruber/read-file-action@v1
+ with:
+ path: ./${{ matrix.test }}/${{ matrix.test }}.txt
+
+ - name: Comment on pull request
+ if: steps.check_failures.outputs.files_exists == 'true'
+ uses: actions/github-script@v6
+ with:
+ script: |
+ await github.rest.issues.createComment({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: ${{ steps.pull_request_number_reader.outputs.content }},
+ body: `Thank you for your contribution! Our ${{ matrix.test }}
`+
+ `test detected some potential issues in the files you added.\n\n`+
+ `
${{ steps.failure_reader.outputs.content }}
`
+ });