Skip to content

Commit 74ad923

Browse files
committed
Add CI workflow to check c10 is synced with PyTorch
This script checks that all files in our c10 copy are in sync with our pinned version of PyTorch. Test Plan: 1) detected us being out of sync when I wrote this PR 2) CI to run it and make sure that we are clean now ghstack-source-id: f19bb5c ghstack-comment-id: 2825037146 Pull-Request-resolved: #10403
1 parent 370cbfc commit 74ad923

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

.ci/scripts/check_c10_sync.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -exu
9+
ls pytorch/.git || git clone https://github.com/pytorch/pytorch.git
10+
pushd pytorch
11+
git checkout "$(< ../.ci/docker/ci_commit_pins/pytorch.txt)"
12+
popd
13+
"$(dirname "${BASH_SOURCE[0]}")"/diff_c10_mirror_with_pytorch.sh

.ci/scripts/compare_dirs.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -eux
9+
10+
# Check if dir1's files are also found in dir2 with the same
11+
# contents. Exempt files named BUCK, CMakeLists.txt, TARGETS, or
12+
# targets.bzl.
13+
14+
if [ $# -ne 2 ]; then
15+
echo "Usage: $0 dir1 dir2" >&2
16+
exit 1
17+
fi
18+
dir1="$1"
19+
dir2="$2"
20+
21+
if [ ! -d "$dir1" ] || [ ! -d "$dir2" ]; then
22+
echo "Error: Both directories must exist" >&2
23+
exit 1
24+
fi
25+
26+
while IFS= read -r -d '' file; do
27+
base=$(basename "$file")
28+
case "$base" in
29+
"BUCK"|"CMakeLists.txt"|"TARGETS"|"targets.bzl")
30+
continue
31+
;;
32+
esac
33+
# Construct the corresponding path in the second directory
34+
file2="$dir2/${file#$dir1/}"
35+
# Check if the corresponding file exists in the second directory
36+
if [ ! -f "$file2" ]; then
37+
echo "Error: File '$file' found in '$dir1' but not found in '$dir2'" >&2
38+
exit 1
39+
fi
40+
# Compare the contents of the two files using diff
41+
set +ex
42+
differences=$(diff -u -p "$file" "$file2")
43+
set -e # leave x off
44+
# If there are any differences, print an error message and exit with failure status
45+
if [ -n "$differences" ]; then
46+
echo "Error: Mismatch detected in file '$file':" >&2
47+
echo "$differences" >&2
48+
exit 1
49+
fi
50+
set -x
51+
done < <(find "$dir1" -type f -print0)
52+
# If no mismatches were found, exit with success status
53+
exit 0
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
$(dirname "${BASH_SOURCE[0]}")/compare_dirs.sh runtime/core/portable_type/c10/c10 pytorch/c10
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: check-c10-sync
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- .ci/docker/ci_commit_pins/pytorch.txt
7+
- .ci/scripts/compare_dirs.sh
8+
- .ci/scripts/diff_c10_mirror_with_pytorch.sh
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
check-c10-sync:
16+
permissions:
17+
id-token: write
18+
contents: read
19+
name: check-c10-sync
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v3
23+
with:
24+
fetch-depth: 0
25+
- name: Clone PyTorch
26+
run: |
27+
set -ex
28+
git clone https://github.com/pytorch/pytorch.git
29+
pushd pytorch || return
30+
git checkout "$(< ../.ci/docker/ci_commit_pins/pytorch.txt)"
31+
popd
32+
.ci/scripts/check_c10_sync.sh

0 commit comments

Comments
 (0)