Skip to content

Setup a CI to push generated bindings to a dedicated branch #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ on:
branches:
- main
- master
# Run this once per three days
schedule:
- cron: '29 17 */3 * *'
# This can also manually run
workflow_dispatch: {}

jobs:

Expand Down Expand Up @@ -171,7 +176,7 @@ jobs:
(matrix.config.emit-bindings == 'true'))
uses: actions/upload-artifact@main
with:
name: ${{ matrix.config.os }} (R-${{ matrix.config.r }} rust-${{ matrix.config.rust-version }}) generated bindings
name: generated_binding-${{ matrix.config.os }}-R-${{ matrix.config.r }}-rust-${{ matrix.config.rust-version }}
path: generated_bindings

# Run tests again using different bindings
Expand Down Expand Up @@ -269,5 +274,49 @@ jobs:
}
env:
NO_TEST_TARGETS: ${{ join(matrix.config.no-test-targets, ',') }}

# Gather the generated bindings and push them to generated_bindings branch.
# If we need to update the bindings, create a pull request from that branch.
commit_generated_bindings:
needs: test_with_bindgen
runs-on: ubuntu-latest
# Do not run this on pull request
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2


- uses: actions/download-artifact@v2

- name: Push the generated bindings
run: |
# 1) If there's already generated_bindings branch, checkout it.
# 2) If generated_binding branch is not created, create it from the default branch.
if git ls-remote --exit-code --heads origin generated_bindings 2>&1 >/dev/null; then
git fetch origin --no-tags --prune --depth=1 generated_bindings
git checkout generated_bindings
else
git switch -c generated_bindings
fi

# Update or add the bindings
cp generated_binding-*/*.rs bindings/

# Replace the default bindings
cd bindings
for x in linux-x86_64 macos-aarch64 macos-x86_64 windows-x86 windows-x86_64; do
# Choose the newest version except for devel
ln --force -s "$(ls -1 ./bindings-${x}-*.rs | grep -v devel | sort | tail -1)" ./bindings-${x}.rs
done
cd ..

# detect changes (the code is derived from https://stackoverflow.com/a/3879077)
git add bindings/
git update-index --refresh
if ! git diff-index --quiet HEAD -- bindings/; then
git config --local user.name "${GITHUB_ACTOR}"
git config --local user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git commit -m "Update bindings [skip ci]"
git push origin generated_bindings
else
echo "No changes"
fi
16 changes: 16 additions & 0 deletions MAINTAINERS_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Precomputed bindings

### How to update the precomputed bindings?

The precomputed bindings are continuously updated on `generated_bindings` branch,
but it doesn't propagate into `master` branch automatically; when we need to
reflect the recent changes, create a pull request from `generated_bindings` branch.
This link is the shortcut for this:

<https://github.com/extendr/libR-sys/compare/master...generated_bindings?expand=1>

### How to address conflicts in `generated_bindings`?

You can just delete the branch. Since the GitHub Actions CI runs periodically,
it will be created again from the latest `master` in a few days (or you can
retrigger the build manually).