summaryrefslogtreecommitdiff
path: root/third_party/re2/src/.github/workflows/python.yml
blob: 0767cc5a8a2129b91d22eb8fb1f604cd7d269ebe (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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
name: Python
on:
  workflow_dispatch:
    inputs:
      build:
        required: true
        type: number
permissions:
  contents: read
jobs:
  wheel-linux:
    name: Linux ${{ matrix.os }}, ${{ matrix.arch.name }}, Python ${{ matrix.ver }}
    runs-on: ${{ matrix.arch.runs-on }}
    container:
      image: quay.io/pypa/${{ matrix.os }}_${{ matrix.arch.python-name }}
      # Don't run as root within the container.
      # Neither Git nor Bazel appreciates that.
      # 1001 is the GitHub Actions runner user.
      options: --init --user 1001
    strategy:
      fail-fast: false
      matrix:
        arch:
          - { name: X64,   python-name: x86_64,  runs-on: [ubuntu-latest]             }
          - { name: ARM64, python-name: aarch64, runs-on: [self-hosted, linux, arm64] }
        os: [manylinux2014, manylinux_2_28]
        ver: ['3.8', '3.9', '3.10', '3.11', '3.12']
    env:
      BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      PYTHON: /usr/local/bin/python${{ matrix.ver }}
      # Bazel fails if the username is unknown.
      USER: runner
    steps:
      - uses: actions/checkout@v3
      # Stash the timestamp for the commit SHA that triggered the workflow.
      - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}"
        shell: bash
      # TODO(junyer): Use `v2` whenever a new release is tagged.
      - uses: bazelbuild/setup-bazelisk@6244971d4f7ba9aca943c2f3ede2bbd813fcca51
      - name: Prepare Python ${{ matrix.ver }} environment
        run: |
          "${PYTHON}" -m pip install --upgrade pip
          "${PYTHON}" -m pip install --upgrade build wheel auditwheel
          "${PYTHON}" -m pip install --upgrade absl-py
        shell: bash
      - name: Build wheel
        env:
          SOURCE_DATE_EPOCH: ${{ env.timestamp }}
        run: |
          "${PYTHON}" -m build --wheel
          "${PYTHON}" -m auditwheel repair --wheel-dir=. dist/*
        shell: bash
        working-directory: python
      - name: Test wheel
        run: |
          "${PYTHON}" -m pip install google_re2-*.whl
          "${PYTHON}" re2_test.py
        shell: bash
        working-directory: python
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ hashFiles('python/google_re2-*.whl') }}
          path: python/google_re2-*.whl
          retention-days: 1
  wheel-macos:
    name: macOS ${{ matrix.os }}, ${{ matrix.arch.name }}, Python ${{ matrix.ver }}
    runs-on: macos-${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        arch:
          - { name: X64,   bazel-name: x86_64, python-name: x86_64 }
          - { name: ARM64, bazel-name: arm64,  python-name: arm64  }
        os: [11, 12, 13]
        ver: ['3.8', '3.9', '3.10', '3.11', '3.12']
    env:
      BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      BAZEL_CPU: darwin_${{ matrix.arch.bazel-name }}
      PLAT_NAME: macosx-${{ matrix.os }}.0-${{ matrix.arch.python-name }}
      # Stop macOS from reporting the system version as 10.x.
      # Otherwise, Python refuses to install the built wheel!
      SYSTEM_VERSION_COMPAT: 0
    steps:
      - uses: actions/checkout@v3
      # Stash the timestamp for the commit SHA that triggered the workflow.
      - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}"
        shell: bash
      # TODO(junyer): Use `v2` whenever a new release is tagged.
      - uses: bazelbuild/setup-bazelisk@6244971d4f7ba9aca943c2f3ede2bbd813fcca51
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.ver }}
      - name: Prepare Python ${{ matrix.ver }} environment
        run: |
          python -m pip install --upgrade pip
          python -m pip install --upgrade build wheel delocate
          python -m pip install --upgrade absl-py
        shell: bash
      - name: Build wheel
        env:
          SOURCE_DATE_EPOCH: ${{ env.timestamp }}
        run: |
          python -m build --wheel
          python -m delocate.cmd.delocate_wheel --wheel-dir=. dist/*
        shell: bash
        working-directory: python
      - if: matrix.arch.name == runner.arch
        name: Test wheel
        run: |
          python -m pip install google_re2-*.whl
          python re2_test.py
        shell: bash
        working-directory: python
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ hashFiles('python/google_re2-*.whl') }}
          path: python/google_re2-*.whl
          retention-days: 1
  wheel-windows:
    name: Windows, ${{ matrix.arch.name }}, Python ${{ matrix.ver }}
    runs-on: windows-latest
    strategy:
      fail-fast: false
      matrix:
        arch:
          - { name: X86, bazel-name: x64_x86, python-name: win32     }
          - { name: X64, bazel-name: x64,     python-name: win_amd64 }
        ver: ['3.8', '3.9', '3.10', '3.11', '3.12']
    env:
      BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      BAZEL_CPU: ${{ matrix.arch.bazel-name }}_windows
      PLAT_NAME: ${{ matrix.arch.python-name }}
    steps:
      - uses: actions/checkout@v3
      # Stash the timestamp for the commit SHA that triggered the workflow.
      - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}"
        shell: bash
      # Avoid the Chocolatey install of Bazel getting in the way;
      # `bazelbuild/setup-bazelisk` doesn't work for some reason.
      - run: |
          choco uninstall -y bazel
          choco install -y bazelisk
        shell: bash
      # Lowercase the architecture name for `actions/setup-python`.
      - run: |
          ARCHITECTURE=${{ matrix.arch.name }}
          echo "architecture=${ARCHITECTURE,,}" >> "${GITHUB_ENV}"
        shell: bash
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.ver }}
          architecture: ${{ env.architecture }}
      - name: Prepare Python ${{ matrix.ver }} environment
        run: |
          python -m pip install --upgrade pip
          python -m pip install --upgrade build wheel delvewheel
          python -m pip install --upgrade absl-py
        shell: bash
      - name: Build wheel
        env:
          SOURCE_DATE_EPOCH: ${{ env.timestamp }}
        run: |
          python -m build --wheel
          python -m delvewheel repair --wheel-dir=. dist/*
        shell: bash
        working-directory: python
      - name: Test wheel
        run: |
          python -m pip install google_re2-*.whl
          python re2_test.py
        shell: bash
        working-directory: python
      - uses: actions/upload-artifact@v3
        with:
          name: ${{ hashFiles('python/google_re2-*.whl') }}
          path: python/google_re2-*.whl
          retention-days: 1
  publish:
    needs:
      - wheel-linux
      - wheel-macos
      - wheel-windows
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      # Stash the timestamp for the commit SHA that triggered the workflow.
      - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}"
        shell: bash
      - uses: actions/setup-python@v4
        with:
          python-version: '3.x'
      - name: Prepare Python 3.x environment
        run: |
          python -m pip install --upgrade pip
          python -m pip install --upgrade build wheel
        shell: bash
      - if: inputs.build == 1
        name: Build source
        env:
          SOURCE_DATE_EPOCH: ${{ env.timestamp }}
        run: |
          python -m build --sdist
        shell: bash
        working-directory: python
      - uses: actions/download-artifact@v3
        with:
          path: python
      - name: Set build number to ${{ inputs.build }}
        env:
          SOURCE_DATE_EPOCH: ${{ env.timestamp }}
        run: |
          mkdir -p dist
          for WHL in */google_re2-*.whl; do
            python -m wheel unpack "${WHL}"
            python -m wheel pack --dest-dir=dist --build-number=${{ inputs.build }} google_re2-*
            rm -rf google_re2-*
          done
        shell: bash
        working-directory: python
      - if: inputs.build >= 1
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          password: ${{ secrets.PYPI_API_TOKEN }}
          packages_dir: python/dist