|
9 | 9 | branches:
|
10 | 10 | - main
|
11 | 11 | - master
|
| 12 | + # Run this once per three days |
| 13 | + schedule: |
| 14 | + - cron: '29 17 */3 * *' |
| 15 | + # This can also manually run |
| 16 | + workflow_dispatch: {} |
12 | 17 |
|
13 | 18 | jobs:
|
14 | 19 |
|
@@ -171,7 +176,7 @@ jobs:
|
171 | 176 | (matrix.config.emit-bindings == 'true'))
|
172 | 177 | uses: actions/upload-artifact@main
|
173 | 178 | with:
|
174 |
| - name: ${{ matrix.config.os }} (R-${{ matrix.config.r }} rust-${{ matrix.config.rust-version }}) generated bindings |
| 179 | + name: generated_binding-${{ matrix.config.os }}-R-${{ matrix.config.r }}-rust-${{ matrix.config.rust-version }} |
175 | 180 | path: generated_bindings
|
176 | 181 |
|
177 | 182 | # Run tests again using different bindings
|
@@ -269,5 +274,49 @@ jobs:
|
269 | 274 | }
|
270 | 275 | env:
|
271 | 276 | NO_TEST_TARGETS: ${{ join(matrix.config.no-test-targets, ',') }}
|
| 277 | + |
| 278 | + # Gather the generated bindings and push them to generated_bindings branch. |
| 279 | + # If we need to update the bindings, create a pull request from that branch. |
| 280 | + commit_generated_bindings: |
| 281 | + needs: test_with_bindgen |
| 282 | + runs-on: ubuntu-latest |
| 283 | + # Do not run this on pull request |
| 284 | + if: github.ref == 'refs/heads/master' |
| 285 | + steps: |
| 286 | + - uses: actions/checkout@v2 |
272 | 287 |
|
273 |
| - |
| 288 | + - uses: actions/download-artifact@v2 |
| 289 | + |
| 290 | + - name: Push the generated bindings |
| 291 | + run: | |
| 292 | + # 1) If there's already generated_bindings branch, checkout it. |
| 293 | + # 2) If generated_binding branch is not created, create it from the default branch. |
| 294 | + if git ls-remote --exit-code --heads origin generated_bindings 2>&1 >/dev/null; then |
| 295 | + git fetch origin --no-tags --prune --depth=1 generated_bindings |
| 296 | + git checkout generated_bindings |
| 297 | + else |
| 298 | + git switch -c generated_bindings |
| 299 | + fi |
| 300 | +
|
| 301 | + # Update or add the bindings |
| 302 | + cp generated_binding-*/*.rs bindings/ |
| 303 | +
|
| 304 | + # Replace the default bindings |
| 305 | + cd bindings |
| 306 | + for x in linux-x86_64 macos-aarch64 macos-x86_64 windows-x86 windows-x86_64; do |
| 307 | + # Choose the newest version except for devel |
| 308 | + ln --force -s "$(ls -1 ./bindings-${x}-*.rs | grep -v devel | sort | tail -1)" ./bindings-${x}.rs |
| 309 | + done |
| 310 | + cd .. |
| 311 | +
|
| 312 | + # detect changes (the code is derived from https://stackoverflow.com/a/3879077) |
| 313 | + git add bindings/ |
| 314 | + git update-index --refresh |
| 315 | + if ! git diff-index --quiet HEAD -- bindings/; then |
| 316 | + git config --local user.name "${GITHUB_ACTOR}" |
| 317 | + git config --local user.email "${GITHUB_ACTOR}@users.noreply.github.com" |
| 318 | + git commit -m "Update bindings [skip ci]" |
| 319 | + git push origin generated_bindings |
| 320 | + else |
| 321 | + echo "No changes" |
| 322 | + fi |
0 commit comments