1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Test

on:
  push:
    branches: [ main ]
    paths-ignore:
      - 'docs/**'
      - '*.rst'
  pull_request:
    branches: [ main ]
    paths-ignore:
      - 'docs/**'
      - '*.rst'
  # Allow manual workflow triggering from the "Actions" tab.
  workflow_dispatch:

permissions:
  contents: read
  id-token: write

jobs:
  test:
    runs-on: ubuntu-latest

    services:
      postgres:
        image: postgres
        env:
          POSTGRES_PASSWORD: password
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          # Make accessible on localhost.
          - 5432:5432

      redis:
        image: redis
        options: >-
          --health-cmd "redis-cli ping"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          # Make accessible on localhost.
          - 6379:6379

    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.13"]

    steps:
    - name: Check out repository
      uses: actions/checkout@v4
      with:
        persist-credentials: false

    - name: Install uv and Python
      uses: astral-sh/setup-uv@v7
      with:
        enable-cache: true
        cache-dependency-glob: "uv.lock"
        python-version: ${{ matrix.python-version }}

    - name: Install project
      run: uv sync --frozen --only-group test

    - name: Test with pytest and coverage
      env:
        POSTGRES_HOST: localhost
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: password
        POSTGRES_DB: postgres
        PYTEST_ADDOPTS: "--color=yes"
      run: |
        uv run coverage run --source=byceps -m pytest tests

    - name: Generate XML output from test coverage
      if: github.repository == 'byceps/byceps' && github.ref_name == 'main'
      run: |
        uv run coverage xml

    - name: Upload coverage to Qlty
      uses: qltysh/qlty-action/coverage@v1
      if: github.repository == 'byceps/byceps' && github.ref_name == 'main'
      with:
        oidc: true
        files: coverage.xml

    - name: Post result to Discord
      # Run job even if build is cancelled.
      if: always() && github.repository == 'byceps/byceps' && github.ref_name == 'main'
      env:
        JOB_RESULT: ${{ job.status }}
        DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
      run: uv run ./.github/workflows/send-workflow-result-to-discord.py --result $JOB_RESULT --webhook-url $DISCORD_WEBHOOK_URL