Skip to content

Add integration test coverage for PR validation #376

Add integration test coverage for PR validation

Add integration test coverage for PR validation #376

Workflow file for this run

#
# Copyright 2023 ABSA Group Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: Build and Test
on:
pull_request:
branches:
- '**'
types: [ opened, synchronize, reopened ]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
static-code-analysis:
runs-on: ubuntu-latest
name: Pylint Static Code Analysis
steps:
- name: Checkout repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: '3.13'
cache: 'pip'
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Analyze code with Pylint
id: analyze-code
run: |
pylint_score=$(pylint $(git ls-files '*.py')| grep 'rated at' | awk '{print $7}' | cut -d'/' -f1)
echo "score=$pylint_score" >> "$GITHUB_OUTPUT"
- name: Check Pylint score
run: |
score=${{ steps.analyze-code.outputs.score }}
echo "Pylint score is $score"
if (( $(echo "$score < 9.5" | bc -l) )); then
echo "Failure: Pylint score is below 9.5 (project score: $score)."
exit 1
else
echo "Success: Pylint score is above 9.5 (project score: $score)."
fi
code-format-check:
runs-on: ubuntu-latest
name: Black Format Check
steps:
- name: Checkout repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: '3.13'
cache: 'pip'
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Check code format with Black
id: check-format
run: |
black --check $(git ls-files '*.py')
unit-test:
name: Unit Tests
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: '3.13'
cache: 'pip'
- name: Install Python dependencies
run: |
pip install -r requirements.txt
- name: Set PYTHONPATH environment variable
run: echo "PYTHONPATH=${GITHUB_WORKSPACE}/release_notes_generator/release_notes_generator" >> $GITHUB_ENV
- name: Check code coverage with Pytest
run: pytest --cov=. -v tests/unit --cov-fail-under=80
mypy-check:
runs-on: ubuntu-latest
name: Mypy Type Check
steps:
- name: Checkout repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: '3.13'
cache: 'pip'
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Check types with Mypy
id: check-types
run: |
mypy .
snapshot-tests:
name: Snapshot Tests (Mocked)
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v5
with:
python-version: '3.13'
cache: 'pip'
- name: Install Python dependencies
run: |
pip install -r requirements.txt
- name: Set PYTHONPATH environment variable
run: echo "PYTHONPATH=${GITHUB_WORKSPACE}" >> $GITHUB_ENV
- name: Run all integration tests
run: pytest -v tests/integration/
integration-test-real-api:
name: Integration Test (Real GitHub API)
runs-on: ubuntu-latest
# Only run on PRs from same repo (not forks)
if: github.event.pull_request.head.repo.full_name == github.repository
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v5
with:
python-version: '3.13'
cache: 'pip'
- name: Install Python dependencies
run: |
pip install -r requirements.txt
- name: Set PYTHONPATH environment variable
run: echo "PYTHONPATH=${GITHUB_WORKSPACE}" >> $GITHUB_ENV
- name: Run action against real repository and validate output
env:
INPUT_TAG_NAME: 'v0.2.0'
INPUT_GITHUB_REPOSITORY: 'AbsaOSS/generate-release-notes'
INPUT_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
INPUT_CHAPTERS: |
[
{ title: Breaking Changes 💥, label: breaking-change },
{ title: New Features 🎉, label: enhancement },
{ title: New Features 🎉, label: feature },
{ title: Bugfixes 🛠, label: bug }
]
INPUT_WARNINGS: 'true'
INPUT_PRINT_EMPTY_CHAPTERS: 'false'
INPUT_VERBOSE: 'true'
INPUT_HIERARCHY: 'false'
INPUT_DUPLICITY_SCOPE: 'both'
INPUT_PUBLISHED_AT: 'false'
INPUT_SKIP_RELEASE_NOTES_LABELS: 'skip-release-notes'
run: |
# Run the action with verbose/debug logging
python main.py > output.txt 2>&1
exit_code=$?
# Display output for debugging
echo "=== Action Output ==="
cat output.txt
echo "=== End of Output ==="
problems=()
# Check exit code
if [ $exit_code -ne 0 ]; then
problems+=("action exit code was $exit_code")
fi
# Check for markdown chapter headers
if ! grep -qE '^### (Breaking Changes 💥|New Features 🎉|Bugfixes 🛠)' output.txt; then
problems+=("missing expected chapter headers")
fi
# Check for issue/PR references (e.g., #123)
if ! grep -qE '#[0-9]+' output.txt; then
problems+=("missing issue/PR references")
fi
# Check for developer mentions (e.g., @username)
if ! grep -qE '@[a-zA-Z0-9_-]+' output.txt; then
problems+=("missing developer mentions")
fi
# Check for completion message
if ! grep -q "completed successfully" output.txt; then
problems+=("missing completion success message")
fi
# Check for DEBUG log level (verbose mode)
if ! grep -q "DEBUG" output.txt; then
problems+=("missing DEBUG logs (verbose mode may not be working)")
fi
# Check for generated release notes block
if ! grep -q "Generated release notes:" output.txt; then
problems+=("missing 'Generated release notes:' marker")
fi
if [ ${#problems[@]} -ne 0 ]; then
echo "❌ Integration test validation failed: ${problems[*]}"
exit 1
fi