summaryrefslogtreecommitdiff
path: root/.github/workflows/build.yml
blob: eb6996daa0f2d8c3df44fbe6c71da52eebfe07a0 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Executed on every push by GitHub Actions. This runs CI tests and
# generates wheels (not all) on the following platforms:
#
# * Linux
# * macOS
# * Windows (disabled)
# * FreeBSD
#
# To skip certain builds see:
# https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip
#
# External GH actions:
# * https://github.com/pypa/cibuildwheel
# * https://github.com/actions/checkout
# * https://github.com/actions/setup-python
# * https://github.com/actions/upload-artifact
# * https://github.com/marketplace/actions/cancel-workflow-action
# * https://github.com/vmactions/freebsd-vm

on: [push, pull_request]
name: build
jobs:
  # Linux + macOS + Windows Python 3
  py3:
    name: py3-${{ matrix.os }}-${{ startsWith(matrix.os, 'windows') && matrix.archs || 'all' }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 20
    strategy:
      fail-fast: false
      matrix:
        include:
        - os: ubuntu-latest
          archs: "x86_64 i686"
        - os: macos-12
          archs: "x86_64 arm64"
        - os: windows-2019
          archs: "AMD64"
        - os: windows-2019
          archs: "x86"

    steps:
    - name: Cancel previous runs
      uses: styfle/cancel-workflow-action@0.9.1
      with:
        access_token: ${{ github.token }}

    - uses: actions/checkout@v3
    - uses: actions/setup-python@v4
      with:
        python-version: 3.11

    - name: Create wheels + run tests
      uses: pypa/cibuildwheel@v2.11.2
      env:
        CIBW_ARCHS: "${{ matrix.archs }}"

    - name: Upload wheels
      uses: actions/upload-artifact@v3
      with:
        name: wheels
        path: wheelhouse

    - name: Generate .tar.gz
      if: matrix.os == 'ubuntu-latest'
      run: |
        make generate-manifest
        python setup.py sdist
        mv dist/psutil*.tar.gz wheelhouse/

  # Linux + macOS + Python 2
  py2:
    name: py2-${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 20
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-12]
    env:
      CIBW_TEST_COMMAND:
        PYTHONWARNINGS=always PYTHONUNBUFFERED=1 PSUTIL_DEBUG=1 python {project}/psutil/tests/runner.py &&
        PYTHONWARNINGS=always PYTHONUNBUFFERED=1 PSUTIL_DEBUG=1 python {project}/psutil/tests/test_memleaks.py
      CIBW_TEST_EXTRAS: test
      CIBW_BUILD: 'cp27-*'

    steps:
    - name: Cancel previous runs
      uses: styfle/cancel-workflow-action@0.9.1
      with:
        access_token: ${{ github.token }}

    - uses: actions/checkout@v3
    - uses: actions/setup-python@v4
      with:
        python-version: 3.9

    - name: Create wheels + run tests
      uses: pypa/cibuildwheel@v1.12.0

    - name: Upload wheels
      uses: actions/upload-artifact@v3
      with:
        name: wheels
        path: wheelhouse

    - name: Generate .tar.gz
      if: matrix.os == 'ubuntu-latest'
      run: |
        make generate-manifest
        python setup.py sdist
        mv dist/psutil*.tar.gz wheelhouse/

  # FreeBSD (tests only)
  py3-freebsd:
    runs-on: macos-12
    steps:
    - name: Cancel previous runs
      uses: styfle/cancel-workflow-action@0.9.1
      with:
        access_token: ${{ github.token }}

    - uses: actions/checkout@v3

    - name: Run tests
      id: test
      uses: vmactions/freebsd-vm@v0
      with:
        usesh: true
        prepare: pkg install -y gcc python3
        run: |
          set +e
          export \
            PYTHONUNBUFFERED=1 \
            PYTHONWARNINGS=always \
            PSUTIL_DEBUG=1
          python3 -m pip install --user setuptools
          python3 setup.py install
          python3 psutil/tests/runner.py
          python3 psutil/tests/test_memleaks.py

  # Run linters
  linters:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - uses: actions/setup-python@v4
    - name: 'Run linters'
      run: |
        # py3
        python3 -m pip install flake8 isort
        python3 -m flake8 .
        python3 -m isort .
        # clinter
        find . -type f \( -iname "*.c" -o -iname "*.h" \) | xargs python3 scripts/internal/clinter.py

  # Check sanity of .tar.gz + wheel files
  check-dist:
    needs: [py2, py3]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: 3.x
      - uses: actions/download-artifact@v3
        with:
          name: wheels
          path: wheelhouse
      - run: |
          python scripts/internal/print_hashes.py wheelhouse/
          pipx run twine check --strict wheelhouse/*