History update: add Readme, make build green when there is not change (#5660)

Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
Adam R 2021-02-22 17:48:47 +01:00 committed by GitHub
parent 77d97227f2
commit a7db1a3509
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 10 deletions

49
history/README.md Normal file
View File

@ -0,0 +1,49 @@
# History -- Change management
Change information is made available explicitly, so clients can update only changed assets, without accessing version information from git.
Change information can be found in the folder `history`.
There is the `history/LATEST.json` file, which always contains the current version info:
- `versionNum`: a simple numerical version designator (e.g. 42).
- commit: the git commit SHA of the head of the master branch, info only.
- date: the date time of the last commit, info only.
The folder `history/versions` contains 1 file per version, named `<version>.json`, e.g. `42.json`.
This file contains the list of changed files between the two versions, plus some meta info.
If there are many files changed, the files are not listed, but `"fullChange": true` is set.
An example of a change file is:
```json
{
"versionEnd": {
"versionNum": 2,
"commit": "159cec70437445948d3081a0b1564b436bccb646",
"date": "2021-02-22T15:26:24.985Z"
},
"versionStart": {
"versionNum": 1,
"commit": "f5117527c2e1dd89d51b72c3634d94edb5a04780",
"date": "2021-02-22T14:56:47.938Z"
},
"fullChange": false,
"changeCount": 12,
"changes": [
"blockchains/ethereum/allowlist.json",
"blockchains/ethereum/assets/0x67c597624B17b16fb77959217360B7cD18284253/info.json",
"blockchains/ethereum/assets/0x67c597624B17b16fb77959217360B7cD18284253/logo.png",
"blockchains/ethereum/assets/0x798D1bE841a82a273720CE31c822C61a67a601C3/info.json",
"blockchains/ethereum/assets/0x798D1bE841a82a273720CE31c822C61a67a601C3/logo.png",
"history/LATEST.json",
"history/versions/PLACEHOLDER",
"package.json",
"script/config.ts",
"script/entrypoint/history.ts",
"script/generic/history.ts",
"script/generic/update-all.ts"
]
}
```

View File

@ -76,12 +76,15 @@ async function getChangedFiles(commitStart: string, commitEnd: string): Promise<
if (!bulk) { if (!bulk) {
return []; return [];
} }
const list: string[] = bulk.split("\n").filter(l => { const list: string[] = bulk.split("\n").filter(l => l);
if (!l) return false; return list;
}
function filterChangedFiles(files: string[]): string[] {
return files.filter(l => {
if (l.startsWith(IgnoreHistoryPrefix)) return false; if (l.startsWith(IgnoreHistoryPrefix)) return false;
return true; return true;
}); });
return list;
} }
function changeListToJson(versionStart: VersionInfo, versionEnd: VersionInfo, changes: string[]): unknown { function changeListToJson(versionStart: VersionInfo, versionEnd: VersionInfo, changes: string[]): unknown {
@ -145,15 +148,17 @@ export async function processChanges(): Promise<number> {
}; };
console.log(`New version: ${JSON.stringify(newVer, null, 4)}`); console.log(`New version: ${JSON.stringify(newVer, null, 4)}`);
const files: string[] = await getChangedFiles(ver.commit, currCommit); const filesRaw: string[] = await getChangedFiles(ver.commit, currCommit);
console.log(`${files.length} changed files found`); console.log(`${filesRaw.length} changed files found`);
if (!files || files.length == 0) { if (!filesRaw || filesRaw.length == 0) {
console.log(`Error: Could not obtain list of changed files, or no changed files between commits ${ver.commit} and ${currCommit}`); console.log(`Error: Could not obtain list of changed files between commits ${ver.commit} and ${currCommit}`);
return 4; return 4;
} }
if (files.length == 0) { const files: string[] = filterChangedFiles(filesRaw);
console.log(`Warning: no changed files bwteewn commits ${ver.commit} ${currCommit}`); console.log(`${files.length} changed files found (excluding history files)`);
return 5; if (!files || files.length == 0) {
console.log(`Warning: No changed files (excluding history files) between commits ${ver.commit} and ${currCommit}`);
return 0;
} }
const changeList: unknown = changeListToJson(ver, newVer, files); const changeList: unknown = changeListToJson(ver, newVer, files);