Skip to content

Commit e66386c

Browse files
authored
chore: try fix CI for forks (#432)
1 parent 9c5e216 commit e66386c

File tree

5 files changed

+85
-54
lines changed

5 files changed

+85
-54
lines changed

.github/workflows/bencher_on_pr_or_fork.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77
jobs:
88
benchmark_fork_pr_branch:
9-
name: Run Fork PR Benchmarks
9+
name: Run PR Benchmarks
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4

.github/workflows/bevy_mod_scripting.yml

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,21 @@ jobs:
7575
jq -c . matrix.json > matrix-one-line.json
7676
echo "matrix=$(cat matrix-one-line.json)" >> $GITHUB_OUTPUT
7777
78+
check-is-fork:
79+
runs-on: ubuntu-latest
80+
outputs:
81+
is_fork: ${{ steps.check-fork.outputs.is_fork }}
82+
steps:
83+
- name: Check if fork
84+
id: check-fork
85+
run: |
86+
if [ "${{ github.repository }}" != "${{ github.event.pull_request.head.repo.full_name }}" ]; then
87+
echo "is_fork=true" >> $GITHUB_OUTPUT
88+
else
89+
echo "is_fork=false" >> $GITHUB_OUTPUT
90+
fi
7891
check:
79-
needs: [check-needs-run, generate-job-matrix]
92+
needs: [check-needs-run, generate-job-matrix, check-is-fork]
8093
permissions:
8194
pull-requests: write
8295
contents: write
@@ -103,49 +116,49 @@ jobs:
103116
# # run: |
104117
# # sudo rm -rf /usr/share/dotnet; sudo rm -rf /opt/ghc; sudo rm -rf "/usr/local/share/boost"; sudo rm -rf "$AGENT_TOOLSDIRECTORY"
105118
- name: Checkout
106-
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' }}
119+
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' && (matrix.run_args.run_on_forks == 'true' || needs.check-is-fork.is_fork != 'true') }}
107120
uses: actions/checkout@v4
108121
- uses: actions-rs/toolchain@v1
109-
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' }}
122+
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' && (matrix.run_args.run_on_forks == 'true' || needs.check-is-fork.is_fork != 'true') }}
110123
with:
111124
toolchain: stable
112125
override: true
113126
- name: Rust Cache
114-
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' }}
127+
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' && (matrix.run_args.run_on_forks == 'true' || needs.check-is-fork.is_fork != 'true') }}
115128
uses: Swatinem/rust-cache@v2.7.7
116129
with:
117130
# reasoning: we want to cache xtask, most of the jobs in the matrix will be sped up a good bit thanks to that
118131
save-if: ${{ github.ref == 'refs/heads/main' }}
119132
cache-all-crates: true
120133

121134
- name: Setup
122-
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' }}
135+
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' && (matrix.run_args.run_on_forks == 'true' || needs.check-is-fork.is_fork != 'true') }}
123136
run: |
124137
cargo xtask init
125138
126139
- name: Setup GPU Drivers
127-
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' && matrix.run_args.requires_gpu }}
140+
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' && (matrix.run_args.run_on_forks == 'true' || needs.check-is-fork.is_fork != 'true') && matrix.run_args.requires_gpu }}
128141
run: |
129142
sudo add-apt-repository ppa:kisak/turtle -y
130143
sudo apt-get install --no-install-recommends libxkbcommon-x11-0 xvfb libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers
131144
- name: Check
132-
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' && !matrix.run_args.requires_gpu }}
145+
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' && (matrix.run_args.run_on_forks == 'true' || needs.check-is-fork.is_fork != 'true') && !matrix.run_args.requires_gpu }}
133146
run: |
134147
${{ matrix.run_args.command }}
135148
- name: Check With virtual X11 server
136-
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' && matrix.run_args.requires_gpu }}
149+
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' && (matrix.run_args.run_on_forks == 'true' || needs.check-is-fork.is_fork != 'true') && matrix.run_args.requires_gpu }}
137150
run: |
138151
xvfb-run ${{ matrix.run_args.command }}
139152
140153
- name: Upload coverage artifact
141-
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' && matrix.run_args.generates_coverage }}
154+
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' && (matrix.run_args.run_on_forks == 'true' || needs.check-is-fork.is_fork != 'true') && matrix.run_args.generates_coverage }}
142155
uses: actions/upload-artifact@v4
143156
with:
144157
name: code-coverage-report
145158
path: target/coverage/html/
146159

147160
- name: Update coverage badge
148-
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' && matrix.run_args.generates_coverage }}
161+
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' && (matrix.run_args.run_on_forks == 'true' || needs.check-is-fork.is_fork != 'true') && matrix.run_args.generates_coverage }}
149162
continue-on-error: true
150163
run: |
151164
git checkout -b chore/_update-coverage-badge || git checkout chore/_update-coverage-badge
@@ -163,45 +176,4 @@ jobs:
163176
sed -n 's/.*pull\/\([0-9]*\).*/\1/p' pr.txt > pr_number.txt
164177
PRNUMBER=$(cat pr_number.txt)
165178
gh pr merge $PRNUMBER --squash
166-
fi
167-
generate_bindings:
168-
name: Bindings - Synchronise
169-
permissions:
170-
contents: write
171-
pull-requests: write
172-
runs-on: ubuntu-latest
173-
if: github.repository_owner == 'makspll'
174-
steps:
175-
- name: Checkout
176-
uses: actions/checkout@v4
177-
with:
178-
ref: ${{ github.head_ref || github.ref_name }}
179-
- name: Rust Cache
180-
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' }}
181-
uses: Swatinem/rust-cache@v2.7.7
182-
with:
183-
# reasoning: we want to cache xtask, most of the jobs in the matrix will be sped up a good bit thanks to that
184-
save-if: ${{ github.ref == 'refs/heads/main' }}
185-
cache-all-crates: true
186-
- name: Setup Bot GitHub Credentials
187-
run: |
188-
git config user.name "github-actions[bot]"
189-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
190-
- name: Setup
191-
run: |
192-
cargo xtask init
193-
- name: Generate Bindings
194-
run: |
195-
cargo xtask codegen
196-
- name: Check for changes
197-
id: check_changes
198-
run: |
199-
if [[ -n $(git status --porcelain) ]]; then
200-
echo "changes=true" >> "$GITHUB_OUTPUT";
201-
fi
202-
- name: Commit Changes
203-
if: steps.check_changes.outputs.changes
204-
run: |
205-
git add -A
206-
git commit -m "chore(codegen): update bevy bindings"
207-
git push
179+
fi
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- "**"
5+
6+
name: Synchronize Bindings
7+
8+
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
12+
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.event.pull_request.number || github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
generate_bindings:
17+
name: Synchronise Bindings (Not Fork)
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
runs-on: ubuntu-latest
22+
if: github.event.pull_request.head.repo.full_name == github.repository
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
with:
27+
ref: ${{ github.head_ref || github.ref_name }}
28+
- name: Rust Cache
29+
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' }}
30+
uses: Swatinem/rust-cache@v2.7.7
31+
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
33+
save-if: ${{ github.ref == 'refs/heads/main' }}
34+
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"
39+
- name: Setup
40+
run: |
41+
cargo xtask init
42+
- name: Generate Bindings
43+
run: |
44+
cargo xtask codegen
45+
- name: Check for changes
46+
id: check_changes
47+
run: |
48+
if [[ -n $(git status --porcelain) ]]; then
49+
echo "changes=true" >> "$GITHUB_OUTPUT";
50+
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

crates/bevy_mod_scripting_functions/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(missing_docs)]
22

3-
use ::bevy::prelude::*;
3+
use bevy::prelude::*;
44
pub mod bevy_bindings;
55
pub mod core;
66
pub use core::*;

crates/xtask/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ impl App {
457457
),
458458
os: os.to_string(),
459459
generates_coverage: self.global_args.coverage,
460+
run_on_forks: !matches!(self.subcmd, Xtasks::Bencher { .. } | Xtasks::Bench { .. }),
460461
requires_gpu: matches!(self.subcmd, Xtasks::Docs { .. }),
461462
}
462463
}
@@ -734,6 +735,8 @@ struct CiMatrixRow {
734735
generates_coverage: bool,
735736
/// If this step requires a gpu
736737
requires_gpu: bool,
738+
/// if it should run on fork PR's
739+
run_on_forks: bool,
737740
}
738741

739742
impl Xtasks {

0 commit comments

Comments
 (0)