From b31922c9f7495e972728ed22401c807f8d3a7d8c Mon Sep 17 00:00:00 2001 From: Dao Hoang Son Date: Thu, 21 Sep 2023 09:58:04 +0700 Subject: [PATCH] Post GitHub comment with statistics --- .github/workflows/osm.yml | 18 +++++++++++++++++- transformers/osm/split.php | 8 +++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.github/workflows/osm.yml b/.github/workflows/osm.yml index a436718..8ba4f7c 100644 --- a/.github/workflows/osm.yml +++ b/.github/workflows/osm.yml @@ -23,4 +23,20 @@ jobs: - name: Build demo/parser CLI run: bun install && npm run bun:build working-directory: demo/parser - - run: php transformers/osm/split.php + - run: php transformers/osm/split.php | tee split.log + + - name: Prepare GitHub comment + id: comment + run: printf 'BODY<> $GITHUB_OUTPUT + - name: Post GitHub comment + uses: daohoangson/comment-on-github@35b21121fdbadf807678bec8210cdd7f22a934fe # v2.2.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + body: | + ${{ github.sha }} + + ``` + ${{ steps.comment.outputs.BODY }} + ``` + fingerprint: "### Statistics" diff --git a/transformers/osm/split.php b/transformers/osm/split.php index f3fc4f8..68c9b84 100644 --- a/transformers/osm/split.php +++ b/transformers/osm/split.php @@ -58,12 +58,14 @@ function main() $array[$item['id']] = $item; } - fwrite(STDOUT, sprintf("Paths: %d -> items: %d\n", $pathCount, count($array))); + fwrite(STDERR, sprintf("Paths: %d -> items: %d\n", $pathCount, count($array))); + $i = $j = 0; foreach ($array as $item) { + $j++; if (isset($workingWrittenPaths[$item['path']])) { statisticsTrack($outDir, $item['path'], $workingWrittenPaths[$item['path']]); - fwrite(STDOUT, 'w'); // already written + fwrite(STDERR, ++$i % 50 > 0 ? 'w' : sprintf(" %.2f%%\n", $j / count($array) * 100)); continue; } @@ -84,7 +86,7 @@ function main() $workingWrittenPaths[$item['path']] = $jsonFullPath; statisticsTrack($outDir, $item['path'], $jsonFullPath); file_put_contents($workingFilePath, json_encode(compact('workingWrittenPaths'))); - fwrite(STDOUT, '.'); + fwrite(STDERR, ++$i % 50 > 0 ? '.' : sprintf("%.2f%%\n", $j / count($array) * 100)); continue; }