diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d58c1d3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,176 @@ +name: Release + +on: + workflow_run: + workflows: [CI] + types: [completed] + workflow_dispatch: + inputs: + tag: + description: Existing incubating tag to publish + required: true + type: string + +concurrency: + group: release-${{ github.event.workflow_run.head_branch || inputs.tag }} + cancel-in-progress: false + +permissions: + actions: read + contents: write + id-token: write + packages: write + +jobs: + publish: + if: >- + github.event_name == 'workflow_dispatch' || + ( + github.event.workflow_run.event == 'push' && + github.event.workflow_run.conclusion == 'success' && + startsWith(github.event.workflow_run.head_branch, 'v') && + contains(github.event.workflow_run.head_branch, '-incubating.') + ) + runs-on: ubuntu-24.04 + env: + RELEASE_TAG: >- + ${{ github.event.workflow_run.head_branch || inputs.tag }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + steps: + - uses: actions/checkout@v7 + with: + ref: ${{ env.RELEASE_TAG }} + fetch-depth: 0 + + - uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: "17" + + - uses: actions/setup-node@v7 + with: + node-version: "24" + registry-url: https://npm.pkg.github.com + scope: "@oxyroid" + cache: npm + cache-dependency-path: web-sdk/package-lock.json + + - name: Verify tag and CI + env: + GH_TOKEN: ${{ github.token }} + CI_HEAD_SHA: ${{ github.event.workflow_run.head_sha }} + run: | + git show-ref --verify --quiet "refs/tags/$RELEASE_TAG" + tag_sha="$(git rev-list -n 1 "$RELEASE_TAG")" + if [[ -n "$CI_HEAD_SHA" ]]; then + [[ "$tag_sha" == "$CI_HEAD_SHA" ]] + elif ! gh run list \ + --workflow ci.yml \ + --branch "$RELEASE_TAG" \ + --event push \ + --status success \ + --limit 20 \ + --json headSha \ + --jq ".[] | select(.headSha == \"$tag_sha\")" | + grep -q .; then + echo "No successful CI run found for $RELEASE_TAG" >&2 + exit 1 + fi + ./scripts/verify-release-tag.sh "$RELEASE_TAG" + + - name: Build release artifacts + run: | + release_version="${RELEASE_TAG#v}" + mkdir -p build/release + ./gradlew :android-sdk:assembleRelease + cp android-sdk/build/outputs/aar/android-sdk-release.aar \ + "build/release/pixdot-android-$release_version.aar" + ( + cd web-sdk + npm ci + npm exec -- tsc -p tsconfig.json + npm pack --pack-destination ../build/release + ) + tar \ + --transform "s,^,pixdot-core-$release_version/," \ + -czf "build/release/pixdot-core-$release_version.tar.gz" \ + CMakeLists.txt LICENSE cmake core + + - name: Publish Android package + env: + GITHUB_ACTOR: ${{ github.actor }} + GITHUB_TOKEN: ${{ github.token }} + run: | + release_version="${RELEASE_TAG#v}" + pom_url="https://maven.pkg.github.com/$GITHUB_REPOSITORY/io/github/oxyroid/pixdot-android/$release_version/pixdot-android-$release_version.pom" + if curl --fail --silent \ + --user "$GITHUB_ACTOR:$GITHUB_TOKEN" \ + "$pom_url" >/dev/null; then + echo "Android package $release_version already exists" + else + ./gradlew :android-sdk:publishReleasePublicationToGitHubPackagesRepository + fi + + - name: Publish Web package to GitHub Packages + env: + NODE_AUTH_TOKEN: ${{ github.token }} + run: | + release_version="${RELEASE_TAG#v}" + package="@oxyroid/pixdot@$release_version" + if npm view "$package" version \ + --registry https://npm.pkg.github.com >/dev/null 2>&1; then + echo "Web package $release_version already exists" + else + npm publish \ + "build/release/oxyroid-pixdot-$release_version.tgz" \ + --tag incubating + fi + + - uses: actions/setup-node@v7 + if: ${{ env.NPM_TOKEN != '' }} + with: + node-version: "24" + registry-url: https://registry.npmjs.org + scope: "@oxyroid" + + - name: Publish Web package to npmjs + if: ${{ env.NPM_TOKEN != '' }} + env: + NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }} + run: | + release_version="${RELEASE_TAG#v}" + package="@oxyroid/pixdot@$release_version" + if npm view "$package" version \ + --registry https://registry.npmjs.org >/dev/null 2>&1; then + echo "Web package $release_version already exists on npmjs" + else + npm publish \ + "build/release/oxyroid-pixdot-$release_version.tgz" \ + --registry https://registry.npmjs.org \ + --tag incubating \ + --access public \ + --provenance + fi + + - name: Create GitHub prerelease + env: + GH_TOKEN: ${{ github.token }} + run: | + release_version="${RELEASE_TAG#v}" + ( + cd build/release + sha256sum \ + "pixdot-android-$release_version.aar" \ + "oxyroid-pixdot-$release_version.tgz" \ + "pixdot-core-$release_version.tar.gz" \ + > SHA256SUMS + ) + if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then + gh release upload "$RELEASE_TAG" build/release/* --clobber + else + gh release create "$RELEASE_TAG" \ + build/release/* \ + --generate-notes \ + --prerelease \ + --title "PixDot Protocol $release_version" + fi diff --git a/README.md b/README.md index 7ba5052..d7bca51 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A portable protocol library and BLE SDKs for compatible smart bead boards. > [!IMPORTANT] > This project is incubating. Protocol coverage and public APIs may change > before the first stable release. Incubating builds use prerelease tags such -> as `v0.3.0-incubating.1`. +> as `v0.3.0-incubating.2`. ## Packages @@ -20,6 +20,12 @@ A portable protocol library and BLE SDKs for compatible smart bead boards. - `@oxyroid/pixdot`: Web Bluetooth transport backed by the C core through WASM. - [Protocol reference](docs/protocol.md) +## Releases + +Incubating releases provide the Android AAR, Web npm tarball, portable C core +and checksums on [GitHub Releases](https://github.com/oxyroid/pixdot-protocol/releases). +Android and Web packages are also published to GitHub Packages after CI passes. + ## Architecture `core` is the only protocol implementation. It owns packet encoding, CRC, diff --git a/README.zh-CN.md b/README.zh-CN.md index 6e118bd..66afcfc 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -9,7 +9,7 @@ > [!IMPORTANT] > 本项目仍在孵化,首个稳定版本发布前,协议覆盖范围和公开 API 可能调整。 -> 孵化版本使用 `v0.3.0-incubating.1` 形式的预发布 tag。 +> 孵化版本使用 `v0.3.0-incubating.2` 形式的预发布 tag。 ## 组件 @@ -19,6 +19,12 @@ - `@oxyroid/pixdot`:通过 WASM 使用 C Core 的 Web Bluetooth 传输层。 - [协议参考](docs/protocol.zh-CN.md) +## 发布产物 + +孵化版本会在 [GitHub Releases](https://github.com/oxyroid/pixdot-protocol/releases) +提供 Android AAR、Web npm 压缩包、可移植 C Core 与校验和。CI 通过后也会将 +Android 和 Web 包发布到 GitHub Packages。 + ## 架构 `core` 是唯一的协议实现,负责数据包编码、CRC、分帧与响应解析。Android、 diff --git a/android-sdk/README.md b/android-sdk/README.md index f9432d0..43296ba 100644 --- a/android-sdk/README.md +++ b/android-sdk/README.md @@ -10,9 +10,17 @@ The library manifest declares the required BLE permissions. The caller must grant the permissions applicable to the device's Android version before using the scanner or client. -## Add the AAR +## Add the SDK -Build the release artifact: +Download `pixdot-android-0.3.0-incubating.2.aar` from the +[incubating release](https://github.com/oxyroid/pixdot-protocol/releases/tag/v0.3.0-incubating.2), +or use `io.github.oxyroid:pixdot-android:0.3.0-incubating.2` from the repository: + +```text +https://maven.pkg.github.com/oxyroid/pixdot-protocol +``` + +To build the AAR locally: ```sh ANDROID_HOME=/path/to/android-sdk ./gradlew :android-sdk:assembleRelease diff --git a/android-sdk/README.zh-CN.md b/android-sdk/README.zh-CN.md index bebdee3..1e754a4 100644 --- a/android-sdk/README.zh-CN.md +++ b/android-sdk/README.zh-CN.md @@ -9,9 +9,17 @@ 库清单已声明 BLE 所需权限。调用扫描器或客户端前,调用方须授予当前 Android 版本适用的权限。 -## 添加 AAR +## 添加 SDK -构建 release 产物: +从[孵化版本](https://github.com/oxyroid/pixdot-protocol/releases/tag/v0.3.0-incubating.2) +下载 `pixdot-android-0.3.0-incubating.2.aar`,或从以下仓库使用 +`io.github.oxyroid:pixdot-android:0.3.0-incubating.2`: + +```text +https://maven.pkg.github.com/oxyroid/pixdot-protocol +``` + +本地构建 AAR: ```sh ANDROID_HOME=/path/to/android-sdk ./gradlew :android-sdk:assembleRelease diff --git a/android-sdk/build.gradle.kts b/android-sdk/build.gradle.kts index 4060f3f..b6b3e23 100644 --- a/android-sdk/build.gradle.kts +++ b/android-sdk/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "io.github.oxyroid" -version = "0.3.0-incubating.1" +version = "0.3.0-incubating.2" android { namespace = "io.github.oxyroid.pixdot" @@ -56,6 +56,19 @@ dependencies { testImplementation("junit:junit:4.13.2") } +publishing { + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/oxyroid/pixdot-protocol") + credentials { + username = System.getenv("GITHUB_ACTOR") ?: "github" + password = System.getenv("GITHUB_TOKEN") ?: "" + } + } + } +} + afterEvaluate { publishing { publications { diff --git a/ios-sdk/README.md b/ios-sdk/README.md index 44008d0..565d2f1 100644 --- a/ios-sdk/README.md +++ b/ios-sdk/README.md @@ -5,7 +5,7 @@ The Swift package provides scanning, CoreBluetooth transport and `async/await` commands. Protocol operations run in the repository's C core. -> This SDK is incubating. Pin `v0.3.0-incubating.1` when adding the package. +> This SDK is incubating. Pin `v0.3.0-incubating.2` when adding the package. ## Add the package diff --git a/ios-sdk/README.zh-CN.md b/ios-sdk/README.zh-CN.md index e5cb7cb..b88f4fd 100644 --- a/ios-sdk/README.zh-CN.md +++ b/ios-sdk/README.zh-CN.md @@ -5,7 +5,7 @@ Swift Package 提供设备扫描、CoreBluetooth 传输和 `async/await` 命令。协议操作 由仓库中的 C Core 执行。 -> SDK 仍在孵化,添加 Package 时请固定到 `v0.3.0-incubating.1`。 +> SDK 仍在孵化,添加 Package 时请固定到 `v0.3.0-incubating.2`。 ## 添加 Package diff --git a/scripts/verify-release-tag.sh b/scripts/verify-release-tag.sh new file mode 100755 index 0000000..d707f0d --- /dev/null +++ b/scripts/verify-release-tag.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -euo pipefail + +release_tag="${1:-}" +if [[ ! "$release_tag" =~ ^v([0-9]+\.[0-9]+\.[0-9]+-incubating\.[0-9]+)$ ]]; then + echo "Invalid incubating release tag: $release_tag" >&2 + exit 1 +fi + +release_version="${BASH_REMATCH[1]}" +native_version="${release_version%%-*}" +android_version="$( + sed -n 's/^version = "\(.*\)"/\1/p' android-sdk/build.gradle.kts +)" +web_version="$(node -p "require('./web-sdk/package.json').version")" +cmake_version="$( + sed -nE \ + 's/^project\(PixDotProtocol VERSION ([0-9]+\.[0-9]+\.[0-9]+).*$/\1/p' \ + CMakeLists.txt +)" + +[[ "$android_version" == "$release_version" ]] || { + echo "Android version $android_version does not match $release_version" >&2 + exit 1 +} +[[ "$web_version" == "$release_version" ]] || { + echo "Web version $web_version does not match $release_version" >&2 + exit 1 +} +[[ "$cmake_version" == "$native_version" ]] || { + echo "CMake version $cmake_version does not match $native_version" >&2 + exit 1 +} + +echo "Release versions match $release_tag" diff --git a/web-sdk/README.md b/web-sdk/README.md index 3d5344a..b320ff8 100644 --- a/web-sdk/README.md +++ b/web-sdk/README.md @@ -11,6 +11,12 @@ The SDK requires a browser with Web Bluetooth and a secure context. The target GATT service UUID is required because browsers only expose services declared during device selection. +## Install + +```sh +npm install https://github.com/oxyroid/pixdot-protocol/releases/download/v0.3.0-incubating.2/oxyroid-pixdot-0.3.0-incubating.2.tgz +``` + ## Connect ```ts diff --git a/web-sdk/README.zh-CN.md b/web-sdk/README.zh-CN.md index 02e0922..629bfba 100644 --- a/web-sdk/README.zh-CN.md +++ b/web-sdk/README.zh-CN.md @@ -10,6 +10,12 @@ Bluetooth 传输和类型化 API 绑定。 SDK 需要支持 Web Bluetooth 的浏览器和安全上下文。连接时必须提供目标 GATT service UUID,因为浏览器只会开放设备选择阶段声明的 service。 +## 安装 + +```sh +npm install https://github.com/oxyroid/pixdot-protocol/releases/download/v0.3.0-incubating.2/oxyroid-pixdot-0.3.0-incubating.2.tgz +``` + ## 连接 ```ts diff --git a/web-sdk/package-lock.json b/web-sdk/package-lock.json index 83aebf1..02158b0 100644 --- a/web-sdk/package-lock.json +++ b/web-sdk/package-lock.json @@ -1,12 +1,12 @@ { "name": "@oxyroid/pixdot", - "version": "0.3.0-incubating.1", + "version": "0.3.0-incubating.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@oxyroid/pixdot", - "version": "0.3.0-incubating.1", + "version": "0.3.0-incubating.2", "license": "Apache-2.0", "devDependencies": { "@types/web-bluetooth": "0.0.21", diff --git a/web-sdk/package.json b/web-sdk/package.json index 390f89e..a6f3a7e 100644 --- a/web-sdk/package.json +++ b/web-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@oxyroid/pixdot", - "version": "0.3.0-incubating.1", + "version": "0.3.0-incubating.2", "description": "Web Bluetooth SDK for PixDot smart bead boards", "type": "module", "sideEffects": false,