Skip to content

Commit 5297d6e

Browse files
committed
write rustfmt diff check output to diff-check.zip
Now we have an archive that we can inspect after running the diff-check job. I believe this will be easier to inspect than looking at diff output in the github actions console.
1 parent d698bf4 commit 5297d6e

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

.github/workflows/check_diff.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ jobs:
3131
3232
- name: check diff
3333
run: bash ${GITHUB_WORKSPACE}/ci/check_diff.sh ${{ github.event.inputs.clone_url }} ${{ github.event.inputs.branch_name }} ${{ github.event.inputs.commit_hash || github.event.inputs.branch_name }} ${{ github.event.inputs.rustfmt_configs }}
34+
35+
- name: Archive Diff Check Report
36+
uses: actions/upload-artifact@v3
37+
with:
38+
name: diff-check-report
39+
path: diff-check.zip

ci/check_diff.sh

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function create_diff() {
7171
# $RUSFMT_BIN: Path to the rustfmt master binary. Created when running `compile_rustfmt`
7272
# $FEATURE_BIN: Path to the rustfmt feature binary. Created when running `compile_rustfmt`
7373
# $OPTIONAL_RUSTFMT_CONFIGS: Optional configs passed to the script from $4
74+
# $OUTPUT_DIR: Path to an output directory for storing the diff files. Set in `main`
7475
function check_diff() {
7576
echo "running rustfmt (master) on $1"
7677
create_diff $RUSFMT_BIN rustfmt_diff.txt
@@ -89,11 +90,18 @@ function check_diff() {
8990
--unified=0 --no-index rustfmt_diff.txt feature_diff.txt 2>&1 | tail -n +6 | cut -c 2-
9091
)
9192

93+
# COPY diffs into output dir
94+
mkdir $OUTPUT_DIR/$1
95+
echo "Copying diffs to $OUTPUT_DIR/$1"
96+
cp rustfmt_diff.txt $OUTPUT_DIR/$1/rustfmt_diff.txt
97+
cp feature_diff.txt $OUTPUT_DIR/$1/feature_diff.txt
98+
9299
if [ -z "$diff" ]; then
93100
echo "no diff detected between rustfmt and the feture branch"
94101
return 0
95102
else
96-
echo "$diff"
103+
echo "Copying diffs between rustfmt and feature branch to $OUTPUT_DIR/$1/diff.txt"
104+
echo "$diff" >> $OUTPUT_DIR/$1/diff.txt
97105
return 1
98106
fi
99107
}
@@ -160,11 +168,27 @@ function check_repo() {
160168
cd $WORKDIR
161169
}
162170

171+
# Zip up all the diff changes detected by the script
172+
#
173+
# Globlas:
174+
# $OUTPUT_DIR: Output directory where all `*diif.txt` files are written to. Set in `main`.
175+
# $CURRENT_DIR: The directory where the script was run from. Set in `main`.
176+
function zip_up_diffs() {
177+
cd $OUTPUT_DIR
178+
179+
# Just to clean things up we'll make sure to remove empty files and directories
180+
find . -type f -empty -delete
181+
find . -type d -empty -delete
182+
zip -q -r $CURRENT_DIR/diff-check .
183+
}
184+
163185
function main() {
186+
CURRENT_DIR=$(pwd)
164187
tmp_dir=$(mktemp -d -t rustfmt-XXXXXXXX)
165188
echo Created tmp_dir $tmp_dir
166189

167190
compile_rustfmt $tmp_dir
191+
OUTPUT_DIR=$(mktemp -d -t diff-output-XXX)
168192

169193
# run checks
170194
check_repo "https://github.com/rust-lang/rust.git" rust-lang-rust
@@ -191,9 +215,12 @@ function main() {
191215
check_repo "https://github.com/actix/actix.git" actix
192216
check_repo "https://github.com/denoland/deno.git" denoland_deno
193217

218+
zip_up_diffs
219+
194220
# cleanup temp dir
195-
echo removing tmp_dir $tmp_dir
221+
echo removing tmp_dir $tmp_dir and $OUTPUT_DIR
196222
rm -rf $tmp_dir
223+
rm -rf $OUTPUT_DIR
197224

198225
# figure out the exit code
199226
for status in ${STATUSES[@]}

0 commit comments

Comments
 (0)