-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from DreamEnderKing/dev
ci: 👷 Add CI to publish hash.json of this repo.
- Loading branch information
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System.Text.Json; | ||
|
||
Dictionary<string, string> MD5Data = new Dictionary<string, string>(); | ||
|
||
public string ConvertAbsToRel(string basePath, string fullPath) | ||
{ | ||
if (fullPath.StartsWith(basePath)) | ||
{ | ||
fullPath = fullPath.Replace(basePath, "."); | ||
} | ||
return fullPath; | ||
} | ||
|
||
public string GetFileMd5Hash(string strFileFullPath) | ||
{ | ||
var fst = new FileStream(strFileFullPath, FileMode.Open, FileAccess.Read); | ||
byte[] data = System.Security.Cryptography.MD5.Create().ComputeHash(fst); | ||
|
||
StringBuilder sBuilder = new StringBuilder(); | ||
|
||
for (int i = 0; i < data.Length; i++) | ||
{ | ||
sBuilder.Append(data[i].ToString("x2")); | ||
} | ||
|
||
fst.Close(); | ||
return sBuilder.ToString().ToLower(); | ||
} | ||
|
||
public static bool IsUserFile(string filename) | ||
{ | ||
if (filename.Contains("git") || filename.Contains("bin") || filename.Contains("obj")) | ||
return true; | ||
if (filename.EndsWith("sh") || filename.EndsWith("cmd")) | ||
return true; | ||
if (filename.EndsWith("gz")) | ||
return true; | ||
if (filename.Contains("AI.cpp") || filename.Contains("AI.py")) | ||
return true; | ||
if (filename.Contains("hash.json")) | ||
return true; | ||
if (filename.EndsWith("log")) | ||
return true; | ||
return false; | ||
} | ||
|
||
public void SaveMD5Data() | ||
{ | ||
FileStream fs = new FileStream(@"/home/runner/work/THUAI7/hash.json", FileMode.OpenOrCreate, FileAccess.ReadWrite); | ||
StreamWriter sw = new StreamWriter(fs); | ||
fs.SetLength(0); | ||
var exp1 = from i in MD5Data | ||
select new KeyValuePair<string, string>(i.Key.Replace(Path.DirectorySeparatorChar, '/'), i.Value); | ||
sw.Write(JsonSerializer.Serialize(exp1.ToDictionary<string, string>())); | ||
sw.Flush(); | ||
sw.Dispose(); | ||
fs.Dispose(); | ||
} | ||
|
||
public void ScanDir(string dir) | ||
{ | ||
var d = new DirectoryInfo(dir); | ||
foreach (var file in d.GetFiles()) | ||
{ | ||
var relFile = ConvertAbsToRel(@"/home/runner/work/THUAI7/", file.FullName); | ||
// 用户自己的文件不会被计入更新hash数据中 | ||
if (IsUserFile(relFile)) | ||
continue; | ||
var hash = GetFileMd5Hash(file.FullName); | ||
if (MD5Data.Keys.Contains(relFile)) | ||
{ | ||
if (MD5Data[relFile] != hash) | ||
{ | ||
MD5Data[relFile] = hash; | ||
} | ||
} | ||
else | ||
{ | ||
MD5Data.Add(relFile, hash); | ||
} | ||
} | ||
foreach (var d1 in d.GetDirectories()) { ScanDir(d1.FullName); } | ||
} | ||
|
||
ScanDir(@"/home/runner/work/THUAI7/"); | ||
SaveMD5Data(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: publish | ||
on: | ||
push: | ||
branches: [dev, main, master] | ||
|
||
jobs: | ||
print-thuai7-json: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup .NET Core | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: 8.0.x | ||
- name: Setup dotnet-script | ||
run: dotnet tool install --global dotnet-script | ||
- name: Generate THUAI7 hash.json | ||
run: dotnet script .github/preProcess/ExportHash.csx | ||
- name: Upload THUAI7 hash.json | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: hash.json | ||
path: /home/runner/work/THUAI7/hash.json |