Skip to content

Commit 67c5a5d

Browse files
authored
chore: try make bindings sync work on forks (#437)
1 parent 92d99fd commit 67c5a5d

File tree

2 files changed

+71
-27
lines changed

2 files changed

+71
-27
lines changed
Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,51 @@
11
on:
22
pull_request:
3-
branches:
4-
- "**"
3+
types: [opened, reopened, edited, synchronize]
54

65
name: Synchronize Bindings
76

87
concurrency:
9-
# Use github.run_id on main branch
10-
# Use github.event.pull_request.number on pull requests, so it's unique per pull request
11-
# Use github.ref on other branches, so it's unique per branch
128
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.event.pull_request.number || github.ref }}
139
cancel-in-progress: true
1410

1511
jobs:
16-
generate_bindings:
17-
name: Synchronise Bindings (Not Fork)
18-
permissions:
19-
contents: write
20-
pull-requests: write
12+
generate_bindings:
13+
name: Generate Diff
2114
runs-on: ubuntu-latest
22-
if: github.event.pull_request.head.repo.full_name == github.repository
2315
steps:
2416
- name: Checkout
2517
uses: actions/checkout@v4
26-
with:
27-
ref: ${{ github.head_ref || github.ref_name }}
2818
- name: Rust Cache
29-
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' }}
3019
uses: Swatinem/[email protected]
3120
with:
32-
# reasoning: we want to cache xtask, most of the jobs in the matrix will be sped up a good bit thanks to that
3321
save-if: ${{ github.ref == 'refs/heads/main' }}
3422
cache-all-crates: true
35-
- name: Setup Bot GitHub Credentials
36-
run: |
37-
git config user.name "github-actions[bot]"
38-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
3923
- name: Setup
4024
run: |
4125
cargo xtask init
4226
- name: Generate Bindings
4327
run: |
4428
cargo xtask codegen
45-
- name: Check for changes
29+
- name: Check for changes and create diff
4630
id: check_changes
4731
run: |
4832
if [[ -n $(git status --porcelain) ]]; then
49-
echo "changes=true" >> "$GITHUB_OUTPUT";
33+
echo "changes=true" >> "$GITHUB_OUTPUT"
34+
git diff > bindings.diff
35+
echo "Diff created:"
36+
cat bindings.diff
37+
else
38+
echo "changes=false" >> "$GITHUB_OUTPUT"
5039
fi
51-
- name: Commit Changes
52-
if: steps.check_changes.outputs.changes
53-
run: |
54-
git add -A
55-
git commit -m "chore(codegen): update bevy bindings"
56-
git push
40+
- name: Upload Diff Artifact
41+
if: steps.check_changes.outputs.changes == 'true'
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: bindings.diff
45+
path: bindings.diff
46+
retention-days: 1
47+
- name: Upload GitHub Pull Request Event
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: event-bindings.json
51+
path: ${{ github.event_path }}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
on:
2+
workflow_run:
3+
workflows: [Synchronize Bindings]
4+
types: [completed]
5+
6+
name: Synchronize Bindings (Check Diff)
7+
8+
permissions: write-all
9+
10+
jobs:
11+
apply_fork_bindings:
12+
name: Apply Bindings (Fork)
13+
runs-on: ubuntu-latest
14+
if: github.event.workflow_run.conclusion == 'success'
15+
env:
16+
DIFF_ARTIFACT: bindings.diff
17+
PR_EVENT: event-bindings.json
18+
steps:
19+
- name: Download Benchmark Results
20+
uses: dawidd6/action-download-artifact@v6
21+
with:
22+
name: ${{ env.DIFF_ARTIFACT }}
23+
run_id: ${{ github.event.workflow_run.id }}
24+
- name: Download PR Event
25+
uses: dawidd6/action-download-artifact@v6
26+
with:
27+
name: ${{ env.PR_EVENT }}
28+
run_id: ${{ github.event.workflow_run.id }}
29+
- name: Export PR Event Data
30+
uses: actions/github-script@v6
31+
with:
32+
script: |
33+
let fs = require('fs');
34+
let prEvent = JSON.parse(fs.readFileSync(process.env.PR_EVENT, {encoding: 'utf8'}));
35+
core.exportVariable("PR_HEAD", prEvent.pull_request.head.ref);
36+
core.exportVariable("PR_BASE", prEvent.pull_request.base.ref);
37+
core.exportVariable("PR_BASE_SHA", prEvent.pull_request.base.sha);
38+
core.exportVariable("PR_NUMBER", prEvent.number);
39+
core.exportVariable("HEAD_REPO", prEvent.pull_request.head.repo.full_name);
40+
core.exportVariable("HEAD_REPO_URL", prEvent.pull_request.head.repo.git_url);
41+
- name: Fail PR With URL
42+
uses: actions/github-script@v6
43+
with:
44+
script: |
45+
core.setFailed(`Running `cargo xtask codegen` produces changes in the bindings, please make sure to run this command locally and commit the changes to the PR.`);
46+
47+
48+
49+

0 commit comments

Comments
 (0)