diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2023-04-03 12:22:52 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-03 12:22:52 -0400 |
| commit | 817a05c1abdee0009c625b0bba7971e6ab9501c0 (patch) | |
| tree | e756138e4d94ab26fe6c9f35a7658d2ad518c5d5 | |
| parent | 35cb5d1cfc163b95f48a2bc4f1f22bbff6e9e109 (diff) | |
Frogress script (#10)
* initial progress script
* uploadfrogress script
* Add Frogress step to Jenkinsfile
* rename to animalforest
* badge
* ZeldaRET
| -rw-r--r-- | Jenkinsfile | 12 | ||||
| -rw-r--r-- | README.md | 4 | ||||
| -rwxr-xr-x | tools/progress.py | 80 | ||||
| -rwxr-xr-x | tools/upload_frogress.py | 38 |
4 files changed, 133 insertions, 1 deletions
diff --git a/Jenkinsfile b/Jenkinsfile index 05324d8..8f7ce46 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,6 +3,10 @@ pipeline { label 'af' } + environment { + FROGRESS_KEY = credentials('af_frogress_key') + } + options { ansiColor('xterm') } @@ -41,6 +45,14 @@ pipeline { sh 'bash -c "make -j uncompressed"' } } + stage('Upload to Frogress') { + when { + branch 'main' + } + steps { + sh 'python3 ./tools/upload_frogress.py jp --apikey $FROGRESS_KEY' + } + } } post { failure { @@ -1,4 +1,6 @@ -# Animal Forest +# Animal Forest ![Code jp Progress] + +[Code jp Progress]: https://img.shields.io/endpoint?label=Code%20jp&url=https%3A%2F%2Fprogress.deco.mp%2Fdata%2Fdrmario64%2Fjp%2Fcode%2F%3Fmode%3Dshield%26measure%3Dall ```diff - WARNING! - diff --git a/tools/progress.py b/tools/progress.py new file mode 100755 index 0000000..bff79fd --- /dev/null +++ b/tools/progress.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 + +# SPDX-FileCopyrightText: © 2023 ZeldaRET +# SPDX-License-Identifier: MIT + +from __future__ import annotations + +import argparse +import mapfile_parser +from pathlib import Path + + +ASMPATH = Path("asm") +NONMATCHINGS = "nonmatchings" + + +def getProgressFromMapFile(mapFile: mapfile_parser.MapFile, asmPath: Path, nonmatchings: Path, aliases: dict[str, str]=dict(), pathIndex: int=2) -> tuple[mapfile_parser.ProgressStats, dict[str, mapfile_parser.ProgressStats]]: + totalStats = mapfile_parser.ProgressStats() + progressPerFolder: dict[str, mapfile_parser.ProgressStats] = dict() + + for file in mapFile: + if len(file.symbols) == 0: + continue + + folder = file.filepath.parts[pathIndex] + if folder in aliases: + folder = aliases[folder] + + if folder not in progressPerFolder: + progressPerFolder[folder] = mapfile_parser.ProgressStats() + + originalFilePath = Path(*file.filepath.parts[pathIndex:]) + fullAsmFile = asmPath / originalFilePath.with_suffix(".s") + wholeFileIsUndecomped = fullAsmFile.exists() + + for func in file.symbols: + if wholeFileIsUndecomped: + totalStats.undecompedSize += func.size + progressPerFolder[folder].undecompedSize += func.size + elif mapFile.findSymbolByName(func.name) is not None: + totalStats.undecompedSize += func.size + progressPerFolder[folder].undecompedSize += func.size + else: + totalStats.decompedSize += func.size + progressPerFolder[folder].decompedSize += func.size + + return totalStats, progressPerFolder + + +def getProgress(mapPath: Path, version: str) -> tuple[mapfile_parser.ProgressStats, dict[str, mapfile_parser.ProgressStats]]: + mapFile = mapfile_parser.MapFile() + mapFile.readMapFile(mapPath) + + for file in mapFile: + if len(file.symbols) == 0: + continue + + filepathParts = list(file.filepath.parts) + if version in filepathParts: + filepathParts.remove(version) + file.filepath = Path(*filepathParts) + + nonMatchingsPath = ASMPATH / version / NONMATCHINGS + + return mapFile.filterBySegmentType(".text").getProgress(ASMPATH / version, nonMatchingsPath, aliases={"ultralib": "libultra"}) + +def progressMain(): + parser = argparse.ArgumentParser() + parser.add_argument("-v", "--version", help="version to process", default="jp") + + args = parser.parse_args() + + mapPath = Path("build") / f"animalforest.{args.version}.map" + + totalStats, progressPerFolder = getProgress(mapPath, args.version) + + mapfile_parser.progress_stats.printStats(totalStats, progressPerFolder) + +if __name__ == "__main__": + progressMain() diff --git a/tools/upload_frogress.py b/tools/upload_frogress.py new file mode 100755 index 0000000..38ee29c --- /dev/null +++ b/tools/upload_frogress.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +# SPDX-FileCopyrightText: © 2023 ZeldaRET +# SPDX-License-Identifier: MIT + +from __future__ import annotations + +import argparse +import mapfile_parser +from pathlib import Path + +import progress + + +BASE_URL = "https://progress.deco.mp" +PROJECT = "animalforest" + +def uploadProgressMain(): + parser = argparse.ArgumentParser() + parser.add_argument("version", help="Version slug") + parser.add_argument("--apikey", help="API key") + + args = parser.parse_args() + + version: str = args.version + category: str = "code" + apikey: str = args.apikey + mapPath = Path("build") / f"animalforest.{args.version}.map" + + totalStats, progressPerFolder = progress.getProgress(mapPath, version) + + entries: dict[str, int] = mapfile_parser.frontends.upload_frogress.getFrogressEntriesFromStats(totalStats, progressPerFolder, verbose=True) + + url = mapfile_parser.utils.generateFrogressEndpointUrl(BASE_URL, PROJECT, version) + exit(mapfile_parser.frontends.upload_frogress.uploadEntriesToFrogress(entries, category, url, apikey=apikey, verbose=True)) + +if __name__ == '__main__': + uploadProgressMain() |
