Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .ci/scripts/check_c10_sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this file being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops! supposed to be the thing that the workflow calls

# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

set -exu
ls pytorch/.git || git clone https://github.com/pytorch/pytorch.git
pushd pytorch
git checkout "$(< ../.ci/docker/ci_commit_pins/pytorch.txt)"
popd
"$(dirname "${BASH_SOURCE[0]}")"/diff_c10_mirror_with_pytorch.sh
53 changes: 53 additions & 0 deletions .ci/scripts/compare_dirs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

set -eux

# Check if dir1's files are also found in dir2 with the same
# contents. Exempt files named BUCK, CMakeLists.txt, TARGETS, or
# targets.bzl.

if [ $# -ne 2 ]; then
echo "Usage: $0 dir1 dir2" >&2
exit 1
fi
dir1="$1"
dir2="$2"

if [ ! -d "$dir1" ] || [ ! -d "$dir2" ]; then
echo "Error: Both directories must exist" >&2
exit 1
fi

while IFS= read -r -d '' file; do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on continuing after errors (instead of exiting on first mismatch)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

base=$(basename "$file")
case "$base" in
"BUCK"|"CMakeLists.txt"|"TARGETS"|"targets.bzl")
continue
;;
esac
# Construct the corresponding path in the second directory
file2="$dir2/${file#$dir1/}"
# Check if the corresponding file exists in the second directory
if [ ! -f "$file2" ]; then
echo "Error: File '$file' found in '$dir1' but not found in '$dir2'" >&2
exit 1
fi
# Compare the contents of the two files using diff
set +ex
differences=$(diff -u -p "$file" "$file2")
set -e # leave x off
# If there are any differences, print an error message and exit with failure status
if [ -n "$differences" ]; then
echo "Error: Mismatch detected in file '$file':" >&2
echo "$differences" >&2
exit 1
fi
set -x
done < <(find "$dir1" -type f -print0)
# If no mismatches were found, exit with success status
exit 0
8 changes: 8 additions & 0 deletions .ci/scripts/diff_c10_mirror_with_pytorch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

$(dirname "${BASH_SOURCE[0]}")/compare_dirs.sh runtime/core/portable_type/c10/c10 pytorch/c10
32 changes: 32 additions & 0 deletions .github/workflows/check_c10_sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: check-c10-sync

on:
pull_request:
paths:
- .ci/docker/ci_commit_pins/pytorch.txt
- .ci/scripts/compare_dirs.sh
- .ci/scripts/diff_c10_mirror_with_pytorch.sh

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
cancel-in-progress: true

jobs:
check-c10-sync:
permissions:
id-token: write
contents: read
name: check-c10-sync
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Clone PyTorch
run: |
set -ex
git clone https://github.com/pytorch/pytorch.git
pushd pytorch || return
git checkout "$(< ../.ci/docker/ci_commit_pins/pytorch.txt)"
popd
.ci/scripts/diff_c10_mirror_with_pytorch.sh
Loading