Skip to content

Commit

Permalink
Add test-integration job
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsmith committed Jul 19, 2023
1 parent 7c43c0a commit 5ac45da
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 54 deletions.
12 changes: 12 additions & 0 deletions .github/actions/create-local-properties/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Create local.properties
description:

runs:
using: composite
steps:
- shell: bash
run: |
for version in 8 11 17; do
java_home_var=JAVA_HOME_${version}_X64
echo chaquopy.java.home.$version=${!java_home_var}
done > product/local.properties
95 changes: 71 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,52 @@ concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash

jobs:
build-product:
runs-on: macos-latest # The fastest runner
versions:
name: List versions
runs-on: macos-latest
steps:
- uses: actions/checkout@v3.5.3

- name: List Python versions
id: python-versions
- id: python
run: |
cd target
echo default=$(./list-versions.py --default)
for mode in short long; do
echo "$mode<<EOF"
./list-versions.py --$mode
echo EOF
done >> $GITHUB_OUTPUT
- id: agp
run: |
cd product/gradle-plugin/src/test/integration/data
(
echo -n versions=
echo base-* | sed 's/base-//g' | jq -cR 'split(" ")'
) >> $GITHUB_OUTPUT
outputs:
python-default: ${{ steps.python.outputs.default }}
python-short: ${{ steps.python.outputs.short }}
python-long: ${{ steps.python.outputs.long }}
agp: ${{ steps.agp.outputs.versions }}

build-product:
needs: versions
runs-on: macos-latest
steps:
- uses: actions/checkout@v3.5.3

- uses: actions/setup-python@v4.6.1
with:
python-version: ${{ steps.python-versions.outputs.short }}
python-version: ${{ needs.versions.outputs.python-short }}

# This step uses a self-contained script rather than steps.python-versions,
# This step uses a self-contained script rather than needs.versions,
# because it's referenced from product/README.md.
- name: Download Android Python builds
run: |
Expand All @@ -45,34 +70,56 @@ jobs:
# runtime/build.gradle. COMPILE_SDK_VERSION can then be removed from Common.java,
# since it's not used anywhere else.
- name: Set up Android SDK
run: "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager
'cmake;3.22.1' 'ndk;22.1.7171670' 'platforms;android-30'"

- name: Create local.properties
run: |
for version in 8 11 17; do
java_home_var=JAVA_HOME_${version}_X64
echo chaquopy.java.home.$version=${!java_home_var}
done > product/local.properties
$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager \
'cmake;3.22.1' 'ndk;22.1.7171670' 'platforms;android-30'
- uses: ./.github/actions/create-local-properties

- name: Build
run: |
cd product
./gradlew publish
- uses: actions/upload-artifact@v3.1.2
- name: Upload Maven repository
uses: actions/upload-artifact@v3.1.2
with:
name: maven
path: maven
if-no-files-found: error

# test-gradle-plugin:
# needs: build-product
# strategy:
# fail-fast: false
# matrix:
# os: [macos, ubuntu, windows]
# agp-version: ["8.0"] # TODO: generate from directory listing
test-integration:
needs: [versions, build-product]
strategy:
fail-fast: false
matrix:
os: [macos, ubuntu, windows]
agp-version: ${{ fromJSON(needs.versions.outputs.agp) }}

runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v3.5.3

- uses: actions/setup-python@v4.6.1
with:
python-version: ${{ needs.versions.outputs.python-short }}

- name: Download Maven repository
uses: actions/download-artifact@v3.0.2
with:
name: maven
path: maven

- name: Install Python requirements
run: |
python${{ needs.versions.outputs.python-default }} -m \
pip install -r gradle-plugin/src/test/integration/requirements.txt
- uses: ./.github/actions/create-local-properties

- name: Test
run: |
cd product
./gradlew testIntegration-${{ matrix.agp-version }}
# runs-on: ${{ matrix.os }}-latest
# steps:
1 change: 0 additions & 1 deletion product/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 21 additions & 20 deletions product/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ This file contains instructions for building and testing Chaquopy.

# Build prerequisites

