Skip to content

Commit 8c3ec49

Browse files
committed
Refactor reproducibility check
1 parent 95ef2f5 commit 8c3ec49

File tree

1 file changed

+64
-40
lines changed

1 file changed

+64
-40
lines changed

.github/workflows/repro_check.yml

Lines changed: 64 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,103 @@
1-
name: Build and Diff Projects
1+
# Workflow that runs after a merge to master, builds toolchain in 2 different
2+
# directories to check for reproducible builds. This check helps track which
3+
# commits cause reproducibility issues. This check should pass before stable
4+
# release are made.
5+
6+
name: Reproducibility check
27

38
on:
49
push:
5-
branches:
6-
- master
7-
pull_request:
810
branches:
911
- master
1012
- reproducible
1113

1214
jobs:
1315
build_and_compare:
14-
runs-on: ubuntu-latest
16+
runs-on: ubuntu-24.04
17+
18+
strategy:
19+
matrix:
20+
build_dir: [buildA, buildA_extended]
1521

1622
steps:
1723
- name: Checkout repository
18-
uses: actions/checkout@v2
19-
20-
- name: Set up Python
21-
uses: actions/setup-python@v2
22-
with:
23-
python-version: '3.x' # Adjust to the version you need
24+
uses: actions/checkout@v4
2425

25-
- name: Build and store buildA binaries
26+
# Build the two toolchains for comparision
27+
- name: Build and store ${{ matrix.build_dir }} binaries
2628
run: |
27-
mkdir ../buildA
28-
cp -r "$(pwd)" ../buildA
29-
pushd ../buildA
30-
SOURCE_DIR=$(dirname $(find . -maxdepth 2 -name x.py))
31-
$SOURCE_DIR/configure --set rust.channel=nightly
32-
$SOURCE_DIR/x.py build --stage 2 -j$(($(nproc)*2/3))
33-
rm -rf $SOURCE_DIR
34-
STAGE2_DIR=`find build -name stage2`
35-
cp -r "$STAGE2_DIR" .
36-
echo "Contents stage 2 dir : `ls stage2`"
37-
rm -rf build
38-
popd
29+
mkdir ../${{ matrix.build_dir }}
30+
cp -r "$(pwd)" ../${{ matrix.build_dir }}
31+
pushd ../${{ matrix.build_dir }}
3932
40-
- name: Build and store buildA_extended binaries
41-
run: |
42-
mkdir ../buildA_extended
43-
cp -r "$(pwd)" ../buildA_extended
44-
pushd ../buildA_extended
45-
SOURCE_DIR=$(dirname $(find . -maxdepth 2 -name x.py))
33+
# Find source directory.
34+
SOURCE_DIR=$(dirname $(find . -maxdepth 2 -name x.py))
35+
36+
# FIXME: Setting channel to nightly because only nightly builds succeed on ci.
4637
$SOURCE_DIR/configure --set rust.channel=nightly
38+
39+
# Build rust till stage 2
4740
$SOURCE_DIR/x.py build --stage 2 -j$(($(nproc)*2/3))
41+
42+
# Remove copy of source directory to save space.
4843
rm -rf $SOURCE_DIR
49-
STAGE2_DIR=`find build -name stage2`
44+
45+
# Find stage 2 artifacts directory
46+
STAGE2_DIR=$(find build -name stage2)
47+
48+
# Save stage 2 directory contents before we delete build
5049
cp -r "$STAGE2_DIR" .
51-
echo "Contents stage 2 dir : `ls stage2`"
50+
echo "Contents stage 2 dir : $(ls stage2)"
51+
52+
# Remove build directory to save space
5253
rm -rf build
5354
popd
5455
55-
- name: Compare builds and archive artifacts
56+
# Compare the two builds
57+
- name: Compare builds
58+
id: compare
5659
run: |
5760
# Ensure the directories exist
5861
if [[ ! -d "../buildA" || ! -d "../buildA_extended" ]]; then
5962
echo "Error: Build directories not found!"
6063
exit 1
6164
fi
6265
63-
# Perform a diff between the two builds
64-
diff -r ../buildA/stage2 ../buildA_extended/stage2 || echo "Differences found!"
65-
66-
tar -czf buildA.tar.gz ../buildA
67-
tar -czf buildA_extended.tar.gz ../buildA_extended
66+
# Perform a recursive diff between the stage2 directories of both builds
67+
# If there are differences, record the result so we can upload artifacts and then fail later
68+
# The binaries should be identical, so the cause of difference should be analysed and fixed
69+
# appropriately.
70+
if diff -r ../buildA/stage2 ../buildA_extended/stage2; then
71+
echo "No differences found."
72+
echo "has_diff=false" >> $GITHUB_OUTPUT
73+
else
74+
echo "Differences found!"
75+
echo "has_diff=true" >> $GITHUB_OUTPUT
76+
fi
6877
78+
# Upload buildA directory as an artifact (for debugging purposes)
79+
# This artifact contains stage2 folder from buildA. This artifact would
80+
# be helpful to debug reproducibility issue when this test fails.
6981
- name: Upload buildA artifact
82+
if: steps.compare.outputs.has_diff == 'true'
7083
uses: actions/upload-artifact@v4
7184
with:
7285
name: buildA
73-
path: buildA.tar.gz
86+
path: ../buildA
7487

88+
# Upload buildA_extended directory as an artifact (for debugging purposes)
89+
# This artifact contains stage2 folder from buildA_extended. This artifact would
90+
# be helpful to debug reproducibility issue when this test fails.
7591
- name: Upload buildA_extended artifact
92+
if: steps.compare.outputs.has_diff == 'true'
7693
uses: actions/upload-artifact@v4
7794
with:
7895
name: buildA_extended
79-
path: buildA_extended.tar.gz
96+
path: ../buildA_extended
97+
98+
# Fail the job if differences were found between the builds
99+
- name: Fail the job if there are differences
100+
if: steps.compare.outputs.has_diff == 'true'
101+
run: |
102+
echo "Differences found between buildA and buildA_extended, Reproducibility check failed"
103+
exit 1

0 commit comments

Comments
 (0)