Rebased Teams extension. #464
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: Tests | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
types: | |
- opened | |
- ready_for_review | |
- reopened | |
- synchronize | |
workflow_call: | |
jobs: | |
test_package: | |
name: Tests | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
architecture: x64 | |
cache: pip | |
cache-dependency-path: "**/pyproject.toml" | |
- name: Install Poetry | |
run: | | |
pip install poetry | |
- name: Install dependencies | |
run: | | |
poetry install | |
- name: Get coverage artifact ID | |
id: coverage-artifact | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const workflows = await github.rest.actions.listRepoWorkflows({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
const workflowId = workflows.data.workflows.find(workflow => workflow.name === "${{ github.workflow }}")?.id; | |
if (!workflowId) return ""; | |
const workflowRuns = await github.rest.actions.listWorkflowRuns({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: workflowId, | |
branch: "${{ github.base_ref }}", | |
event: "push", | |
status: "success", | |
}); | |
return workflowRuns.data.workflow_runs[0]?.id ?? ""; | |
result-encoding: string | |
retries: 3 | |
- name: Download main coverage artifact | |
uses: actions/download-artifact@v4 | |
if: steps.coverage-artifact.outputs.result != '' | |
continue-on-error: true # There is a chance that the artifact doesn't exist, or has expired | |
with: | |
name: coverage | |
path: "${{ github.workspace }}/coverage-main" | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
run-id: ${{ steps.coverage-artifact.outputs.result }} | |
- name: Get coverage from main | |
id: coverage-value | |
run: | | |
MIN_COVERAGE=0 | |
if [[ -f "./coverage-main/coverage.xml" ]]; then | |
MIN_COVERAGE=$(grep -m 1 "<coverage" "./coverage-main/coverage.xml" | sed -E 's/.*line-rate="([^"]*)".*/\1/') # Extract the line rate from the XML | |
MIN_COVERAGE=$(awk "BEGIN {print int($MIN_COVERAGE * 100)}") # Turn into percentage, rounding down to avoid rounding issues | |
fi | |
echo "MIN_COVERAGE=$MIN_COVERAGE" >> "$GITHUB_OUTPUT" | |
- name: Run Unit tests | |
run: poetry run pytest -m "not azure and not functional" --junitxml=coverage-junit.xml --cov=. --cov-report xml:coverage.xml --cov-fail-under ${{ steps.coverage-value.outputs.MIN_COVERAGE }} | |
- uses: actions/upload-artifact@v4 | |
if: ${{ !cancelled() }} | |
with: | |
name: coverage | |
path: | | |
coverage-junit.xml | |
coverage.xml | |
if-no-files-found: error | |
- name: Run Functional tests | |
run: poetry run pytest -m "functional" |