Test Councils #2510
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test Councils | |
on: | |
workflow_dispatch: | |
push: | |
paths-ignore: | |
- "wiki/**" | |
- "**/*.md" | |
- "uk_bin_collection_api_server/**" | |
branches: [ "master" ] | |
pull_request: | |
paths-ignore: | |
- "wiki/**" | |
- "**/*.md" | |
- "uk_bin_collection_api_server/**" | |
branches: [ "master" ] | |
schedule: | |
- cron: '0 0 * * *' # Nightly schedule for full test run | |
jobs: | |
setup: | |
name: Setup Environment | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Poetry | |
run: pipx install poetry==1.8.4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: 3.12 | |
- name: Install Dependencies | |
run: make install-dev | |
- name: Lint JSON | |
run: jq empty uk_bin_collection/tests/input.json | |
- name: Get All Council Files That Have Changed | |
id: changed-council-files | |
uses: tj-actions/changed-files@v45 | |
with: | |
files: | | |
uk_bin_collection/uk_bin_collection/councils/**.py | |
- name: Set Council Tests Environment Variable | |
id: set-council-tests | |
run: | | |
IFS=' ' read -ra FILES <<< "${{ steps.changed-council-files.outputs.all_changed_files }}" | |
COUNCIL_TESTS="" | |
for file in "${FILES[@]}"; do | |
FILENAME=$(basename "$file" .py) | |
if [ -z "$COUNCIL_TESTS" ]; then | |
COUNCIL_TESTS="$FILENAME" | |
else | |
COUNCIL_TESTS="$COUNCIL_TESTS or $FILENAME" | |
fi | |
done | |
echo "council_tests=$COUNCIL_TESTS" >> $GITHUB_OUTPUT | |
outputs: | |
council_tests: ${{ steps.set-council-tests.outputs.council_tests }} | |
unit-tests: | |
name: Run Unit Tests | |
needs: setup | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: [3.12] | |
poetry-version: [1.8.4] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install Poetry | |
run: pipx install poetry==${{ matrix.poetry-version }} | |
- name: Install Dependencies | |
run: make install-dev | |
- name: Run Unit Tests | |
run: make unit-tests | |
- name: Upload Test Results to Codecov | |
uses: codecov/codecov-action@v5 | |
with: | |
fail_ci_if_error: false | |
token: ${{ secrets.CODECOV_TOKEN }} | |
file: coverage.xml | |
parity-check: | |
name: Parity Check | |
needs: setup | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: [3.12] | |
poetry-version: [1.8.4] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install Poetry | |
run: pipx install poetry==${{ matrix.poetry-version }} | |
- name: Install Dependencies | |
run: make install-dev | |
- name: Check Parity of Councils / input.json / Feature file | |
run: | | |
repo=${{ github.event.pull_request.head.repo.full_name || 'robbrad/UKBinCollectionData' }} | |
branch=${{ github.event.pull_request.head.ref || 'master' }} | |
make parity-check repo=$repo branch=$branch | |
integration-tests: | |
name: Run Integration Tests | |
needs: setup | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: [3.12] | |
poetry-version: [1.8.4] | |
services: | |
selenium: | |
image: selenium/standalone-chrome:latest | |
options: --shm-size=2gb --name selenium --hostname selenium | |
ports: | |
- 4444:4444 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install Poetry | |
run: pipx install poetry==${{ matrix.poetry-version }} | |
- name: Install Dependencies | |
run: make install-dev | |
- name: Run Integration Tests | |
env: | |
HEADLESS: True | |
COUNCIL_TESTS: ${{ needs.setup.outputs.council_tests }} | |
run: make matrix=${{ matrix.python-version }} councils="${{ env.COUNCIL_TESTS }}" integration-tests | |
continue-on-error: true | |
report: | |
name: Generate and Upload Reports | |
needs: [unit-tests, parity-check, integration-tests] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: [3.12] | |
steps: | |
- uses: actions/checkout@v4 | |
# Fetch existing gh-pages to preserve history if on master branch and it's a push or schedule | |
- name: Get Existing History | |
if: github.ref == 'refs/heads/master' && (github.event_name == 'push' || github.event_name == 'schedule') | |
uses: actions/checkout@v4 | |
with: | |
ref: gh-pages | |
path: allure-history | |
continue-on-error: true | |
# If PR doesn't need existing history, we can skip fetching. If you do want partial history across PRs, | |
# you could add another condition for pull_request here. | |
# Generate Full Run Allure Reports (push/schedule on master) | |
- name: Allure report action for Full Run | |
if: (github.event_name == 'push' || github.event_name == 'schedule') && github.ref == 'refs/heads/master' | |
uses: simple-elf/allure-report-action@master | |
with: | |
allure_results: build/${{ matrix.python-version }}/allure-results | |
subfolder: ${{ matrix.python-version }} | |
allure_history: allure-history/full | |
keep_reports: 20 | |
# Generate Partial Run Allure Reports (pull_request) | |
- name: Allure report action for Partial Run | |
if: github.event_name == 'pull_request' | |
uses: simple-elf/allure-report-action@master | |
with: | |
allure_results: build/${{ matrix.python-version }}/allure-results | |
subfolder: ${{ matrix.python-version }} | |
allure_history: allure-history/partial | |
keep_reports: 20 | |
# Archive Full Reports | |
- name: Tar full report | |
if: (github.event_name == 'push' || github.event_name == 'schedule') && github.ref == 'refs/heads/master' | |
run: tar -cvf allure_full_history_${{ matrix.python-version }}.tar allure-history/full/${{ matrix.python-version }} | |
# Archive Partial Reports | |
- name: Tar partial report | |
if: github.event_name == 'pull_request' | |
run: tar -cvf allure_partial_history_${{ matrix.python-version }}.tar allure-history/partial/${{ matrix.python-version }} | |
# Upload artifacts | |
- name: Upload artifact for Full Report | |
if: (github.event_name == 'push' || github.event_name == 'schedule') && github.ref == 'refs/heads/master' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: allure_full_history_${{ matrix.python-version }} | |
path: allure_full_history_${{ matrix.python-version }}.tar | |
- name: Upload artifact for Partial Report | |
if: github.event_name == 'pull_request' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: allure_partial_history_${{ matrix.python-version }} | |
path: allure_partial_history_${{ matrix.python-version }}.tar | |
deploy: | |
name: Deploy Reports | |
runs-on: ubuntu-latest | |
needs: report | |
if: github.ref == 'refs/heads/master' | |
steps: | |
# Download Full Artifacts (push/schedule) | |
- uses: actions/download-artifact@v4 | |
name: Download Full Artifacts | |
if: github.event_name == 'push' || github.event_name == 'schedule' | |
with: | |
name: allure_full_history_3.12 | |
path: allure-history/tars/full | |
# Download Partial Artifacts (pull_request) | |
- uses: actions/download-artifact@v4 | |
name: Download Partial Artifacts | |
if: github.event_name == 'pull_request' | |
with: | |
name: allure_partial_history_3.12 | |
path: allure-history/tars/partial | |
# Create directories if needed | |
- name: Create Full / Partial dirs | |
run: | | |
mkdir -p allure-history/full allure-history/partial | |
# Untar Full Reports | |
- name: Untar Full Reports | |
if: github.event_name == 'push' || github.event_name == 'schedule' | |
run: | | |
shopt -s nullglob | |
for i in allure-history/tars/full/*.tar; do tar -xvf "$i" -C allure-history/full; done | |
# Untar Partial Reports | |
- name: Untar Partial Reports | |
if: github.event_name == 'pull_request' | |
run: | | |
shopt -s nullglob | |
for i in allure-history/tars/partial/*.tar; do tar -xvf "$i" -C allure-history/partial; done | |
# Remove Tar Reports | |
- name: Remove Tar Reports | |
run: rm -rf allure-history/tars | |
# Ensure not empty | |
- name: Ensure not empty | |
run: | | |
if [ ! "$(ls -A allure-history)" ]; then | |
touch allure-history/.placeholder | |
fi | |
# Deploy everything to gh-pages | |
- name: Deploy | |
uses: peaceiris/actions-gh-pages@v4 | |
with: | |
personal_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_branch: gh-pages | |
publish_dir: allure-history |