Skip to content

Commit 4f9ad8a

Browse files
Setup a CI to push generated bindings to a dedicated branch (#60)
1 parent 78bca0c commit 4f9ad8a

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

.github/workflows/test.yml

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ on:
99
branches:
1010
- main
1111
- master
12+
# Run this once per three days
13+
schedule:
14+
- cron: '29 17 */3 * *'
15+
# This can also manually run
16+
workflow_dispatch: {}
1217

1318
jobs:
1419

@@ -171,7 +176,7 @@ jobs:
171176
(matrix.config.emit-bindings == 'true'))
172177
uses: actions/upload-artifact@main
173178
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 }}
175180
path: generated_bindings
176181

177182
# Run tests again using different bindings
@@ -269,5 +274,49 @@ jobs:
269274
}
270275
env:
271276
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
272287

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

MAINTAINERS_GUIDE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Precomputed bindings
2+
3+
### How to update the precomputed bindings?
4+
5+
The precomputed bindings are continuously updated on `generated_bindings` branch,
6+
but it doesn't propagate into `master` branch automatically; when we need to
7+
reflect the recent changes, create a pull request from `generated_bindings` branch.
8+
This link is the shortcut for this:
9+
10+
<https://github.com/extendr/libR-sys/compare/master...generated_bindings?expand=1>
11+
12+
### How to address conflicts in `generated_bindings`?
13+
14+
You can just delete the branch. Since the GitHub Actions CI runs periodically,
15+
it will be created again from the latest `master` in a few days (or you can
16+
retrigger the build manually).

0 commit comments

Comments
 (0)