ISSUE-21: Refactor tests checking output #104
Workflow file for this run
This file contains hidden or 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: Typecheck & run tests | |
on: | |
push: | |
branches: | |
- 'main' | |
- 'feature/*' | |
- 'bugfix/*' | |
issue_comment: | |
types: [created] | |
jobs: | |
get-main-ref: | |
runs-on: ubuntu-latest | |
name: Get ref to check out (based on branch or PR) | |
# permissions: | |
# checks: write | |
steps: | |
- name: Get PR's branch name | |
id: from-pr | |
if: ${{ contains(github.event.comment.html_url, '/pull/') }} | |
run: | | |
PR=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" ${{ github.event.issue.pull_request.url }}) | |
echo "branch=$(echo $PR | jq -r '.head.ref')" >> "$GITHUB_OUTPUT" | |
echo "onPR=true" >> "$GITHUB_OUTPUT" | |
- name: Get current branch name | |
id: from-branch | |
if: ${{ !contains(github.event.comment.html_url, '/pull/') }} | |
run: | | |
echo "branch=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT" | |
echo "onPR=false" >> "$GITHUB_OUTPUT" | |
outputs: | |
branch: ${{ steps.from-pr.outputs.branch || steps.from-branch.outputs.branch }} | |
onPR: ${{ steps.from-pr.outputs.onPR || steps.from-branch.outputs.onPR }} | |
# wip: | |
# runs-on: ubuntu-latest | |
# name: WIP | |
# needs: [get-main-ref] | |
# permissions: | |
# checks: read | |
# env: | |
# GH_TOKEN: ${{ github.token }} | |
# steps: | |
# - name: print body | |
# run: | | |
# gh api \ | |
# -H "Accept: application/vnd.github+json" \ | |
# -H "X-GitHub-Api-Version: 2022-11-28" \ | |
# /repos/ShellMagick/commit-hooks/commits/${{ needs.get-main-ref.outputs.branch }}/check-suites > response.json | |
# cat response.json | |
coverage: | |
runs-on: ubuntu-latest | |
name: Run tests on lowest supported Python version on Ubuntu | |
needs: [get-main-ref] | |
steps: | |
- name: Checkout current branch | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ needs.get-main-ref.outputs.branch }} | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.9' | |
- run: python -m pip install --upgrade setuptools virtualenv | |
- run: pip install -r requirements-dev.txt | |
- run: pytest --cov=hooks --cov-fail-under=100 | |
type-check: | |
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/type-check') || contains(github.event.comment.body, '/all-tests')) }} | |
runs-on: ubuntu-latest | |
name: Type checking | |
needs: [get-main-ref] | |
steps: | |
- name: Checkout current branch | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ needs.get-main-ref.outputs.branch }} | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.9' | |
- run: python -m pip install --upgrade setuptools virtualenv | |
- run: pip install -r requirements-dev.txt | |
- run: mypy hooks | |
mutate: | |
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/mutate') || contains(github.event.comment.body, '/all-tests')) }} | |
runs-on: ubuntu-latest | |
name: Mutation tests | |
needs: [get-main-ref, coverage] | |
steps: | |
- name: Checkout current branch | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ needs.get-main-ref.outputs.branch }} | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- run: python -m pip install --upgrade setuptools virtualenv | |
- run: pip install -r requirements-dev.txt | |
- run: pytest --cov=hooks | |
- run: mutmut run --paths-to-mutate "./hooks/" --use-coverage --no-progress | |
combos: | |
if: ${{ !needs.get-main-ref.outputs.onPR || (contains(github.event.comment.body, '/combos') || contains(github.event.comment.body, '/all-tests')) }} | |
runs-on: ${{ matrix.os }} | |
name: Tests on ${{ matrix.os }} with Python ${{ matrix.env }} | |
needs: [get-main-ref, coverage] | |
strategy: | |
matrix: | |
os: [windows-latest, ubuntu-latest, macos-latest] | |
env: ['3.9', '3.10', '3.11', '3.12'] | |
exclude: | |
# exclude the sanity-run combo, no need to re-run it | |
- os: ubuntu-latest | |
env: '3.9' | |
# exclude the main combo, no need to re-run it | |
- os: ubuntu-latest | |
env: '3.12' | |
steps: | |
- name: Checkout current branch | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ needs.get-main-ref.outputs.branch }} | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.env }} | |
- run: python -m pip install --upgrade setuptools virtualenv | |
- run: pip install -r requirements-dev.txt | |
- run: pytest |