Update Bindings #112
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Bindings | |
| on: | |
| schedule: | |
| - cron: "0 0 * * *" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| check-upstream: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| needs_update: ${{ steps.check.outputs.needs_update }} | |
| upstream_version: ${{ steps.check.outputs.upstream_version }} | |
| current_version: ${{ steps.check.outputs.current_version }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Get upstream MaaFramework version | |
| id: check | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| UPSTREAM_TAG=$(gh release list --repo MaaXYZ/MaaFramework \ | |
| --exclude-drafts \ | |
| --limit 1 \ | |
| --json tagName \ | |
| --jq '.[0].tagName') | |
| UPSTREAM_VERSION="${UPSTREAM_TAG#v}" | |
| CURRENT_VERSION=$(grep '^version = ' maa-framework-sys/Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') | |
| echo "upstream_version=$UPSTREAM_VERSION" >> $GITHUB_OUTPUT | |
| echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| echo "Upstream: $UPSTREAM_VERSION, Current: $CURRENT_VERSION" | |
| echo "Event: $GITHUB_EVENT_NAME" | |
| if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then | |
| echo "needs_update=true" >> $GITHUB_OUTPUT | |
| elif [ "$UPSTREAM_VERSION" != "$CURRENT_VERSION" ]; then | |
| echo "needs_update=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "needs_update=false" >> $GITHUB_OUTPUT | |
| fi | |
| update-bindings: | |
| needs: check-upstream | |
| if: needs.check-upstream.outputs.needs_update == 'true' | |
| runs-on: macos-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install dep | |
| run: | | |
| brew install llvm | |
| echo "LIBCLANG_PATH=$(brew --prefix llvm)/lib" >> $GITHUB_ENV | |
| - name: Download MaaFramework SDK from release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| TAG="v${{ needs.check-upstream.outputs.upstream_version }}" | |
| mkdir -p asset sdk install | |
| ASSET_NAME=$(gh release view "$TAG" --repo MaaXYZ/MaaFramework --json assets \ | |
| --jq '.assets[].name | select(((ascii_downcase | contains("mac")) or (ascii_downcase | contains("osx"))) and ((ascii_downcase | contains("arm64")) or (ascii_downcase | contains("aarch64"))))' \ | |
| | head -n 1) | |
| test -n "$ASSET_NAME" || (echo "No macOS arm64 asset found for $TAG" && exit 1) | |
| gh release download "$TAG" --repo MaaXYZ/MaaFramework --pattern "$ASSET_NAME" --dir asset | |
| FILE=$(find asset -type f | head -n 1) | |
| case "$FILE" in | |
| *.zip) unzip -q "$FILE" -d sdk ;; | |
| *.tar.gz|*.tgz) tar -xzf "$FILE" -C sdk ;; | |
| *.tar.xz) tar -xJf "$FILE" -C sdk ;; | |
| *) echo "Unsupported asset: $FILE"; exit 1 ;; | |
| esac | |
| ROOT=$(find sdk -mindepth 1 -maxdepth 1 -type d | head -n 1) | |
| [ -n "$ROOT" ] || ROOT=sdk | |
| cp -R "$ROOT"/. install/ | |
| - name: Update sys version in Cargo.toml | |
| run: | | |
| NEW_VERSION="${{ needs.check-upstream.outputs.upstream_version }}" | |
| sed -i '' "s/^version = \".*\"/version = \"$NEW_VERSION\"/" maa-framework-sys/Cargo.toml | |
| sed -i '' "s/maa-framework-sys = { path = \"maa-framework-sys\", version = \".*\" }/maa-framework-sys = { path = \"maa-framework-sys\", version = \"$NEW_VERSION\" }/" Cargo.toml | |
| - name: Regenerate bindings (Static) | |
| env: | |
| MAA_SDK_PATH: ${{ github.workspace }}/install | |
| run: | | |
| rm -rf target/debug/build/maa-framework-sys-* | |
| cargo build -p maa-framework-sys --features generate-bindings | |
| cp target/debug/build/maa-framework-sys-*/out/bindings.rs maa-framework-sys/src/bindings/static_bindings.rs | |
| - name: Regenerate dynamic bindings | |
| env: | |
| MAA_SDK_PATH: ${{ github.workspace }}/install | |
| run: | | |
| rm -rf target/debug/build/maa-framework-sys-* | |
| cargo build -p maa-framework-sys --features generate-bindings,dynamic | |
| for dir in target/debug/build/maa-framework-sys-*/out; do | |
| if [ -f "$dir/bindings.rs" ] && grep -q "CompositeLibrary" "$dir/bindings.rs"; then | |
| cp "$dir/bindings.rs" maa-framework-sys/src/bindings/dynamic_bindings.rs | |
| cp "$dir/shims.rs" maa-framework-sys/src/bindings/shims.rs | |
| break | |
| fi | |
| done | |
| - name: Check changes | |
| id: changes | |
| run: | | |
| if git diff --quiet; then | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create Pull Request | |
| if: steps.changes.outputs.has_changes == 'true' | |
| uses: peter-evans/create-pull-request@v6 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | |
| committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | |
| commit-message: "feat(sys): update bindings for MaaFramework v${{ needs.check-upstream.outputs.upstream_version }}" | |
| title: "feat(sys): update bindings for MaaFramework v${{ needs.check-upstream.outputs.upstream_version }}" | |
| body: | | |
| Automatically generated PR to update `maa-framework-sys` bindings. | |
| **Changes:** | |
| - Updated version: `${{ needs.check-upstream.outputs.current_version }}` → `${{ needs.check-upstream.outputs.upstream_version }}` | |
| - Regenerated FFI bindings (static and dynamic) | |
| Please review and merge to publish the new version. | |
| branch: update-sys-${{ needs.check-upstream.outputs.upstream_version }} | |
| delete-branch: true | |
| add-paths: | | |
| maa-framework-sys/** | |
| Cargo.toml | |
| Cargo.lock |