* A local Python installation for each Python version suported by Chaquopy (list them
with `target/list-versions.py --short`). These must be on the PATH as `pythonX.Y` on
Unix, or `py -X.Y` on Windows.
* A local Python installation for each Python major.minor version suported by Chaquopy
(list them with `target/list-versions.py --short`). These must be on the PATH as
`pythonX.Y` on Unix, or `py -X.Y` on Windows.
* On Linux, install them from your distribution, or use Miniconda.
* On Mac and Windows, download them from https://python.org/.

* Android Python headers and libraries in target/prefix. These can be installed as
shown in ci.yml.
Expand All @@ -27,6 +29,7 @@ This file contains instructions for building and testing Chaquopy.

chaquopy.java.home.8=<path>


# Build

The build can be done either at the command line using `gradlew`, or by opening the project in
Expand All @@ -45,29 +48,27 @@ server.

# Runtime tests

Most of the runtime library unit tests included in the [Android demo
app](https://github.com/chaquo/chaquopy/) can also be run locally. You must have installed the
same major.minor version of Python as Chaquopy currently uses: this is represented below as
`X.Y`.
The runtime unit tests are mainly run on Android via the demo app in ../demo. However,
the non-Android-specific features, such as the Java/Python interface, can also be tested
directly on the build platform.

Prerequisities (on Windows, these must be the MSYS2 versions):

Linux prerequisites:
* GCC and binutils.

* Python development headers (e.g. `pythonX.Y-dev` on Debian)
* The same Python major.minor version as Chaquopy uses by default.

Windows prerequisites:
* On Linux, install it from your distribution, or use Miniconda. Make sure you also
include the development headers (e.g. `pythonX.Y-dev` on Debian).

* Install MSYS2.
* Make sure the `mingw64\bin` directory is on the `PATH`, and is the directory actually used
for invocations of `pythonX.Y`.
* On Mac, download it from https://python.org/.

Common prerequisities (on Windows, these must be the MSYS2 versions):
* On Windows, install it using MSYS2's `pacman`. If MSYS2 has already moved on to a
later Python version, download the correct version from
http://repo.msys2.org/mingw/mingw64/ and install it with `pacman -U`.

* GCC and binutils.
* The same Python major.minor version as Chaquopy currently uses.
* On Linux, if your distribution supplies a different Python version, it's easy to build the
correct version from source.
* On Windows, if MSYS2 has already moved on to the next Python version, download the correct
version from http://repo.msys2.org/mingw/mingw64/ and install it with `pacman -U`.
Make sure your PATH is set so that invocations of `pythonX.Y` will use the MSYS2
version.

The tests are run by the Gradle tasks `runtime:testPython` and `runtime:testJava`. Or run
`runtime:check` to test everything at once.
Expand Down
28 changes: 19 additions & 9 deletions target/list-versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,29 @@

parser = argparse.ArgumentParser()
mode_group = parser.add_mutually_exclusive_group(required=True)
mode_group.add_argument("--default", action="store_true")
mode_group.add_argument("--short", action="store_true")
mode_group.add_argument("--long", action="store_true")
args = parser.parse_args()

product_dir = abspath(f"{dirname(__file__)}/../product")
lines = []
for line in open(f"{product_dir}/buildSrc/src/main/java/com/chaquo/python/Common.java"):
match = re.search(r'PYTHON_VERSIONS.put\("(\d+)\.(\d+)\.(\d+)", "(\d+)"\)', line)
if match:
major, minor, micro, build = match.groups()
if args.short:
print(f"{major}.{minor}")
elif args.long:
print(f"{major}.{minor}.{micro}-{build}")
else:
raise AssertionError()
if args.default:
match = re.search(r'DEFAULT_PYTHON_VERSION = "(.+)"', line)
if match:
lines.append(match[1])
break
else:
match = re.search(r'PYTHON_VERSIONS.put\("(\d+)\.(\d+)\.(\d+)", "(\d+)"\)', line)
if match:
major, minor, micro, build = match.groups()
if args.short:
lines.append(f"{major}.{minor}")
elif args.long:
lines.append(f"{major}.{minor}.{micro}-{build}")
else:
raise AssertionError()

assert lines
print("\n".join(lines))

0 comments on commit 5ac45da

Please sign in to comment.