Skip to content

Commit

Permalink
Add PyPy (#80)
Browse files Browse the repository at this point in the history
* add pypy

* fix actions var

* workdir

* add pypy release workflow

* add pypy version to zip

* win binaries are at root of directory

* fix pip on macos

* macos -> darwin

* macos -> darwin
  • Loading branch information
bjia56 authored Aug 8, 2024
1 parent d8b9073 commit 6789d40
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .github/workflows/build_python_on_branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,15 @@ jobs:
uses: ./.github/workflows/repackage_graalpy.yml
with:
graalpy_version: ${{ matrix.graalpy_version }}
platforms: "linux-x86_64,linux-aarch64,macos,windows"

pypy:
name: PyPy ${{ matrix.pypy_version }}
strategy:
fail-fast: false
matrix:
pypy_version: [ 7.3.16 ]
uses: ./.github/workflows/repackage_pypy.yml
with:
pypy_version: ${{ matrix.pypy_version }}
platforms: "linux-x86_64,linux-aarch64,macos,windows"
92 changes: 92 additions & 0 deletions .github/workflows/release_pypy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Build and publish PyPy

on:
workflow_dispatch:
inputs:
pypy_version:
required: true
type: string
beta:
required: false
type: boolean
default: false
workflow_call:
inputs:
pypy_version:
required: true
type: string
beta:
required: false
type: boolean
default: false

jobs:
build:
name: Build PyPy ${{ inputs.pypy_version }}
uses: ./.github/workflows/repackage_pypy.yml
with:
pypy_version: ${{ inputs.pypy_version }}
platforms: "linux-x86_64,linux-aarch64,macos,windows"

publish:
name: Publish PyPy ${{ inputs.pypy_version }}
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get tags
run: git fetch --tags origin

- name: Download artifact
uses: actions/download-artifact@v4
with:
pattern: pypy-*
path: /tmp/pypy/
merge-multiple: true

- name: Get latest
run: |
echo "LATEST_TAG=$(./scripts/pick_semver.sh ${{ inputs.pypy_version }} ${{ inputs.beta }} pypy true)" >> $GITHUB_ENV
- name: Pick tag
id: pick_tag
run: |
SELECTED_TAG=$(./scripts/pick_semver.sh ${{ inputs.pypy_version }} ${{ inputs.beta }} pypy)
echo "SELECTED_TAG=$SELECTED_TAG" >> $GITHUB_ENV
echo "::set-output name=release_tag::$SELECTED_TAG"
- name: Create release
run: |
gh release create ${{ env.SELECTED_TAG }} \
--title ${{ env.SELECTED_TAG }} \
--target ${{ github.sha }} \
${{ env.LATEST_TAG && format('--generate-notes --notes-start-tag {0}', env.LATEST_TAG) || format('--notes "PyPy {0}"', inputs.pypy_version) }} \
${{ inputs.beta && '--prerelease' || '' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload files
uses: softprops/action-gh-release@v2
with:
files: /tmp/pypy/pypy*.zip
tag_name: ${{ env.SELECTED_TAG }}

outputs:
release_tag: ${{ steps.pick_tag.outputs.release_tag }}

update_installers:
name: Update installers
needs: publish
permissions:
contents: write
uses: ./.github/workflows/update_nodejs_installers.yml
with:
version: ${{ inputs.pypy_version }}
release_tag: ${{ needs.publish.outputs.release_tag }}
beta: ${{ inputs.beta }}
implementation: pypy
secrets: inherit
120 changes: 120 additions & 0 deletions .github/workflows/repackage_pypy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Repackage PyPy

on:
workflow_dispatch:
inputs:
pypy_version:
required: true
type: string
platforms:
required: true
type: string
default: "linux-x86_64,linux-aarch64,macos,windows"
workflow_call:
inputs:
pypy_version:
required: true
type: string
platforms:
required: true
type: string

env:
image_map: '{"x86_64": "amd64/ubuntu:20.04", "aarch64": "arm64v8/ubuntu:20.04"}'

jobs:
build_linux:
name: Linux ${{ inputs.pypy_version }} ${{ matrix.arch }}
if: ${{ contains(inputs.platforms, 'linux') }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch: [x86_64, aarch64]
exclude:
- arch: ${{ !contains(inputs.platforms, 'linux-x86_64') && 'x86_64' || '' }}
- arch: ${{ !contains(inputs.platforms, 'linux-aarch64') && 'aarch64' || '' }}

steps:
- name: Parse image
id: parse_image
run: |
IMAGE=$(echo ${{ toJSON(env.image_map) }} | jq -r '.["${{ matrix.arch }}"]')
echo "image=$IMAGE" >> "$GITHUB_OUTPUT"
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Repackage
uses: addnab/docker-run-action@v3
with:
image: ${{ steps.parse_image.outputs.image }}
options: -v ${{ github.workspace }}:/work --workdir /work
shell: bash
run: |
set -ex
./scripts/repackage_pypy.sh ${{ matrix.arch }} ${{ inputs.pypy_version }} linux
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: pypy-linux-${{ matrix.arch }}-${{ inputs.pypy_version }}
path: ./pypy*.zip

build_windows:
name: Windows ${{ inputs.pypy_version }} x86_64
if: ${{ contains(inputs.platforms, 'windows') }}
runs-on: windows-latest

steps:
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: Checkout
uses: actions/checkout@v4

- name: Repackage
shell: bash
run: |
set -ex
./scripts/repackage_pypy.sh x86_64 ${{ inputs.pypy_version }} windows
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: pypy-windows-x86_64-${{ inputs.pypy_version }}
path: ./pypy*.zip

build_macos:
name: MacOS ${{ inputs.pypy_version }} ${{ matrix.arch }}
if: ${{ contains(inputs.platforms, 'macos') }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
arch: [x86_64, aarch64]
include:
- arch: x86_64
runner: macos-12
- arch: aarch64
runner: macos-14

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Repackage
run: |
set -ex
./scripts/repackage_pypy.sh ${{ matrix.arch }} ${{ inputs.pypy_version }} darwin
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: pypy-darwin-${{ matrix.arch }}-${{ inputs.pypy_version }}
path: ./pypy*.zip
2 changes: 1 addition & 1 deletion .github/workflows/update_nodejs_installers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:

- name: Update and publish installers
run: |
python ./scripts/update_installer.py ${{ inputs.version }} ${{ inputs.release_tag }} ${{ inputs.implementation}}
python ./scripts/update_installer.py ${{ inputs.version }} ${{ inputs.release_tag }} ${{ inputs.implementation }}
cd ./installers/nodejs
npm i
Expand Down
4 changes: 4 additions & 0 deletions installers/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
"versionBuilds": {
"24.0.2": "graalpy-v24.0.2-beta.1"
}
},
"pypy": {
"versions": [],
"versionBuilds": {}
}
}
}
82 changes: 82 additions & 0 deletions scripts/repackage_pypy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash

set -e

ARCH=$1
PYPY_VERSION=$2
PLATFORM=$3

if [[ "${PLATFORM}" == "linux" ]]; then
echo "::group::Install tools"
apt update && apt -y install zip python3-pip curl
echo "::endgroup::"
fi

if [[ "${PLATFORM}" == "darwin" ]]; then
python3 -m venv venv
source venv/bin/activate
fi

python3 -m pip install pyclean

WORKDIR=$(pwd)

function repackage_pypy () {
DISTRIBUTION=$1
echo "::group::PyPy ${DISTRIBUTION}"

if [[ "${PLATFORM}" == "linux" ]]; then
if [[ "${ARCH}" == "x86_64" ]]; then
DL_LINK=https://downloads.python.org/pypy/pypy${DISTRIBUTION}-v${PYPY_VERSION}-linux64.tar.bz2
DL_FILENAME=pypy${DISTRIBUTION}-v${PYPY_VERSION}-linux64
else
DL_LINK=https://downloads.python.org/pypy/pypy${DISTRIBUTION}-v${PYPY_VERSION}-aarch64.tar.bz2
DL_FILENAME=pypy${DISTRIBUTION}-v${PYPY_VERSION}-aarch64
fi
elif [[ "${PLATFORM}" == "darwin" ]]; then
if [[ "${ARCH}" == "x86_64" ]]; then
DL_LINK=https://downloads.python.org/pypy/pypy${DISTRIBUTION}-v${PYPY_VERSION}-macos_x86_64.tar.bz2
DL_FILENAME=pypy${DISTRIBUTION}-v${PYPY_VERSION}-macos_x86_64
else
DL_LINK=https://downloads.python.org/pypy/pypy${DISTRIBUTION}-v${PYPY_VERSION}-macos_arm64.tar.bz2
DL_FILENAME=pypy${DISTRIBUTION}-v${PYPY_VERSION}-macos_arm64
fi
elif [[ "${PLATFORM}" == "windows" ]]; then
DL_LINK=https://downloads.python.org/pypy/pypy${DISTRIBUTION}-v${PYPY_VERSION}-win64.zip
DL_FILENAME=pypy${DISTRIBUTION}-v${PYPY_VERSION}-win64
fi
UPLOAD_FILENAME=pypy${DISTRIBUTION}-${PYPY_VERSION}-${PLATFORM}-${ARCH}

if [[ "${PLATFORM}" == "windows" ]]; then
curl -L ${DL_LINK} --output ${DL_FILENAME}.zip
7z.exe x ${DL_FILENAME}.zip
rm ${DL_FILENAME}.zip
else
curl -L ${DL_LINK} --output ${DL_FILENAME}.tar.bz2
tar -xf ${DL_FILENAME}.tar.bz2
rm ${DL_FILENAME}.tar.bz2
fi

cd ${DL_FILENAME}
if [[ "${PLATFORM}" == "windows" ]]; then
./python -m ensurepip
else
./bin/python -m ensurepip
fi

cd ${WORKDIR}
mv ${DL_FILENAME} ${UPLOAD_FILENAME}

python3 -m pyclean -v ${UPLOAD_FILENAME}
tar -czf ${WORKDIR}/${UPLOAD_FILENAME}.tar.gz ${UPLOAD_FILENAME}
if [[ "${PLATFORM}" == "windows" ]]; then
7z.exe a ${WORKDIR}/${UPLOAD_FILENAME}.zip ${UPLOAD_FILENAME}
else
zip ${WORKDIR}/${UPLOAD_FILENAME}.zip $(tar tf ${WORKDIR}/${UPLOAD_FILENAME}.tar.gz)
fi

echo "::endgroup::"
}

repackage_pypy 3.10
repackage_pypy 3.9

0 comments on commit 6789d40

Please sign in to comment.