Skip to content

Commit d72ad9d

Browse files
committed
Added Utility to Accept Snapshots
1 parent 3ed4025 commit d72ad9d

File tree

3 files changed

+38
-43
lines changed

3 files changed

+38
-43
lines changed

.build/Build.cs

+31
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Linq;
1111
using System;
1212
using System.IO;
13+
using Serilog;
1314

1415
[UnsetVisualStudioEnvironmentVariables]
1516
partial class Build : NukeBuild
@@ -100,6 +101,36 @@ partial class Build : NukeBuild
100101
RootDirectory / "matrix.json",
101102
JsonConvert.SerializeObject(matrix));
102103
});
104+
105+
Target Accept => _ => _
106+
.Executes(() =>
107+
{
108+
foreach (var mismatchDir in Directory.GetDirectories(
109+
RootDirectory, "__MISMATCH__", SearchOption.AllDirectories))
110+
{
111+
Log.Information("Analyzing {0} ...", mismatchDir);
112+
113+
var snapshotDir = Directory.GetParent(mismatchDir)!.FullName;
114+
foreach (var mismatch in Directory.GetFiles(
115+
mismatchDir, "*.*", SearchOption.TopDirectoryOnly))
116+
{
117+
var snapshot = Path.Combine(snapshotDir, Path.GetFileName(mismatch));
118+
if (File.Exists(snapshot))
119+
{
120+
File.Delete(snapshot);
121+
File.Move(mismatch, snapshot);
122+
}
123+
}
124+
125+
foreach (var mismatch in Directory.GetFiles(
126+
mismatchDir, "*.*", SearchOption.AllDirectories))
127+
{
128+
File.Delete(mismatch);
129+
}
130+
131+
Directory.Delete(mismatchDir, true);
132+
}
133+
});
103134
}
104135

105136

accept.cmd

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
:; set -eo pipefail
2+
:; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
3+
:; ${SCRIPT_DIR}/accept.sh "$@"
4+
:; exit $?
5+
6+
./build.cmd accept

accept.sh

+1-43
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,3 @@
11
#!/bin/zsh
22

3-
# Use a variable to keep track of whether any directories were found
4-
found_mismatch=false
5-
6-
# Use a variable to check if the header has been printed
7-
header_printed=false
8-
9-
# Find all __MISMATCH__ folders
10-
find . -type d -name "__MISMATCH__" | while read mismatch_dir; do
11-
# Mark that we found a mismatch directory
12-
found_mismatch=true
13-
14-
# Get the parent __snapshots__ directory
15-
snapshot_dir="$(dirname "$mismatch_dir")"
16-
17-
# If there are files in the directory, copy them
18-
if [ "$(ls -A "$mismatch_dir")" ]; then
19-
for file in "$mismatch_dir"/*; do
20-
if [ -f "$file" ]; then
21-
cp "$file" "$snapshot_dir/"
22-
23-
# Print the header only once
24-
if [ "$header_printed" = false ]; then
25-
echo "Found Updated Snapshots:"
26-
header_printed=true
27-
fi
28-
29-
# Extract relevant path details and print
30-
relative_path="${snapshot_dir#./src/HotChocolate/}" # strip the common prefix
31-
echo "- $relative_path/$(basename "$file")"
32-
fi
33-
done
34-
fi
35-
36-
# Remove the __MISMATCH__ directory
37-
rm -r "$mismatch_dir"
38-
done
39-
40-
# Check if any directories were found
41-
if [ "$found_mismatch" = false ]; then
42-
echo "All snapshots are up to date!"
43-
else
44-
echo "\nDone!"
45-
fi
3+
./build.sh accept

0 commit comments

Comments
 (0)