Skip to content

Commit e9fad49

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: ca04bfa2bfd9ed4c598f4431e3ebdddf8e510c7b ghstack-comment-id: 2825037146 Pull-Request-resolved: #10403
1 parent 80fc3fc commit e9fad49

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

.ci/scripts/check_c10_sync.sh

+13
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

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
exit_status=0
27+
while IFS= read -r -d '' file; do
28+
base=$(basename "$file")
29+
case "$base" in
30+
"BUCK"|"CMakeLists.txt"|"TARGETS"|"targets.bzl")
31+
continue
32+
;;
33+
esac
34+
# Construct the corresponding path in the second directory
35+
file2="$dir2/${file#$dir1/}"
36+
# Check if the corresponding file exists in the second directory
37+
if [ ! -f "$file2" ]; then
38+
echo "Error: File '$file' found in '$dir1' but not found in '$dir2'" >&2
39+
exit 1
40+
fi
41+
# Compare the contents of the two files using diff
42+
set +ex
43+
differences=$(diff -u -p "$file" "$file2")
44+
set -e # leave x off
45+
# If there are any differences, print an error message and exit with failure status
46+
if [ -n "$differences" ]; then
47+
echo "Error: Mismatch detected in file '$file':" >&2
48+
echo "$differences" >&2
49+
exit_status=1
50+
fi
51+
set -x
52+
done < <(find "$dir1" -type f -print0)
53+
54+
exit $exit_status
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

.github/workflows/check-c10-sync.yml

+32
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)