Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 113 additions & 4 deletions .github/workflows/_build-cibuildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ on:
description: Package version being built.
required: true
type: string
source:
description: Source provider (checkout or pypi-sdist).
required: false
default: checkout
type: string
repository:
description: Upstream owner/repository to check out.
required: true
description: Upstream owner/repository to check out when source is checkout.
required: false
default: ''
type: string
ref:
description: Upstream ref to check out.
required: true
description: Upstream ref to check out when source is checkout.
required: false
default: ''
type: string
artifact-tag:
description: Platform or ABI suffix used in the uploaded artifact name.
Expand Down Expand Up @@ -262,7 +269,24 @@ jobs:
runs-on: ubuntu-24.04-riscv
timeout-minutes: ${{ inputs['timeout-minutes'] }}
steps:
- name: Validate source configuration
env:
SOURCE: ${{ inputs.source }}
REPOSITORY: ${{ inputs.repository }}
run: |
case "$SOURCE" in
checkout)
test -n "$REPOSITORY"
;;
pypi-sdist) ;;
*)
echo "unsupported source: $SOURCE" >&2
exit 1
;;
esac

- name: Checkout ${{ inputs.repository }} ${{ inputs.ref }}
if: inputs.source == 'checkout'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: ${{ inputs.repository }}
Expand All @@ -274,6 +298,91 @@ jobs:
sparse-checkout: ${{ inputs['checkout-sparse-checkout'] }}
persist-credentials: false

- name: Download and extract PyPI sdist
if: inputs.source == 'pypi-sdist'
env:
PACKAGE: ${{ inputs.package }}
VERSION: ${{ inputs.version }}
DESTINATION: ${{ inputs.package }}
run: |
python3 - <<'PY'
import hashlib
import json
import os
import shutil
import stat
import tarfile
import tempfile
import urllib.parse
import urllib.request
import zipfile
from pathlib import Path, PurePosixPath

distribution = os.environ["PACKAGE"]
version = os.environ["VERSION"]
destination = Path(os.environ["GITHUB_WORKSPACE"], os.environ["DESTINATION"])
api = "https://pypi.org/pypi/{}/{}/json".format(
urllib.parse.quote(distribution, safe=""),
urllib.parse.quote(version, safe=""),
)
request = urllib.request.Request(
api,
headers={"User-Agent": "riseproject-dev/python-wheels"},
)
with urllib.request.urlopen(request) as response:
metadata = json.load(response)
sdists = [item for item in metadata["urls"] if item["packagetype"] == "sdist"]
if len(sdists) != 1:
raise SystemExit(
f"expected exactly one PyPI sdist for {distribution} {version}, found {len(sdists)}"
)

sdist = sdists[0]
parsed = urllib.parse.urlparse(sdist["url"])
if parsed.scheme != "https" or parsed.hostname != "files.pythonhosted.org":
raise SystemExit(f"unexpected PyPI sdist URL: {sdist['url']}")
filename = Path(sdist["filename"]).name
if filename != sdist["filename"]:
raise SystemExit(f"unsafe PyPI sdist filename: {sdist['filename']}")

archive = Path(os.environ["RUNNER_TEMP"], filename)
digest = hashlib.sha256()
request = urllib.request.Request(
sdist["url"],
headers={"User-Agent": "riseproject-dev/python-wheels"},
)
with urllib.request.urlopen(request) as response, archive.open("wb") as stream:
while chunk := response.read(1024 * 1024):
digest.update(chunk)
stream.write(chunk)
expected = sdist["digests"]["sha256"]
if digest.hexdigest() != expected:
raise SystemExit(f"SHA-256 mismatch for {filename}")

staging = Path(tempfile.mkdtemp(prefix="pypi-sdist-", dir=os.environ["RUNNER_TEMP"]))
if tarfile.is_tarfile(archive):
with tarfile.open(archive) as source:
source.extractall(staging, filter="data")
elif zipfile.is_zipfile(archive):
with zipfile.ZipFile(archive) as source:
for member in source.infolist():
path = PurePosixPath(member.filename)
mode = member.external_attr >> 16
if path.is_absolute() or ".." in path.parts or stat.S_ISLNK(mode):
raise SystemExit(f"unsafe path in {filename}: {member.filename}")
source.extractall(staging)
else:
raise SystemExit(f"unsupported PyPI sdist archive: {filename}")

roots = [path for path in staging.iterdir() if path.name != "__MACOSX"]
if len(roots) != 1 or not roots[0].is_dir():
raise SystemExit(f"expected one source directory in {filename}")
if destination.exists():
raise SystemExit(f"source destination already exists: {destination}")
shutil.move(roots[0], destination)
print(f"Downloaded {filename} with SHA-256 {expected}")
PY

- name: Checkout patches
if: inputs.patches
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand Down
86 changes: 12 additions & 74 deletions .github/workflows/build-acora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,88 +43,26 @@ jobs:
package: acora
version: ${{ inputs.version }}

build_sdist:
needs: [setup]
if: needs.setup.outputs.versions != '[]'
strategy:
fail-fast: false
matrix:
version: ${{ fromJSON(needs.setup.outputs.versions) }}
name: Build acora ${{ matrix.version }} sdist
runs-on: ubuntu-latest
permissions:
contents: read
env:
ACORA_VERSION: ${{ matrix.version }}

steps:
- name: Checkout acora acora-${{ env.ACORA_VERSION }}
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: scoder/acora
ref: acora-${{ env.ACORA_VERSION }}
persist-credentials: false

- name: setup uv
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
with:
python-version: '3.12'
activate-environment: true
enable-cache: false

- name: Build sdist
run: |
uv pip install setuptools wheel "Cython>=3.0.11"
python setup.py sdist

- name: Upload sdist artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: acora-${{ env.ACORA_VERSION }}-sdist
path: dist/*.tar.gz
if-no-files-found: error

build_wheels:
needs: [setup, build_sdist]
needs: [setup]
if: needs.setup.outputs.versions != '[]'
name: Build acora ${{ matrix.version }} ${{ matrix.python }}-${{ matrix.platform }}_riscv64
runs-on: ubuntu-24.04-riscv
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.setup.outputs.matrix) }}

env:
ACORA_VERSION: ${{ matrix.version }}

steps:
- name: Download sdist
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: acora-${{ env.ACORA_VERSION }}-sdist
path: dist/

- id: sdist_path
run: echo "path=$(echo dist/*.tar.gz)" >> "$GITHUB_OUTPUT"

- name: Build wheels
uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0
with:
package-dir: ${{ steps.sdist_path.outputs.path }}
output-dir: wheelhouse/
env:
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.platform }}_riscv64
CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }}
# test.py sits next to the acora/ source package at the sdist root; without
# staging it would shadow the installed wheel (gotcha 25).
CIBW_TEST_SOURCES: test.py README.rst
CIBW_TEST_COMMAND: python test.py -v

- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: acora-${{ env.ACORA_VERSION }}-${{ matrix.python }}-${{ matrix.platform }}_riscv64
path: wheelhouse/*.whl
if-no-files-found: error
uses: $/.github/workflows/_build-cibuildwheel.yml
with:
package: acora
version: ${{ matrix.version }}
source: pypi-sdist
artifact-tag: ${{ matrix.python }}-${{ matrix.platform }}_riscv64
cibw-build: ${{ matrix.python }}-${{ matrix.platform }}_riscv64
# test.py sits next to the acora/ source package at the sdist root; without
# staging it would shadow the installed wheel (gotcha 25).
cibw-test-sources: test.py README.rst
cibw-test-command: python test.py -v

publish:
name: Publish acora ${{ matrix.version }}
Expand Down
Loading