Skip to content

Commit

Permalink
Python内部默认调用JS实现 (#30)
Browse files Browse the repository at this point in the history
* kotlin侧添加webpack

* python call js

* 添加benchmark

* python call http

* 编辑打包脚本

* Update python-package.yml

* 编辑打包脚本

* 编辑import策略

* 部分模型改为value class

* Build DokkaGfm documents

* 默认打包时编译JS

* 重新去除静态库桥接方式

* 更新README

* 重新添加docker镜像打包脚本

* fix

---------

Co-authored-by: huangwenlong06 <huangwenlong06@meituan.com>
Co-authored-by: ssttkkl <ssttkkl@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 3, 2024
1 parent fcfa6ee commit 9f78ddd
Show file tree
Hide file tree
Showing 29 changed files with 3,188 additions and 335 deletions.
94 changes: 93 additions & 1 deletion .github/workflows/build-entry-fatjar.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
name: Build WebApi FatJar
on:
pull_request:
branches: [main]
release:
types: [published]
workflow_dispatch:

env:
GHCR_REGISTRY: ghcr.io
IMAGE_NAME: ssttkkl/mahjong-utils-webapi

jobs:
build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -33,4 +39,90 @@ jobs:
uses: AButler/upload-release-assets@v3.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
files: mahjong-utils-webapi/build/libs/*-all.jar
files: mahjong-utils-webapi/build/libs/*-all.jar

docker-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1
with:
cosign-release: 'v2.1.1'

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry docker.io
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.GHCR_REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: |
${{ env.IMAGE_NAME }}
${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
# platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
40 changes: 8 additions & 32 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,67 +16,43 @@ permissions:

jobs:
build:
strategy:
matrix:
os: [ macos-latest, windows-latest, ubuntu-latest ]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- name: Checkout my repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up Python 3.11
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: '3.11'
python-version: '3.12'
- name: Setup Java JDK
if: ${{ matrix.os != 'ubuntu-latest' }}
uses: actions/setup-java@v3.6.0
with:
java-version: 11
java-version: 17
distribution: temurin
cache: 'gradle'
- name: Cache Kotlin/Native compiler
id: cache-konan
uses: actions/cache@v3
with:
path: ~/.konan
key: ${{ runner.os }}-konan
- name: Install dependencies
working-directory: python-lib
run: |
python3 -m pip install --upgrade pip
python3 -m pip install build
- name: Build dist
if: ${{ matrix.os != 'ubuntu-latest' }}
working-directory: python-lib
run: |
python3 -m build --sdist --wheel --outdir dist/
- name: Build dist (for Linux)
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: RalfG/python-wheels-manylinux-build@v0.6.0-manylinux_2_28_x86_64
with:
system-packages: java-11-openjdk
python-versions: cp310-cp310
package-path: python-lib
- name: Upload the Build Artifact
if: ${{ matrix.os != 'ubuntu-latest' }}
uses: actions/upload-artifact@v3.1.1
with:
name: distribution
path: python-lib/dist/*
- name: Upload the Build Artifact (for Linux)
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: actions/upload-artifact@v3.1.1
with:
name: distribution
path: python-lib/dist/*-manylinux*.whl
test:
needs: build
strategy:
matrix:
py: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
os: [ windows-latest, ubuntu-latest ]
os: [ windows-latest, ubuntu-latest, macos-latest ]
fail-fast: false
runs-on: ${{ matrix.os }}
env:
Expand All @@ -102,15 +78,15 @@ jobs:
- name: Install package (for Linux)
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
python -m pip install dist/*-manylinux*.whl
python -m pip install dist/*.whl
- name: Install package (for MacOS)
if: ${{ matrix.os == 'macos-latest' }}
run: |
python -m pip install dist/*-macosx*.whl
python -m pip install dist/*.whl
- name: Install package (for Windows)
if: ${{ matrix.os == 'windows-latest' }}
run: |
Get-ChildItem "dist/*-win*.whl" | Foreach-Object { python -m pip install $_.FullName }
Get-ChildItem "dist/*.whl" | Foreach-Object { python -m pip install $_.FullName }
- name: Test
working-directory: python-lib
run: |
Expand Down
4 changes: 4 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ gradlePlugin {
id = "mahjongutils.buildlogic.kmplib"
implementationClass = "mahjongutils.buildlogic.KmpLibConventionPlugin"
}
register("kmpexe") {
id = "mahjongutils.buildlogic.kmpexe"
implementationClass = "mahjongutils.buildlogic.KmpExeConventionPlugin"
}
register("maven-publish") {
id = "mahjongutils.buildlogic.mavenpublish"
implementationClass = "mahjongutils.buildlogic.MavenPublishConventionPlugin"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package mahjongutils.buildlogic

import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.getting
import org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile


class KmpExeConventionPlugin : Plugin<Project> {
override fun apply(target: Project) = with(target) {
with(pluginManager) {
apply(KmpLibConventionPlugin::class.java)
}
configure<KotlinMultiplatformExtension> {
jvm {
mainRun {
mainClass.set("MainKt")
}
}

if (enableNative) {
targets.withType<KotlinNativeTarget>().configureEach {
binaries.executable()
}
}
if (enableJs) {
js(IR) {
browser {
binaries.executable()
}
nodejs {
binaries.executable()
}
useCommonJs()
}
}
if (enableWasm) {
wasmJs {
browser {
binaries.executable()
}
nodejs {
binaries.executable()
}
useCommonJs()
compilations["main"].packageJson {
name = "mahjong-utils-benchmark-wasm"
customField(
"author", mapOf(
"name" to "ssttkkl",
"email" to "huang.wen.long@hotmail.com"
)
)
customField(
"license", "MIT"
)
}
}
wasmWasi {
nodejs {
binaries.executable()
}
}
}
}

if (enableNative) {
afterEvaluate {
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val isAarch64 = System.getProperty("os.arch") == "aarch64"
val currentOsTargetName = when {
hostOs == "Mac OS X" -> {
if (isAarch64) {
"macosArm64"
} else {
"macosX64"
}
}

hostOs == "Linux" -> {
if (isAarch64) {
"linuxArm64"
} else {
"linuxX64"
}
}

isMingwX64 -> "mingwX64"
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}
tasks.create("runDebugExecutableCurrentOs").apply {
group = "run"
dependsOn("runDebugExecutable" + currentOsTargetName.capitalize())
}
tasks.create("runReleaseExecutableCurrentOs").apply {
group = "run"
dependsOn("runReleaseExecutable" + currentOsTargetName.capitalize())
}
}
}
}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ jetbrains-dokka = { id = "org.jetbrains.dokka", version.ref = "jetbrains-dokka"
ktor = { id = "io.ktor.plugin", version.ref = "ktor" }

buildlogic-kmplib = { id = "mahjongutils.buildlogic.kmplib", version.ref = "buildlogic" }
buildlogic-kmpexe = { id = "mahjongutils.buildlogic.kmpexe", version.ref = "buildlogic" }
buildlogic-mavenpublish = { id = "mahjongutils.buildlogic.mavenpublish", version.ref = "buildlogic" }
Loading

0 comments on commit 9f78ddd

Please sign in to comment.