Skip to content

Commit c8a4e6e

Browse files
committed
Test making this work from forks
1 parent ed14590 commit c8a4e6e

File tree

2 files changed

+137
-10
lines changed

2 files changed

+137
-10
lines changed

.github/workflows/build_and_test.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,6 @@ jobs:
7676
has_code_changes: ${{ needs.check_code_changes.outputs.has_code_changes }}
7777
if: github.event_name == 'push' || github.event_name == 'pull_request'
7878

79-
test-torchprime:
80-
name: "torchprime tests"
81-
uses: ./.github/workflows/_torchprime_ci.yml
82-
needs: [build-torch-xla, check_code_changes]
83-
with:
84-
timeout-minutes: 100
85-
has_code_changes: ${{ needs.check_code_changes.outputs.has_code_changes }}
86-
if: github.event_name == 'push' || github.event_name == 'pull_request'
87-
secrets: inherit
88-
8979
push-docs:
9080
name: "Build docs"
9181
uses: ./.github/workflows/_docs.yml
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: Test torchprime
2+
on:
3+
pull_request_target:
4+
branches:
5+
- master
6+
- r[0-9]+.[0-9]+
7+
pull_request: # TODO: Remove before merging
8+
branches:
9+
- master
10+
- r[0-9]+.[0-9]+
11+
push:
12+
branches:
13+
- master
14+
- r[0-9]+.[0-9]+
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
wait-for-build:
22+
name: Wait for build to complete
23+
runs-on: ubuntu-latest
24+
if: github.event_name == 'push' || github.event_name == 'pull_request_target' || github.event_name == 'pull_request'
25+
outputs:
26+
has_code_changes: ${{ steps.check_changes.outputs.has_code_changes }}
27+
workflow_run_id: ${{ steps.get_run_id.outputs.run_id }}
28+
steps:
29+
- name: Wait on Build and test workflow
30+
uses: lewagon/[email protected]
31+
with:
32+
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
33+
check-name: 'Build PyTorch/XLA'
34+
repo-token: ${{ secrets.GITHUB_TOKEN }}
35+
wait-interval: 10
36+
running-workflow-name: 'Test torchprime'
37+
38+
# Get the workflow run ID for artifact download
39+
- name: Get workflow run ID
40+
id: get_run_id
41+
uses: actions/github-script@v7
42+
with:
43+
script: |
44+
const owner = context.repo.owner;
45+
const repo = context.repo.repo;
46+
const ref = context.eventName === 'pull_request_target'
47+
? context.payload.pull_request.head.sha
48+
: context.sha;
49+
50+
// Get workflow runs for this commit
51+
const runs = await github.rest.actions.listWorkflowRunsForRepo({
52+
owner,
53+
repo,
54+
head_sha: ref,
55+
status: 'completed',
56+
per_page: 50
57+
});
58+
59+
// Find the "Build and test" workflow run
60+
const buildRun = runs.data.workflow_runs.find(run =>
61+
run.name === 'Build and test' && run.head_sha === ref
62+
);
63+
64+
if (buildRun) {
65+
core.setOutput('run_id', buildRun.id);
66+
console.log(`Found Build and test workflow run: ${buildRun.id}`);
67+
} else {
68+
core.setFailed('Could not find Build and test workflow run');
69+
}
70+
71+
# Check if the build workflow detected code changes
72+
- name: Check for code changes from build workflow
73+
id: check_changes
74+
uses: actions/github-script@v7
75+
with:
76+
script: |
77+
const owner = context.repo.owner;
78+
const repo = context.repo.repo;
79+
const ref = context.eventName === 'pull_request_target'
80+
? context.payload.pull_request.head.sha
81+
: context.sha;
82+
83+
// Get the check runs for this commit
84+
const checkRuns = await github.rest.checks.listForRef({
85+
owner,
86+
repo,
87+
ref,
88+
check_name: 'Check Code Changes'
89+
});
90+
91+
// Default to running if we can't determine
92+
let hasCodeChanges = 'true';
93+
94+
if (checkRuns.data.check_runs.length > 0) {
95+
const checkRun = checkRuns.data.check_runs[0];
96+
// Try to parse the conclusion or output to determine if code changes exist
97+
if (checkRun.conclusion === 'skipped' ||
98+
(checkRun.output && checkRun.output.text &&
99+
checkRun.output.text.includes('No code changes'))) {
100+
hasCodeChanges = 'false';
101+
}
102+
}
103+
104+
core.setOutput('has_code_changes', hasCodeChanges);
105+
106+
# Download artifacts from the build workflow before calling torchprime tests
107+
download-artifacts:
108+
name: Download build artifacts
109+
needs: wait-for-build
110+
runs-on: ubuntu-latest
111+
if: needs.wait-for-build.outputs.has_code_changes == 'true'
112+
steps:
113+
- name: Download artifacts from build workflow
114+
uses: actions/download-artifact@v4
115+
with:
116+
name: torch-xla-wheels
117+
path: /tmp/wheels/
118+
run-id: ${{ needs.wait-for-build.outputs.workflow_run_id }}
119+
github-token: ${{ secrets.GITHUB_TOKEN }}
120+
121+
# Re-upload artifacts so they're available to the called workflow
122+
- name: Upload artifacts for torchprime workflow
123+
uses: actions/upload-artifact@v4
124+
with:
125+
name: torch-xla-wheels
126+
path: /tmp/wheels/
127+
retention-days: 1
128+
129+
test-torchprime:
130+
name: "torchprime tests"
131+
needs: [wait-for-build, download-artifacts]
132+
if: needs.wait-for-build.result == 'success' && needs.wait-for-build.outputs.has_code_changes == 'true'
133+
uses: ./.github/workflows/_torchprime_ci.yml
134+
with:
135+
timeout-minutes: 100
136+
has_code_changes: ${{ needs.wait-for-build.outputs.has_code_changes }}
137+
secrets: inherit

0 commit comments

Comments
 (0)