• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1name: Python
2on:
3  workflow_dispatch:
4    inputs:
5      build:
6        required: true
7        type: number
8jobs:
9  wheel-linux:
10    name: Linux ${{ matrix.os }}, ${{ matrix.arch.name }}, Python ${{ matrix.ver }}
11    runs-on: ${{ matrix.arch.runs-on }}
12    container:
13      image: quay.io/pypa/${{ matrix.os }}_${{ matrix.arch.python-name }}
14      # Don't run as root within the container.
15      # Neither Git nor Bazel appreciates that.
16      # 1001 is the GitHub Actions runner user.
17      options: --init --user 1001
18    strategy:
19      fail-fast: false
20      matrix:
21        arch:
22          - { name: X64,   python-name: x86_64,  runs-on: [ubuntu-latest]             }
23          - { name: ARM64, python-name: aarch64, runs-on: [self-hosted, linux, arm64] }
24        os: [manylinux2014, manylinux_2_28]
25        ver: ['3.8', '3.9', '3.10', '3.11', '3.12']
26    env:
27      BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28      PYTHON: /usr/local/bin/python${{ matrix.ver }}
29      # Bazel fails if the username is unknown.
30      USER: runner
31    steps:
32      - uses: actions/checkout@v3
33      # Stash the timestamp for the commit SHA that triggered the workflow.
34      - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}"
35        shell: bash
36      # TODO(junyer): Use `v2` whenever a new release is tagged.
37      - uses: bazelbuild/setup-bazelisk@6244971d4f7ba9aca943c2f3ede2bbd813fcca51
38      - name: Prepare Python ${{ matrix.ver }} environment
39        run: |
40          "${PYTHON}" -m pip install --upgrade pip
41          "${PYTHON}" -m pip install --upgrade build wheel auditwheel
42          "${PYTHON}" -m pip install --upgrade absl-py
43        shell: bash
44      - name: Build wheel
45        env:
46          SOURCE_DATE_EPOCH: ${{ env.timestamp }}
47        run: |
48          "${PYTHON}" -m build --wheel
49          "${PYTHON}" -m auditwheel repair --wheel-dir=. dist/*
50        shell: bash
51        working-directory: python
52      - name: Test wheel
53        run: |
54          "${PYTHON}" -m pip install google_re2-*.whl
55          "${PYTHON}" re2_test.py
56        shell: bash
57        working-directory: python
58      - uses: actions/upload-artifact@v3
59        with:
60          name: ${{ hashFiles('python/google_re2-*.whl') }}
61          path: python/google_re2-*.whl
62          retention-days: 1
63  wheel-macos:
64    name: macOS ${{ matrix.os }}, ${{ matrix.arch.name }}, Python ${{ matrix.ver }}
65    runs-on: macos-${{ matrix.os }}
66    strategy:
67      fail-fast: false
68      matrix:
69        arch:
70          - { name: X64,   bazel-name: x86_64, python-name: x86_64 }
71          - { name: ARM64, bazel-name: arm64,  python-name: arm64  }
72        os: [11, 12, 13]
73        ver: ['3.8', '3.9', '3.10', '3.11', '3.12']
74    env:
75      BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76      BAZEL_CPU: darwin_${{ matrix.arch.bazel-name }}
77      PLAT_NAME: macosx-${{ matrix.os }}.0-${{ matrix.arch.python-name }}
78      # Stop macOS from reporting the system version as 10.x.
79      # Otherwise, Python refuses to install the built wheel!
80      SYSTEM_VERSION_COMPAT: 0
81    steps:
82      - uses: actions/checkout@v3
83      # Stash the timestamp for the commit SHA that triggered the workflow.
84      - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}"
85        shell: bash
86      # TODO(junyer): Use `v2` whenever a new release is tagged.
87      - uses: bazelbuild/setup-bazelisk@6244971d4f7ba9aca943c2f3ede2bbd813fcca51
88      - uses: actions/setup-python@v4
89        with:
90          python-version: ${{ matrix.ver }}
91      - name: Prepare Python ${{ matrix.ver }} environment
92        run: |
93          python -m pip install --upgrade pip
94          python -m pip install --upgrade build wheel delocate
95          python -m pip install --upgrade absl-py
96        shell: bash
97      - name: Build wheel
98        env:
99          SOURCE_DATE_EPOCH: ${{ env.timestamp }}
100        run: |
101          python -m build --wheel
102          python -m delocate.cmd.delocate_wheel --wheel-dir=. dist/*
103        shell: bash
104        working-directory: python
105      - if: matrix.arch.name == runner.arch
106        name: Test wheel
107        run: |
108          python -m pip install google_re2-*.whl
109          python re2_test.py
110        shell: bash
111        working-directory: python
112      - uses: actions/upload-artifact@v3
113        with:
114          name: ${{ hashFiles('python/google_re2-*.whl') }}
115          path: python/google_re2-*.whl
116          retention-days: 1
117  wheel-windows:
118    name: Windows, ${{ matrix.arch.name }}, Python ${{ matrix.ver }}
119    runs-on: windows-latest
120    strategy:
121      fail-fast: false
122      matrix:
123        arch:
124          - { name: X86, bazel-name: x64_x86, python-name: win32     }
125          - { name: X64, bazel-name: x64,     python-name: win_amd64 }
126        ver: ['3.8', '3.9', '3.10', '3.11', '3.12']
127    env:
128      BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
129      BAZEL_CPU: ${{ matrix.arch.bazel-name }}_windows
130      PLAT_NAME: ${{ matrix.arch.python-name }}
131    steps:
132      - uses: actions/checkout@v3
133      # Stash the timestamp for the commit SHA that triggered the workflow.
134      - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}"
135        shell: bash
136      # Avoid the Chocolatey install of Bazel getting in the way;
137      # `bazelbuild/setup-bazelisk` doesn't work for some reason.
138      - run: |
139          choco uninstall -y bazel
140          choco install -y bazelisk
141        shell: bash
142      # Lowercase the architecture name for `actions/setup-python`.
143      - run: |
144          ARCHITECTURE=${{ matrix.arch.name }}
145          echo "architecture=${ARCHITECTURE,,}" >> "${GITHUB_ENV}"
146        shell: bash
147      - uses: actions/setup-python@v4
148        with:
149          python-version: ${{ matrix.ver }}
150          architecture: ${{ env.architecture }}
151      - name: Prepare Python ${{ matrix.ver }} environment
152        run: |
153          python -m pip install --upgrade pip
154          python -m pip install --upgrade build wheel delvewheel
155          python -m pip install --upgrade absl-py
156        shell: bash
157      - name: Build wheel
158        env:
159          SOURCE_DATE_EPOCH: ${{ env.timestamp }}
160        run: |
161          python -m build --wheel
162          python -m delvewheel repair --wheel-dir=. dist/*
163        shell: bash
164        working-directory: python
165      - name: Test wheel
166        run: |
167          python -m pip install google_re2-*.whl
168          python re2_test.py
169        shell: bash
170        working-directory: python
171      - uses: actions/upload-artifact@v3
172        with:
173          name: ${{ hashFiles('python/google_re2-*.whl') }}
174          path: python/google_re2-*.whl
175          retention-days: 1
176  publish:
177    needs:
178      - wheel-linux
179      - wheel-macos
180      - wheel-windows
181    runs-on: ubuntu-latest
182    steps:
183      - uses: actions/checkout@v3
184      # Stash the timestamp for the commit SHA that triggered the workflow.
185      - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}"
186        shell: bash
187      - uses: actions/setup-python@v4
188        with:
189          python-version: '3.x'
190      - name: Prepare Python 3.x environment
191        run: |
192          python -m pip install --upgrade pip
193          python -m pip install --upgrade build wheel
194        shell: bash
195      - if: inputs.build == 1
196        name: Build source
197        env:
198          SOURCE_DATE_EPOCH: ${{ env.timestamp }}
199        run: |
200          python -m build --sdist
201        shell: bash
202        working-directory: python
203      - uses: actions/download-artifact@v3
204        with:
205          path: python
206      - name: Set build number to ${{ inputs.build }}
207        env:
208          SOURCE_DATE_EPOCH: ${{ env.timestamp }}
209        run: |
210          mkdir -p dist
211          for WHL in */google_re2-*.whl; do
212            python -m wheel unpack "${WHL}"
213            python -m wheel pack --dest-dir=dist --build-number=${{ inputs.build }} google_re2-*
214            rm -rf google_re2-*
215          done
216        shell: bash
217        working-directory: python
218      - if: inputs.build >= 1
219        uses: pypa/gh-action-pypi-publish@release/v1
220        with:
221          password: ${{ secrets.PYPI_API_TOKEN }}
222          packages_dir: python/dist
223