-
Notifications
You must be signed in to change notification settings - Fork 3
157 lines (129 loc) · 5.98 KB
/
Copy pathupdate-bindings.yml
File metadata and controls
157 lines (129 loc) · 5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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