From 533b79fd19f71fb2a009887f25aabb19d1a0e9ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 28 Jan 2024 12:26:30 +0100 Subject: [PATCH 01/41] PoC version #3 * Add structure of GitHubAction docker type --- Dockerfile | 5 +++++ action.yaml | 22 ++++++++++++++++++++++ docker/entrypoint.sh | 5 +++++ 3 files changed, 32 insertions(+) create mode 100644 Dockerfile create mode 100644 action.yaml create mode 100755 docker/entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9ec4264 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM python:3.11-bullseye + +COPY docker/entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..d3265c0 --- /dev/null +++ b/action.yaml @@ -0,0 +1,22 @@ +name: 'dotnet-format-results' +author: 'Rafał Salamon' +description: 'A GitHub Action creates an HTML report based on the .json file generated by the `dotnet format` command.' +branding: + icon: 'check-circle' + color: 'green' + +inputs: + json-results: + description: "JSON content generated by `dotnet format` command" + required: true + default: '[]' +outputs: + result: + description: Result + +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.json-results }} +# - "[{\"TestVar\": \"TestOutput\"}]" diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 0000000..d2bbed4 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh -l + +echo "JSON Input $1" +html_output="Testing

Testing workflow

" +echo "$html_output" >> $GITHUB_OUTPUT From 22ffed55e1ac1ff0d517706e949fae563cdc8e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 28 Jan 2024 12:46:14 +0100 Subject: [PATCH 02/41] PoC version #3 * Add test workflow --- .github/workflows/test-dotnet-format-results.yml | 13 +++++++++++++ action.yaml | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test-dotnet-format-results.yml diff --git a/.github/workflows/test-dotnet-format-results.yml b/.github/workflows/test-dotnet-format-results.yml new file mode 100644 index 0000000..0243d4a --- /dev/null +++ b/.github/workflows/test-dotnet-format-results.yml @@ -0,0 +1,13 @@ +name: "Test use workflow" +on: [push] +jobs: + runs-on: ubuntu-latest + name: "Test basin usage" + steps: + - name: "Uses" + id: output-convert + uses: x-coders-team/dotnet-format-results@v1.0.0-poc-1 + with: + json-results: '[{"DocumentId":{"ProjectId":{"Id":"f307936d-8b40-4e7c-897c-0f16889c4163"},"Id":"70e32bdf-23e9-4482-a949-65384ce65fce"},"FileName":"WeatherForecastRepository.cs","FilePath":"F:\\Projekty\\crontab-registry\\src\\CrontabRegistry\\Infrastructure\\Repositories\\WeatherForecastRepository.cs","FileChanges":[{"LineNumber":13,"CharNumber":28,"DiagnosticId":"WHITESPACE","FormatDescription":"Napraw formatowanie odstępów. Replace 1 characters with '\\r\\n\\s\\s\\s\\s\\s\\s\\s\\s'."}]}]' + - name: "Display Results" + run: echo "HTML output is ${{ steps.output-convert.html-output }} " diff --git a/action.yaml b/action.yaml index d3265c0..c8733b3 100644 --- a/action.yaml +++ b/action.yaml @@ -11,7 +11,7 @@ inputs: required: true default: '[]' outputs: - result: + html-output: description: Result runs: From 420749ec5210b5f8fe9c705fc60c7038619cbcd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 28 Jan 2024 12:50:00 +0100 Subject: [PATCH 03/41] PoC version #3 --- .github/workflows/test-dotnet-format-results.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-dotnet-format-results.yml b/.github/workflows/test-dotnet-format-results.yml index 0243d4a..ea7692c 100644 --- a/.github/workflows/test-dotnet-format-results.yml +++ b/.github/workflows/test-dotnet-format-results.yml @@ -6,7 +6,7 @@ jobs: steps: - name: "Uses" id: output-convert - uses: x-coders-team/dotnet-format-results@v1.0.0-poc-1 + uses: x-coders-team/dotnet-format-results@v1.0.0-poc-2 with: json-results: '[{"DocumentId":{"ProjectId":{"Id":"f307936d-8b40-4e7c-897c-0f16889c4163"},"Id":"70e32bdf-23e9-4482-a949-65384ce65fce"},"FileName":"WeatherForecastRepository.cs","FilePath":"F:\\Projekty\\crontab-registry\\src\\CrontabRegistry\\Infrastructure\\Repositories\\WeatherForecastRepository.cs","FileChanges":[{"LineNumber":13,"CharNumber":28,"DiagnosticId":"WHITESPACE","FormatDescription":"Napraw formatowanie odstępów. Replace 1 characters with '\\r\\n\\s\\s\\s\\s\\s\\s\\s\\s'."}]}]' - name: "Display Results" From dae94b203436c9e78cc75b33d5bc7080aee729c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 28 Jan 2024 13:00:30 +0100 Subject: [PATCH 04/41] PoC version #3 --- .github/workflows/test-dotnet-format-results.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-dotnet-format-results.yml b/.github/workflows/test-dotnet-format-results.yml index ea7692c..f2679d5 100644 --- a/.github/workflows/test-dotnet-format-results.yml +++ b/.github/workflows/test-dotnet-format-results.yml @@ -6,8 +6,8 @@ jobs: steps: - name: "Uses" id: output-convert - uses: x-coders-team/dotnet-format-results@v1.0.0-poc-2 + uses: x-coders-team/dotnet-format-results@v1.0.0-poc-3 with: - json-results: '[{"DocumentId":{"ProjectId":{"Id":"f307936d-8b40-4e7c-897c-0f16889c4163"},"Id":"70e32bdf-23e9-4482-a949-65384ce65fce"},"FileName":"WeatherForecastRepository.cs","FilePath":"F:\\Projekty\\crontab-registry\\src\\CrontabRegistry\\Infrastructure\\Repositories\\WeatherForecastRepository.cs","FileChanges":[{"LineNumber":13,"CharNumber":28,"DiagnosticId":"WHITESPACE","FormatDescription":"Napraw formatowanie odstępów. Replace 1 characters with '\\r\\n\\s\\s\\s\\s\\s\\s\\s\\s'."}]}]' + json-results: '[{"DocumentId":{"ProjectId":{"Id":"f307936d-8b40-4e7c-897c-0f16889c4163"},"Id":"70e32bdf-23e9-4482-a949-65384ce65fce"},"FileName":"WeatherForecastRepository.cs","FilePath":"F:\\Projekty\\crontab-registry\\src\\CrontabRegistry\\Infrastructure\\Repositories\\WeatherForecastRepository.cs","FileChanges":[{"LineNumber":13,"CharNumber":28,"DiagnosticId":"WHITESPACE","FormatDescription":"Napraw formatowanie odstępów. Replace 1 characters with ''\\r\\n\\s\\s\\s\\s\\s\\s\\s\\s''."}]}]' - name: "Display Results" run: echo "HTML output is ${{ steps.output-convert.html-output }} " From 5d22fed4ce8a38601339c00a49ca8fe1386a045a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 28 Jan 2024 13:02:57 +0100 Subject: [PATCH 05/41] PoC version #3 --- .../workflows/test-dotnet-format-results.yml | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test-dotnet-format-results.yml b/.github/workflows/test-dotnet-format-results.yml index f2679d5..324f7c3 100644 --- a/.github/workflows/test-dotnet-format-results.yml +++ b/.github/workflows/test-dotnet-format-results.yml @@ -1,13 +1,14 @@ name: "Test use workflow" on: [push] jobs: - runs-on: ubuntu-latest - name: "Test basin usage" - steps: - - name: "Uses" - id: output-convert - uses: x-coders-team/dotnet-format-results@v1.0.0-poc-3 - with: - json-results: '[{"DocumentId":{"ProjectId":{"Id":"f307936d-8b40-4e7c-897c-0f16889c4163"},"Id":"70e32bdf-23e9-4482-a949-65384ce65fce"},"FileName":"WeatherForecastRepository.cs","FilePath":"F:\\Projekty\\crontab-registry\\src\\CrontabRegistry\\Infrastructure\\Repositories\\WeatherForecastRepository.cs","FileChanges":[{"LineNumber":13,"CharNumber":28,"DiagnosticId":"WHITESPACE","FormatDescription":"Napraw formatowanie odstępów. Replace 1 characters with ''\\r\\n\\s\\s\\s\\s\\s\\s\\s\\s''."}]}]' - - name: "Display Results" - run: echo "HTML output is ${{ steps.output-convert.html-output }} " + defult_test_job: + runs-on: ubuntu-latest + name: "Test basin usage" + steps: + - name: "Uses" + id: output-convert + uses: x-coders-team/dotnet-format-results@v1.0.0-poc-4 + with: + json-results: '[{"DocumentId":{"ProjectId":{"Id":"f307936d-8b40-4e7c-897c-0f16889c4163"},"Id":"70e32bdf-23e9-4482-a949-65384ce65fce"},"FileName":"WeatherForecastRepository.cs","FilePath":"F:\\Projekty\\crontab-registry\\src\\CrontabRegistry\\Infrastructure\\Repositories\\WeatherForecastRepository.cs","FileChanges":[{"LineNumber":13,"CharNumber":28,"DiagnosticId":"WHITESPACE","FormatDescription":"Napraw formatowanie odstępów. Replace 1 characters with ''\\r\\n\\s\\s\\s\\s\\s\\s\\s\\s''."}]}]' + - name: "Display Results" + run: echo "HTML output is ${{ steps.output-convert.html-output }} " From 07b6eb629fdd17128962fda0f1fe71df7ea64995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 28 Jan 2024 13:04:58 +0100 Subject: [PATCH 06/41] PoC version #3 --- .github/workflows/test-dotnet-format-results.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-dotnet-format-results.yml b/.github/workflows/test-dotnet-format-results.yml index 324f7c3..929fc61 100644 --- a/.github/workflows/test-dotnet-format-results.yml +++ b/.github/workflows/test-dotnet-format-results.yml @@ -6,9 +6,9 @@ jobs: name: "Test basin usage" steps: - name: "Uses" - id: output-convert - uses: x-coders-team/dotnet-format-results@v1.0.0-poc-4 - with: + id: output-convert + uses: x-coders-team/dotnet-format-results@v1.0.0-poc-5 + with: json-results: '[{"DocumentId":{"ProjectId":{"Id":"f307936d-8b40-4e7c-897c-0f16889c4163"},"Id":"70e32bdf-23e9-4482-a949-65384ce65fce"},"FileName":"WeatherForecastRepository.cs","FilePath":"F:\\Projekty\\crontab-registry\\src\\CrontabRegistry\\Infrastructure\\Repositories\\WeatherForecastRepository.cs","FileChanges":[{"LineNumber":13,"CharNumber":28,"DiagnosticId":"WHITESPACE","FormatDescription":"Napraw formatowanie odstępów. Replace 1 characters with ''\\r\\n\\s\\s\\s\\s\\s\\s\\s\\s''."}]}]' - name: "Display Results" - run: echo "HTML output is ${{ steps.output-convert.html-output }} " + run: echo "HTML output is ${{ steps.output-convert.html-output }} " From ce171ea66e0cf85f1400581064d3b9a635faa72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 28 Jan 2024 13:13:43 +0100 Subject: [PATCH 07/41] PoC version #3 --- .github/workflows/test-dotnet-format-results.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-dotnet-format-results.yml b/.github/workflows/test-dotnet-format-results.yml index 929fc61..842e33d 100644 --- a/.github/workflows/test-dotnet-format-results.yml +++ b/.github/workflows/test-dotnet-format-results.yml @@ -5,10 +5,12 @@ jobs: runs-on: ubuntu-latest name: "Test basin usage" steps: + - name: Checkout + uses: actions/checkout@v4 - name: "Uses" id: output-convert - uses: x-coders-team/dotnet-format-results@v1.0.0-poc-5 + uses: ./ with: json-results: '[{"DocumentId":{"ProjectId":{"Id":"f307936d-8b40-4e7c-897c-0f16889c4163"},"Id":"70e32bdf-23e9-4482-a949-65384ce65fce"},"FileName":"WeatherForecastRepository.cs","FilePath":"F:\\Projekty\\crontab-registry\\src\\CrontabRegistry\\Infrastructure\\Repositories\\WeatherForecastRepository.cs","FileChanges":[{"LineNumber":13,"CharNumber":28,"DiagnosticId":"WHITESPACE","FormatDescription":"Napraw formatowanie odstępów. Replace 1 characters with ''\\r\\n\\s\\s\\s\\s\\s\\s\\s\\s''."}]}]' - name: "Display Results" - run: echo "HTML output is ${{ steps.output-convert.html-output }} " + run: echo "HTML output is ${{ steps.output-convert.outputs.html-output }} " From 25652b92f9137ad202e27bb6a980faee91adaa39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 28 Jan 2024 13:22:45 +0100 Subject: [PATCH 08/41] PoC version #3 --- docker/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index d2bbed4..880fc73 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -2,4 +2,4 @@ echo "JSON Input $1" html_output="Testing

Testing workflow

" -echo "$html_output" >> $GITHUB_OUTPUT +echo "html-output=$html_output" >> $GITHUB_OUTPUT From d7f7f101529b8b28e20c0d8ddf84b6169845e465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 28 Jan 2024 13:49:37 +0100 Subject: [PATCH 09/41] PoC version #3 --- Dockerfile | 3 +++ docker/entrypoint.sh | 9 +++++++-- src/main.py | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 src/main.py diff --git a/Dockerfile b/Dockerfile index 9ec4264..323a01d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ FROM python:3.11-bullseye COPY docker/entrypoint.sh /entrypoint.sh +WORKDIR action + +COPY . . ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 880fc73..d85708b 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,5 +1,10 @@ #!/bin/sh -l echo "JSON Input $1" -html_output="Testing

Testing workflow

" -echo "html-output=$html_output" >> $GITHUB_OUTPUT +if html_output=$(python ./src/main.py); then + echo "html-output=$html_output" >> $GITHUB_OUTPUT +else + echo "Unable return HTML output" + exit 1 +fi + diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..e1953bc --- /dev/null +++ b/src/main.py @@ -0,0 +1,2 @@ +html_output = "Testing

Testing workflow

" +print(html_output) \ No newline at end of file From 974237644830846a36abf8d76be3778b18f6ccba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 28 Jan 2024 13:52:16 +0100 Subject: [PATCH 10/41] PoC version #3 --- src/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.py b/src/main.py index e1953bc..e84b7c2 100644 --- a/src/main.py +++ b/src/main.py @@ -1,2 +1,2 @@ -html_output = "Testing

Testing workflow

" +html_output = "Testing from Python

Testing workflow

" print(html_output) \ No newline at end of file From 126c93a88e43a6a80bc4cfa13baaffda1cc88350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 28 Jan 2024 13:59:28 +0100 Subject: [PATCH 11/41] PoC version #3 --- docker/entrypoint.sh | 2 +- src/main.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index d85708b..7b3d39b 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh -l echo "JSON Input $1" -if html_output=$(python ./src/main.py); then +if html_output=$(python ./src/main.py $1); then echo "html-output=$html_output" >> $GITHUB_OUTPUT else echo "Unable return HTML output" diff --git a/src/main.py b/src/main.py index e84b7c2..8cd6478 100644 --- a/src/main.py +++ b/src/main.py @@ -1,2 +1,4 @@ -html_output = "Testing from Python

Testing workflow

" +import sys +json_input = sys.argv[1] +html_output = f"Testing from Python

Testing workflow

{json_input}
" print(html_output) \ No newline at end of file From e5e32d9e459f0b2c8ae3c8b2172087261863dfc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 28 Jan 2024 14:03:41 +0100 Subject: [PATCH 12/41] PoC version #3 --- docker/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 7b3d39b..a796c2f 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh -l echo "JSON Input $1" -if html_output=$(python ./src/main.py $1); then +if html_output=$(python ./src/main.py "$1"); then echo "html-output=$html_output" >> $GITHUB_OUTPUT else echo "Unable return HTML output" From 7da8e6f0b345a178d9afd7d3aec32d676a0a533b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 28 Jan 2024 14:16:53 +0100 Subject: [PATCH 13/41] PoC version #3 --- .../workflows/test-dotnet-format-results.yml | 2 +- README.md | 22 +++++++++++++++++++ action.yaml | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-dotnet-format-results.yml b/.github/workflows/test-dotnet-format-results.yml index 842e33d..b53541c 100644 --- a/.github/workflows/test-dotnet-format-results.yml +++ b/.github/workflows/test-dotnet-format-results.yml @@ -3,7 +3,7 @@ on: [push] jobs: defult_test_job: runs-on: ubuntu-latest - name: "Test basin usage" + name: "Test basic usage" steps: - name: Checkout uses: actions/checkout@v4 diff --git a/README.md b/README.md index 37158cd..5fe6f04 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,24 @@ # dotnet-format-results GitHub Action reads and creates an HTML report based on the .json file generated by the 'dotnet format' command. + +## Inputs + +## `json-results` + +**Required** JSON content generated by `dotnet format` command. Default `[]`. + +## Outputs + +## `html-output` + +Generated HTML code based on JSON input for the results. + +## Example usage + + +``` +uses: x-coders-team/dotnet-format-results@v2 +id: output-convert +with: + json-results: '[{"DocumentId":{"ProjectId":{"Id":"f307936d-8b40-4e7c-897c-0f16889c4163"},"Id":"70e32bdf-23e9-4482-a949-65384ce65fce"},"FileName":"WeatherForecastRepository.cs","FilePath":"F:\\Projekty\\crontab-registry\\src\\CrontabRegistry\\Infrastructure\\Repositories\\WeatherForecastRepository.cs","FileChanges":[{"LineNumber":13,"CharNumber":28,"DiagnosticId":"WHITESPACE","FormatDescription":"Napraw formatowanie odstępów. Replace 1 characters with ''\\r\\n\\s\\s\\s\\s\\s\\s\\s\\s''."}]}]' +``` \ No newline at end of file diff --git a/action.yaml b/action.yaml index c8733b3..1ae71ed 100644 --- a/action.yaml +++ b/action.yaml @@ -12,7 +12,7 @@ inputs: default: '[]' outputs: html-output: - description: Result + description: Generated HTML code based on JSON input for the results. runs: using: 'docker' From 9a460b2e3997bc785b2d645b32d0f720f9c97f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Thu, 1 Feb 2024 20:10:22 +0100 Subject: [PATCH 14/41] PoC version #3 * Dump files --- docker/entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index a796c2f..8a19e94 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,6 +1,9 @@ #!/bin/sh -l echo "JSON Input $1" + +ls -l GITHUB_WORKSPACE + if html_output=$(python ./src/main.py "$1"); then echo "html-output=$html_output" >> $GITHUB_OUTPUT else From 479944f6662a040f70b6a55ea6b70b402148a082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Thu, 1 Feb 2024 20:11:59 +0100 Subject: [PATCH 15/41] PoC version #3 --- docker/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 8a19e94..8b70a66 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -2,7 +2,7 @@ echo "JSON Input $1" -ls -l GITHUB_WORKSPACE +ls -l $GITHUB_WORKSPACE if html_output=$(python ./src/main.py "$1"); then echo "html-output=$html_output" >> $GITHUB_OUTPUT From 1ccb17dcbc085c38c636727469a6e31a6356fba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sat, 3 Feb 2024 13:17:03 +0100 Subject: [PATCH 16/41] Added workdirectory parameter --- action.yaml | 7 ++++++- docker/entrypoint.sh | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/action.yaml b/action.yaml index 1ae71ed..2474c99 100644 --- a/action.yaml +++ b/action.yaml @@ -10,6 +10,11 @@ inputs: description: "JSON content generated by `dotnet format` command" required: true default: '[]' + runner-workdir: + description: "Directory path inside runner help to find correct file in repository" + required: false + default: '' + outputs: html-output: description: Generated HTML code based on JSON input for the results. @@ -19,4 +24,4 @@ runs: image: 'Dockerfile' args: - ${{ inputs.json-results }} -# - "[{\"TestVar\": \"TestOutput\"}]" + - ${{ inputs.runner-workdir }} diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 8b70a66..2d26788 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,10 +1,11 @@ #!/bin/sh -l echo "JSON Input $1" +echo "Runner work directory $2" ls -l $GITHUB_WORKSPACE -if html_output=$(python ./src/main.py "$1"); then +if html_output=$(python ./src/main.py "$1" "$2"); then echo "html-output=$html_output" >> $GITHUB_OUTPUT else echo "Unable return HTML output" From 975c97fe81261e0e7b3bc320a92995cb371ca4c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sat, 3 Feb 2024 13:25:00 +0100 Subject: [PATCH 17/41] Poc v1 --- docker/entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 2d26788..b6bd5f9 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -4,8 +4,9 @@ echo "JSON Input $1" echo "Runner work directory $2" ls -l $GITHUB_WORKSPACE +ls -l /action -if html_output=$(python ./src/main.py "$1" "$2"); then +if html_output=$(python /action/src/main.py "$1" "$2"); then echo "html-output=$html_output" >> $GITHUB_OUTPUT else echo "Unable return HTML output" From 145417d98935d60185686b27cfa6792c7518d9df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sat, 3 Feb 2024 14:02:05 +0100 Subject: [PATCH 18/41] Poc v1 --- docker/entrypoint.sh | 7 +++++-- src/main.py | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index b6bd5f9..81d750e 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -3,8 +3,11 @@ echo "JSON Input $1" echo "Runner work directory $2" -ls -l $GITHUB_WORKSPACE -ls -l /action +if pip install githubkit; then + echo "[OK] pip install githubkit" +else + echo "[KO] pip install githubkit" +fi if html_output=$(python /action/src/main.py "$1" "$2"); then echo "html-output=$html_output" >> $GITHUB_OUTPUT diff --git a/src/main.py b/src/main.py index 8cd6478..c8346e7 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,10 @@ import sys +from githubkit import GitHub, ActionAuthStrategy + +github = GitHub(ActionAuthStrategy()) + json_input = sys.argv[1] +runner_workdir = sys.argv[2] + html_output = f"Testing from Python

Testing workflow

{json_input}
" print(html_output) \ No newline at end of file From 3e7ff08cf12823e07feb9bd7dfb6528316bf273d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sat, 3 Feb 2024 16:46:08 +0100 Subject: [PATCH 19/41] Poc v1 --- .gitignore | 1 + Dockerfile | 2 +- src/__init__.py | 0 src/actions/Action.py | 9 ++++ src/actions/CreateReportAction.py | 14 +++++++ src/actions/__init__.py | 1 + src/app/Application.py | 70 +++++++++++++++++++++++++++++++ src/app/__init__.py | 1 + src/main.py | 11 ++--- src/models/Argument.py | 12 ++++++ src/models/__init__.py | 1 + src/myApp.py | 30 +++++++++++++ src/services/ExampleService.py | 8 ++++ src/services/ServiceAbstract.py | 8 ++++ src/services/__init__.py | 1 + 15 files changed, 161 insertions(+), 8 deletions(-) create mode 100644 .gitignore create mode 100644 src/__init__.py create mode 100644 src/actions/Action.py create mode 100644 src/actions/CreateReportAction.py create mode 100644 src/actions/__init__.py create mode 100644 src/app/Application.py create mode 100644 src/app/__init__.py create mode 100644 src/models/Argument.py create mode 100644 src/models/__init__.py create mode 100644 src/myApp.py create mode 100644 src/services/ExampleService.py create mode 100644 src/services/ServiceAbstract.py create mode 100644 src/services/__init__.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed8ebf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 323a01d..eb11945 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM python:3.11-bullseye COPY docker/entrypoint.sh /entrypoint.sh -WORKDIR action +WORKDIR /action COPY . . diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/actions/Action.py b/src/actions/Action.py new file mode 100644 index 0000000..c882702 --- /dev/null +++ b/src/actions/Action.py @@ -0,0 +1,9 @@ +class Action(): + _app = None + + def __init__(self, app): + self._app = app + pass + + def exec(self): + pass diff --git a/src/actions/CreateReportAction.py b/src/actions/CreateReportAction.py new file mode 100644 index 0000000..5b0882a --- /dev/null +++ b/src/actions/CreateReportAction.py @@ -0,0 +1,14 @@ +from actions.Action import Action + +class CreateReportAction(Action): + exampleService = None + + def __init__(self, app): + super().__init__(app) + self.exampleService = self._app.getService('ExampleService') + + def exec(self): + json_input = self._app.getArgumentByName('json_input') + htmlOutput = self.exampleService.createSampleText(json_input) + print(htmlOutput) + pass diff --git a/src/actions/__init__.py b/src/actions/__init__.py new file mode 100644 index 0000000..4bebda7 --- /dev/null +++ b/src/actions/__init__.py @@ -0,0 +1 @@ +from actions.CreateReportAction import CreateReportAction \ No newline at end of file diff --git a/src/app/Application.py b/src/app/Application.py new file mode 100644 index 0000000..5619356 --- /dev/null +++ b/src/app/Application.py @@ -0,0 +1,70 @@ +from models import Argument +from actions import * + +class Application(): + _appName = '' + _args = [] + _services = dict() + _action_module = 'actions' + _service_module = 'services' + + def __init__(self, appName = '', args = [], services = {}): + self._appName = appName + self._args = args + self._services = services + pass + + @staticmethod + def startUp(argv, entrypointAction = 'index'): + pass + + @staticmethod + def createArgumentsCollection(arg, collection): + collection.append(arg) + return collection + + @staticmethod + def createArgument(argName, argValue): + return Argument(argName, argValue) + + def getArgumentByName(self, argName): + for arg in self._args: + if arg.getName() == argName: + return arg.getValue() + + return None + + def registryService(self, serviceName): + if self.isServiceExists(serviceName) == True: + return + + module = __import__(self._service_module) + serviceClass = getattr(module, serviceName) + self._services[serviceName] = serviceClass(self._services, self) + pass + + def updateService(self, serviceName, serviceImpl): + if self.isServiceExists(serviceName) == False: + return + + module = __import__(self._service_module) + serviceClass = getattr(module, serviceName) + self._services[serviceName] = serviceClass(self._services, self) + pass + + def isServiceExists(self, serviceName): + if serviceName in self._services: + return True + + return False; + + def getService(self, serviceName): + if self.isServiceExists(serviceName) == False: + return None + + return self._services[serviceName] + + def runAction(self, actionName): + module = __import__(self._action_module) + actionClass = getattr(module, actionName) + return actionClass(self).exec() diff --git a/src/app/__init__.py b/src/app/__init__.py new file mode 100644 index 0000000..7e06b5a --- /dev/null +++ b/src/app/__init__.py @@ -0,0 +1 @@ +from app.Application import Application \ No newline at end of file diff --git a/src/main.py b/src/main.py index c8346e7..14794e3 100644 --- a/src/main.py +++ b/src/main.py @@ -1,10 +1,7 @@ import sys -from githubkit import GitHub, ActionAuthStrategy +from myApp import MyApp; -github = GitHub(ActionAuthStrategy()) +# from githubkit import GitHub, ActionAuthStrategy +# github = GitHub(ActionAuthStrategy()) -json_input = sys.argv[1] -runner_workdir = sys.argv[2] - -html_output = f"Testing from Python

Testing workflow

{json_input}
" -print(html_output) \ No newline at end of file +MyApp.startUp(sys.argv, 'CreateReportAction') \ No newline at end of file diff --git a/src/models/Argument.py b/src/models/Argument.py new file mode 100644 index 0000000..630f210 --- /dev/null +++ b/src/models/Argument.py @@ -0,0 +1,12 @@ +class Argument(): + def __init__(self, name, value): + self._name = name + self._value = value + pass + + def getName(self): + return self._name + + def getValue(self): + return self._value + \ No newline at end of file diff --git a/src/models/__init__.py b/src/models/__init__.py new file mode 100644 index 0000000..c27bf83 --- /dev/null +++ b/src/models/__init__.py @@ -0,0 +1 @@ +from models.Argument import Argument \ No newline at end of file diff --git a/src/myApp.py b/src/myApp.py new file mode 100644 index 0000000..fc04d4e --- /dev/null +++ b/src/myApp.py @@ -0,0 +1,30 @@ + +from app import Application + +class MyApp(Application): + def __init__(self,appName = '', args=[], services={}): + super().__init__(appName, args, services) + + @staticmethod + def startUp(argv, entrypointAction = 'index'): + argumentsCollection = MyApp.prepareArgumentsCollection(argv) + app = MyApp('dotnet-format-results', argumentsCollection) + + app.registryService('ExampleService') + + app.runAction(entrypointAction) + pass + + @staticmethod + def prepareArgumentsCollection(argv): + argumentsCollection = [] + argumentsCollection = MyApp.createArgumentsCollection( + arg = MyApp.createArgument('json_input', argv[1]), + collection = argumentsCollection + ) + argumentsCollection = MyApp.createArgumentsCollection( + arg = MyApp.createArgument('runner_workdir', argv[2]), + collection = argumentsCollection + ) + + return argumentsCollection \ No newline at end of file diff --git a/src/services/ExampleService.py b/src/services/ExampleService.py new file mode 100644 index 0000000..5f9a8f0 --- /dev/null +++ b/src/services/ExampleService.py @@ -0,0 +1,8 @@ +from services.ServiceAbstract import ServiceAbstract + +class ExampleService(ServiceAbstract): + def __init__(self, di={}, app=None): + super().__init__(di, app) + + def createSampleText(self, jsonInput): + return f"Testing from Python

Testing workflow

{jsonInput}
" diff --git a/src/services/ServiceAbstract.py b/src/services/ServiceAbstract.py new file mode 100644 index 0000000..0aca0eb --- /dev/null +++ b/src/services/ServiceAbstract.py @@ -0,0 +1,8 @@ +class ServiceAbstract(): + _di = {} + _app = None + + def __init__(self, di = {}, app = None): + self._di = di + self._app = app + pass diff --git a/src/services/__init__.py b/src/services/__init__.py new file mode 100644 index 0000000..41732cb --- /dev/null +++ b/src/services/__init__.py @@ -0,0 +1 @@ +from services.ExampleService import ExampleService \ No newline at end of file From f5f6b98f41e14477db6a0c193294df9027a60b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 11:58:21 +0100 Subject: [PATCH 20/41] Poc v1 --- docker/entrypoint.sh | 1 - src/actions/Action.py | 3 + src/actions/CreateReportAction.py | 12 ++- src/app/Application.py | 36 +------ src/app/DepedencyInjection.py | 30 ++++++ src/app/__init__.py | 3 +- src/main.py | 4 +- src/models/DotnetFormatChange.py | 30 ++++++ src/models/DotnetFormatDocument.py | 30 ++++++ src/models/DotnetFormatDocumentId.py | 14 +++ src/models/DotnetFormatProjectId.py | 9 ++ src/models/__init__.py | 6 +- src/myApp.py | 14 ++- src/services/ExampleService.py | 4 +- src/services/FileJsonEncoderService.py | 24 +++++ src/services/MapperDotnetFormatService.py | 120 ++++++++++++++++++++++ src/services/ServiceAbstract.py | 9 +- src/services/__init__.py | 4 +- 18 files changed, 303 insertions(+), 50 deletions(-) create mode 100644 src/app/DepedencyInjection.py create mode 100644 src/models/DotnetFormatChange.py create mode 100644 src/models/DotnetFormatDocument.py create mode 100644 src/models/DotnetFormatDocumentId.py create mode 100644 src/models/DotnetFormatProjectId.py create mode 100644 src/services/FileJsonEncoderService.py create mode 100644 src/services/MapperDotnetFormatService.py diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 81d750e..ed9a742 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -15,4 +15,3 @@ else echo "Unable return HTML output" exit 1 fi - diff --git a/src/actions/Action.py b/src/actions/Action.py index c882702..c902b76 100644 --- a/src/actions/Action.py +++ b/src/actions/Action.py @@ -7,3 +7,6 @@ def __init__(self, app): def exec(self): pass + + def injectService(self, serviceName): + return self._app._di.getService(serviceName) diff --git a/src/actions/CreateReportAction.py b/src/actions/CreateReportAction.py index 5b0882a..059823f 100644 --- a/src/actions/CreateReportAction.py +++ b/src/actions/CreateReportAction.py @@ -1,14 +1,22 @@ from actions.Action import Action +from pprint import pprint +from inspect import getmembers class CreateReportAction(Action): exampleService = None - + fileJsonEncoderService = None + def __init__(self, app): super().__init__(app) - self.exampleService = self._app.getService('ExampleService') + self.exampleService = self.injectService('ExampleService') + self.fileJsonEncoderService = self.injectService('FileJsonEncoderService') def exec(self): json_input = self._app.getArgumentByName('json_input') + documentsCollection = self.fileJsonEncoderService.loadDocumentCollestionFromText(json_input) + #pprint(documentsCollection) + htmlOutput = self.exampleService.createSampleText(json_input) + print(htmlOutput) pass diff --git a/src/app/Application.py b/src/app/Application.py index 5619356..7eeb2dc 100644 --- a/src/app/Application.py +++ b/src/app/Application.py @@ -4,14 +4,14 @@ class Application(): _appName = '' _args = [] - _services = dict() + _di = None _action_module = 'actions' _service_module = 'services' - def __init__(self, appName = '', args = [], services = {}): + def __init__(self, appName = '', args = [], di = {}): self._appName = appName self._args = args - self._services = services + self._di = di pass @staticmethod @@ -34,36 +34,6 @@ def getArgumentByName(self, argName): return None - def registryService(self, serviceName): - if self.isServiceExists(serviceName) == True: - return - - module = __import__(self._service_module) - serviceClass = getattr(module, serviceName) - self._services[serviceName] = serviceClass(self._services, self) - pass - - def updateService(self, serviceName, serviceImpl): - if self.isServiceExists(serviceName) == False: - return - - module = __import__(self._service_module) - serviceClass = getattr(module, serviceName) - self._services[serviceName] = serviceClass(self._services, self) - pass - - def isServiceExists(self, serviceName): - if serviceName in self._services: - return True - - return False; - - def getService(self, serviceName): - if self.isServiceExists(serviceName) == False: - return None - - return self._services[serviceName] - def runAction(self, actionName): module = __import__(self._action_module) actionClass = getattr(module, actionName) diff --git a/src/app/DepedencyInjection.py b/src/app/DepedencyInjection.py new file mode 100644 index 0000000..211eac3 --- /dev/null +++ b/src/app/DepedencyInjection.py @@ -0,0 +1,30 @@ +class DepedencyInjection(): + _di_services = [] + _service_module = 'services' + + def __init__(self, containers): + self._di_services = containers + pass + + def registryService(self, serviceName): + if (len(self._di_services) == 0): + self._di_services.append(dict()) + + if self.isServiceExists(serviceName) == True: + return + + module = __import__(self._service_module) + serviceClass = getattr(module, serviceName) + self._di_services[0][serviceName] = serviceClass(self) + pass + + def isServiceExists(self, serviceName): + if len(self._di_services) > 0: + if serviceName in self._di_services[0]: + return True + + return False + + def getService(self, serviceName): + self.registryService(serviceName) + return self._di_services[0][serviceName] diff --git a/src/app/__init__.py b/src/app/__init__.py index 7e06b5a..94338d3 100644 --- a/src/app/__init__.py +++ b/src/app/__init__.py @@ -1 +1,2 @@ -from app.Application import Application \ No newline at end of file +from app.Application import Application +from app.DepedencyInjection import DepedencyInjection \ No newline at end of file diff --git a/src/main.py b/src/main.py index 14794e3..8ff4fae 100644 --- a/src/main.py +++ b/src/main.py @@ -4,4 +4,6 @@ # from githubkit import GitHub, ActionAuthStrategy # github = GitHub(ActionAuthStrategy()) -MyApp.startUp(sys.argv, 'CreateReportAction') \ No newline at end of file +containers = [] + +MyApp.startUp(sys.argv, containers, 'CreateReportAction') \ No newline at end of file diff --git a/src/models/DotnetFormatChange.py b/src/models/DotnetFormatChange.py new file mode 100644 index 0000000..eb7032b --- /dev/null +++ b/src/models/DotnetFormatChange.py @@ -0,0 +1,30 @@ +class DotnetFormatChange(): + _lineNumber = '' + _charNumber = '' + _diagnosticId = '' + _formatDescription = '' + + def __init__( + self, + lineNumber, + charNumber, + diagnosticId, + formatDescription + ): + self._lineNumber = lineNumber + self._charNumber = charNumber + self._diagnosticId = diagnosticId + self._formatDescription = formatDescription + pass + + def getLineNumber(self): + return self._lineNumber + + def getCharNumber(self): + return self._charNumber + + def getDiagnosticId(self): + return self._diagnosticId + + def getFormatDescription(self): + return self._formatDescription diff --git a/src/models/DotnetFormatDocument.py b/src/models/DotnetFormatDocument.py new file mode 100644 index 0000000..b69fcf6 --- /dev/null +++ b/src/models/DotnetFormatDocument.py @@ -0,0 +1,30 @@ +class DotnetFormatDocument(): + _documentId = None + _fileName = '' + _filePath = '' + _fileChanges = [] + + def __init__( + self, + documentId, + fileName, + filePath, + fileChanges = [] + ): + self._documentId = documentId + self._fileName = fileName + self._filePath = filePath + self._fileChanges = fileChanges + pass + + def getDocumentId(self): + return self._documentId + + def getFileName(self): + return self._fileName + + def getFilePath(self): + return self._filePath + + def getFileChanges(self): + return self._fileChanges diff --git a/src/models/DotnetFormatDocumentId.py b/src/models/DotnetFormatDocumentId.py new file mode 100644 index 0000000..3d2f27a --- /dev/null +++ b/src/models/DotnetFormatDocumentId.py @@ -0,0 +1,14 @@ +class DotnetFormatDocumentId(): + _projectId = None + _id = '' + + def __init__(self, projectId, id): + self._projectId = projectId + self._id = id + pass + + def getProjectId(self): + return self._projectId + + def getId(self): + return self._id diff --git a/src/models/DotnetFormatProjectId.py b/src/models/DotnetFormatProjectId.py new file mode 100644 index 0000000..311cba5 --- /dev/null +++ b/src/models/DotnetFormatProjectId.py @@ -0,0 +1,9 @@ +class DotnetFormatProjectId(): + _id = '' + + def __init__(self, id): + self._id = id + pass + + def getId(self): + return self._id diff --git a/src/models/__init__.py b/src/models/__init__.py index c27bf83..bcdaaaf 100644 --- a/src/models/__init__.py +++ b/src/models/__init__.py @@ -1 +1,5 @@ -from models.Argument import Argument \ No newline at end of file +from models.Argument import Argument +from models.DotnetFormatDocument import DotnetFormatDocument +from models.DotnetFormatDocumentId import DotnetFormatDocumentId +from models.DotnetFormatProjectId import DotnetFormatProjectId +from models.DotnetFormatChange import DotnetFormatChange \ No newline at end of file diff --git a/src/myApp.py b/src/myApp.py index fc04d4e..7a54881 100644 --- a/src/myApp.py +++ b/src/myApp.py @@ -1,17 +1,23 @@ from app import Application +from app import DepedencyInjection class MyApp(Application): def __init__(self,appName = '', args=[], services={}): super().__init__(appName, args, services) @staticmethod - def startUp(argv, entrypointAction = 'index'): - argumentsCollection = MyApp.prepareArgumentsCollection(argv) - app = MyApp('dotnet-format-results', argumentsCollection) + def startUp(argv, containers, entrypointAction = 'index'): - app.registryService('ExampleService') + argumentsCollection = MyApp.prepareArgumentsCollection(argv) + di = DepedencyInjection(containers); + di.registryService('ExampleService') + di.registryService('FileJsonEncoderService') + di.registryService('MapperDotnetFormatService') + + app = MyApp('dotnet-format-results', argumentsCollection, di) + app.runAction(entrypointAction) pass diff --git a/src/services/ExampleService.py b/src/services/ExampleService.py index 5f9a8f0..b4263b9 100644 --- a/src/services/ExampleService.py +++ b/src/services/ExampleService.py @@ -1,8 +1,8 @@ from services.ServiceAbstract import ServiceAbstract class ExampleService(ServiceAbstract): - def __init__(self, di={}, app=None): - super().__init__(di, app) + def __init__(self, di = None): + super().__init__(di) def createSampleText(self, jsonInput): return f"Testing from Python

Testing workflow

{jsonInput}
" diff --git a/src/services/FileJsonEncoderService.py b/src/services/FileJsonEncoderService.py new file mode 100644 index 0000000..75139ea --- /dev/null +++ b/src/services/FileJsonEncoderService.py @@ -0,0 +1,24 @@ +from services.ServiceAbstract import ServiceAbstract +from models import DotnetFormatChange, DotnetFormatProjectId, DotnetFormatDocumentId, DotnetFormatDocument +import json +from pprint import pprint +from inspect import getmembers + +class FileJsonEncoderService(ServiceAbstract): + mapperService = None + + def __init__(self, di = None): + super().__init__(di) + self.mapperService = self.injectService('MapperDotnetFormatService') + + def loadDocumentCollestionFromText(self, documentCollestionText): + documentsCollection = [] + rawData = json.loads(documentCollestionText) + + #pprint(rawData); + + documentsCollection = self.mapperService.mapDocumentsCollectionFromJson(rawData) + + return documentsCollection + + \ No newline at end of file diff --git a/src/services/MapperDotnetFormatService.py b/src/services/MapperDotnetFormatService.py new file mode 100644 index 0000000..a2f9c8a --- /dev/null +++ b/src/services/MapperDotnetFormatService.py @@ -0,0 +1,120 @@ +from services.ServiceAbstract import ServiceAbstract +from models import DotnetFormatChange, DotnetFormatProjectId, DotnetFormatDocumentId, DotnetFormatDocument +from pprint import pprint +from inspect import getmembers + +class MapperDotnetFormatService(ServiceAbstract): + def __init__(self, di = None): + """The class is responsible for mapping raw data transformed from a JSON string + into a list of objects in the MapperDotnetFormatService format. This service encapsulates the logic for transforming + JSON data into a specific format defined by the MapperDotnetFormatService, providing a convenient and reusable way + to process and work with data in a standardized manner. + + Args: + di (_type_, optional): _description_. Defaults to None. + """ + + super().__init__(di) + + def mapDocumentsCollectionFromJson(self, rawData): + """Maps a collection of documents from raw JSON data to an array of objects in the DotnetFormatDocument format. + + Args: + rawData (List): An array returned from an external source in JSON format containing document data. + + Returns: + List: An array of objects representing the transformed documents in the DotnetFormatDocument format. + """ + + documentsCollection = [] + + for rawDocument in rawData: + documentsCollection.append(self._createDocument(rawDocument)) + + return documentsCollection + + def _createDocument(self, rawDocument): + """Private function that creates and returns an array of DotnetFormatDocument objects + from an associative array retrieved from an external source in JSON format. + + Args: + rawDocument (dict): An associative array containing raw document data in JSON format. + + Returns: + DotnetFormatDocument: objects representing the transformed documents in the DotnetFormatDocument format. + """ + + documentId = self._createDocumentId(rawDocument['DocumentId']) + + return DotnetFormatDocument( + documentId = documentId, + fileName = rawDocument['FileName'], + filePath = rawDocument['FilePath'], + fileChanges = self._createChangesCollection(rawDocument['FileChanges']) + ) + + def _createDocumentId(self, rawDocumentId): + """Private function that creates and returns a DotnetFormatDocumentId object + from an associative array retrieved from an external source in JSON format. + + Args: + rawDocumentId (Dict): An associative array containing raw document ID data in JSON format. + + Returns: + DotnetFormatDocumentId: An object representing the transformed document ID in the DotnetFormatDocumentId format. + """ + + return DotnetFormatDocumentId( + projectId = self._createProjectId(rawDocumentId['ProjectId']), + id = rawDocumentId['Id'] + ) + + def _createProjectId(self, rawProjectId): + """Private function that creates and returns a DotnetFormatProjectId object + from an associative array retrieved from an external source in JSON format. + + Args: + rawProjectId (Dict): An associative array containing raw project ID data in JSON format. + + Returns: + DotnetFormatProjectId: An object representing the transformed project ID in the DotnetFormatProjectId format. + """ + + return DotnetFormatProjectId(id = rawProjectId['Id']) + + def _createChangesCollection(self, rawFileChanges): + """Private function that creates and returns an array of DotnetFormatChange objects + from an array of associative arrays retrieved from an external source in JSON format. + + Args: + rawFileChanges (List[Dict[str, Any]]): An array of associative arrays containing raw file change data in JSON format. + + Returns: + List: An array of objects representing the transformed file changes in the DotnetFormatChange format. + """ + + changesCollection = [] + + for rawFileChange in rawFileChanges: + changesCollection.append(self._createFileChange(rawFileChange)) + + return changesCollection + + def _createFileChange(self, rawFileChange): + """Private function that creates and returns a DotnetFormatChange object + from an associative array retrieved from an external source in JSON format. + + Args: + rawFileChange (Dict): An associative array containing raw file change data in JSON format. + + Returns: + DotnetFormatChange: An object representing the transformed file change in the DotnetFormatChange format. + """ + + return DotnetFormatChange( + lineNumber = rawFileChange['LineNumber'], + charNumber = rawFileChange['CharNumber'], + diagnosticId = rawFileChange['DiagnosticId'], + formatDescription = rawFileChange['FormatDescription'] + ) + \ No newline at end of file diff --git a/src/services/ServiceAbstract.py b/src/services/ServiceAbstract.py index 0aca0eb..de9669f 100644 --- a/src/services/ServiceAbstract.py +++ b/src/services/ServiceAbstract.py @@ -1,8 +1,9 @@ class ServiceAbstract(): - _di = {} - _app = None + _di = None - def __init__(self, di = {}, app = None): + def __init__(self, di = None): self._di = di - self._app = app pass + + def injectService(self, serviceName): + return self._di.getService(serviceName) diff --git a/src/services/__init__.py b/src/services/__init__.py index 41732cb..37f6395 100644 --- a/src/services/__init__.py +++ b/src/services/__init__.py @@ -1 +1,3 @@ -from services.ExampleService import ExampleService \ No newline at end of file +from services.ExampleService import ExampleService +from services.FileJsonEncoderService import FileJsonEncoderService +from services.MapperDotnetFormatService import MapperDotnetFormatService \ No newline at end of file From d91248455ca8b4791588f0f3331c35900591f876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 14:24:19 +0100 Subject: [PATCH 21/41] Poc v1 --- docker/entrypoint.sh | 2 ++ src/actions/CreateReportAction.py | 2 ++ src/myApp.py | 1 + src/services/GitHubChecksService.py | 36 +++++++++++++++++++++++ src/services/MapperDotnetFormatService.py | 4 +-- src/services/__init__.py | 3 +- 6 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 src/services/GitHubChecksService.py diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index ed9a742..40cf58e 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -9,6 +9,8 @@ else echo "[KO] pip install githubkit" fi +echo -e "${GITHUB_SHA} \n" + if html_output=$(python /action/src/main.py "$1" "$2"); then echo "html-output=$html_output" >> $GITHUB_OUTPUT else diff --git a/src/actions/CreateReportAction.py b/src/actions/CreateReportAction.py index 059823f..feef3a1 100644 --- a/src/actions/CreateReportAction.py +++ b/src/actions/CreateReportAction.py @@ -5,11 +5,13 @@ class CreateReportAction(Action): exampleService = None fileJsonEncoderService = None + gitHubChecksService = None def __init__(self, app): super().__init__(app) self.exampleService = self.injectService('ExampleService') self.fileJsonEncoderService = self.injectService('FileJsonEncoderService') + self.gitHubChecksService = self.injectService('GitHubChecksService') def exec(self): json_input = self._app.getArgumentByName('json_input') diff --git a/src/myApp.py b/src/myApp.py index 7a54881..75961fb 100644 --- a/src/myApp.py +++ b/src/myApp.py @@ -15,6 +15,7 @@ def startUp(argv, containers, entrypointAction = 'index'): di.registryService('ExampleService') di.registryService('FileJsonEncoderService') di.registryService('MapperDotnetFormatService') + di.registryService('GitHubChecksService') app = MyApp('dotnet-format-results', argumentsCollection, di) diff --git a/src/services/GitHubChecksService.py b/src/services/GitHubChecksService.py new file mode 100644 index 0000000..d9f9f4b --- /dev/null +++ b/src/services/GitHubChecksService.py @@ -0,0 +1,36 @@ +from services.ServiceAbstract import ServiceAbstract +from githubkit import GitHub, ActionAuthStrategy, Response + +class GitHubChecksService(ServiceAbstract): + _github = None + _owner = "ACTION-DOTNET-FORMAT-RESULTS" + _repo = "REPO" + _checkName = ".NET Format Results [beta]" + _externalId = "action-dotnet-format-results" + + def __init__(self, di = None): + """_summary_ + + Args: + di (DepedencyInjection, optional): _description_. Defaults to None. + """ + + super().__init__(di) + self._github = GitHub(ActionAuthStrategy()) + + def CreateNewCheck(self): + resp = self._github.rest.checks.async_create( + owner = self._owner, + repo = self._repo, + name = self._checkName, + external_id = self._externalId, + status = 'completed', + conclusion = 'skipped', + output = { + "title": ".NET Format Results [beta]", + "summary": "", + "text": "", + } + ) + pass + \ No newline at end of file diff --git a/src/services/MapperDotnetFormatService.py b/src/services/MapperDotnetFormatService.py index a2f9c8a..0fab5c7 100644 --- a/src/services/MapperDotnetFormatService.py +++ b/src/services/MapperDotnetFormatService.py @@ -5,13 +5,13 @@ class MapperDotnetFormatService(ServiceAbstract): def __init__(self, di = None): - """The class is responsible for mapping raw data transformed from a JSON string + """The MapperDotnetFormatService class is responsible for mapping raw data transformed from a JSON string into a list of objects in the MapperDotnetFormatService format. This service encapsulates the logic for transforming JSON data into a specific format defined by the MapperDotnetFormatService, providing a convenient and reusable way to process and work with data in a standardized manner. Args: - di (_type_, optional): _description_. Defaults to None. + di (DepedencyInjection, optional): _description_. Defaults to None. """ super().__init__(di) diff --git a/src/services/__init__.py b/src/services/__init__.py index 37f6395..c4a9be3 100644 --- a/src/services/__init__.py +++ b/src/services/__init__.py @@ -1,3 +1,4 @@ from services.ExampleService import ExampleService from services.FileJsonEncoderService import FileJsonEncoderService -from services.MapperDotnetFormatService import MapperDotnetFormatService \ No newline at end of file +from services.MapperDotnetFormatService import MapperDotnetFormatService +from services.GitHubChecksService import GitHubChecksService \ No newline at end of file From c356e9cb4ae4a1735ea0bdb118d9c53092c0fcaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 14:28:53 +0100 Subject: [PATCH 22/41] Poc v1 --- docker/entrypoint.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 40cf58e..9ea803a 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -9,7 +9,13 @@ else echo "[KO] pip install githubkit" fi -echo -e "${GITHUB_SHA} \n" +echo "GITHUB_SHA: ${GITHUB_SHA} \n" +echo "GITHUB_REPOSITORY_OWNER: ${GITHUB_REPOSITORY_OWNER} \n" +echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY} \n" +echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF} \n" +echo "GITHUB_ACTION_REF: ${GITHUB_ACTION_REF} \n" + + if html_output=$(python /action/src/main.py "$1" "$2"); then echo "html-output=$html_output" >> $GITHUB_OUTPUT From 8d560bcbb9ac9d89ecddc1c25140b4f39cc9d2ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 15:10:13 +0100 Subject: [PATCH 23/41] Poc v1 --- docker/entrypoint.sh | 4 ++-- src/actions/Action.py | 5 ++++- src/actions/CreateReportAction.py | 2 ++ src/app/DepedencyInjection.py | 8 ++++---- src/main.py | 3 ++- src/myApp.py | 20 +++++++++++++------- src/services/ExampleService.py | 4 ++-- src/services/FileJsonEncoderService.py | 4 ++-- src/services/GitHubChecksService.py | 20 +++++++++++++------- src/services/MapperDotnetFormatService.py | 4 ++-- src/services/ServiceAbstract.py | 10 ++++++++-- 11 files changed, 54 insertions(+), 30 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 9ea803a..97c2484 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -15,9 +15,9 @@ echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY} \n" echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF} \n" echo "GITHUB_ACTION_REF: ${GITHUB_ACTION_REF} \n" +gitHubConfig="{\"SHA\": \"${GITHUB_SHA}\", \"REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\", \"REPOSITORY\": \"${GITHUB_REPOSITORY}\"}" - -if html_output=$(python /action/src/main.py "$1" "$2"); then +if html_output=$(python /action/src/main.py "$1" "$2" "${gitHubConfig}"); then echo "html-output=$html_output" >> $GITHUB_OUTPUT else echo "Unable return HTML output" diff --git a/src/actions/Action.py b/src/actions/Action.py index c902b76..9d35b2e 100644 --- a/src/actions/Action.py +++ b/src/actions/Action.py @@ -9,4 +9,7 @@ def exec(self): pass def injectService(self, serviceName): - return self._app._di.getService(serviceName) + return self._app._di.getService(serviceName, self._app) + + def injectConfigByName(self, configName): + return self._app.getArgumentByName(configName) diff --git a/src/actions/CreateReportAction.py b/src/actions/CreateReportAction.py index feef3a1..b4fce66 100644 --- a/src/actions/CreateReportAction.py +++ b/src/actions/CreateReportAction.py @@ -16,6 +16,8 @@ def __init__(self, app): def exec(self): json_input = self._app.getArgumentByName('json_input') documentsCollection = self.fileJsonEncoderService.loadDocumentCollestionFromText(json_input) + self.gitHubChecksService.CreateNewCheck() + #pprint(documentsCollection) htmlOutput = self.exampleService.createSampleText(json_input) diff --git a/src/app/DepedencyInjection.py b/src/app/DepedencyInjection.py index 211eac3..cd59ad7 100644 --- a/src/app/DepedencyInjection.py +++ b/src/app/DepedencyInjection.py @@ -6,7 +6,7 @@ def __init__(self, containers): self._di_services = containers pass - def registryService(self, serviceName): + def registryService(self, serviceName, app): if (len(self._di_services) == 0): self._di_services.append(dict()) @@ -15,7 +15,7 @@ def registryService(self, serviceName): module = __import__(self._service_module) serviceClass = getattr(module, serviceName) - self._di_services[0][serviceName] = serviceClass(self) + self._di_services[0][serviceName] = serviceClass(self, app) pass def isServiceExists(self, serviceName): @@ -25,6 +25,6 @@ def isServiceExists(self, serviceName): return False - def getService(self, serviceName): - self.registryService(serviceName) + def getService(self, serviceName, app): + self.registryService(serviceName, app) return self._di_services[0][serviceName] diff --git a/src/main.py b/src/main.py index 8ff4fae..8dbca37 100644 --- a/src/main.py +++ b/src/main.py @@ -1,9 +1,10 @@ import sys from myApp import MyApp; +from pprint import pprint +from inspect import getmembers # from githubkit import GitHub, ActionAuthStrategy # github = GitHub(ActionAuthStrategy()) containers = [] - MyApp.startUp(sys.argv, containers, 'CreateReportAction') \ No newline at end of file diff --git a/src/myApp.py b/src/myApp.py index 75961fb..adb6934 100644 --- a/src/myApp.py +++ b/src/myApp.py @@ -1,6 +1,7 @@ from app import Application from app import DepedencyInjection +import json class MyApp(Application): def __init__(self,appName = '', args=[], services={}): @@ -10,15 +11,10 @@ def __init__(self,appName = '', args=[], services={}): def startUp(argv, containers, entrypointAction = 'index'): argumentsCollection = MyApp.prepareArgumentsCollection(argv) - + di = DepedencyInjection(containers); - di.registryService('ExampleService') - di.registryService('FileJsonEncoderService') - di.registryService('MapperDotnetFormatService') - di.registryService('GitHubChecksService') app = MyApp('dotnet-format-results', argumentsCollection, di) - app.runAction(entrypointAction) pass @@ -29,9 +25,19 @@ def prepareArgumentsCollection(argv): arg = MyApp.createArgument('json_input', argv[1]), collection = argumentsCollection ) + argumentsCollection = MyApp.createArgumentsCollection( arg = MyApp.createArgument('runner_workdir', argv[2]), collection = argumentsCollection ) - return argumentsCollection \ No newline at end of file + argumentsCollection = MyApp.createArgumentsCollection( + arg = MyApp.createArgument('github_config', MyApp.readJsonConfig(argv[3])), + collection = argumentsCollection + ) + + return argumentsCollection + + @staticmethod + def readJsonConfig(rawText): + return json.loads(rawText) diff --git a/src/services/ExampleService.py b/src/services/ExampleService.py index b4263b9..059da73 100644 --- a/src/services/ExampleService.py +++ b/src/services/ExampleService.py @@ -1,8 +1,8 @@ from services.ServiceAbstract import ServiceAbstract class ExampleService(ServiceAbstract): - def __init__(self, di = None): - super().__init__(di) + def __init__(self, di = None, app = None): + super().__init__(di, app) def createSampleText(self, jsonInput): return f"Testing from Python

Testing workflow

{jsonInput}
" diff --git a/src/services/FileJsonEncoderService.py b/src/services/FileJsonEncoderService.py index 75139ea..8d62597 100644 --- a/src/services/FileJsonEncoderService.py +++ b/src/services/FileJsonEncoderService.py @@ -7,8 +7,8 @@ class FileJsonEncoderService(ServiceAbstract): mapperService = None - def __init__(self, di = None): - super().__init__(di) + def __init__(self, di = None, app = None): + super().__init__(di, app) self.mapperService = self.injectService('MapperDotnetFormatService') def loadDocumentCollestionFromText(self, documentCollestionText): diff --git a/src/services/GitHubChecksService.py b/src/services/GitHubChecksService.py index d9f9f4b..8a10eec 100644 --- a/src/services/GitHubChecksService.py +++ b/src/services/GitHubChecksService.py @@ -1,27 +1,30 @@ from services.ServiceAbstract import ServiceAbstract from githubkit import GitHub, ActionAuthStrategy, Response +from pprint import pprint +from inspect import getmembers class GitHubChecksService(ServiceAbstract): _github = None - _owner = "ACTION-DOTNET-FORMAT-RESULTS" - _repo = "REPO" + _gitHubConfig = None _checkName = ".NET Format Results [beta]" _externalId = "action-dotnet-format-results" - def __init__(self, di = None): + def __init__(self, di = None, app = None): """_summary_ Args: di (DepedencyInjection, optional): _description_. Defaults to None. """ - super().__init__(di) + super().__init__(di, app) self._github = GitHub(ActionAuthStrategy()) + self._gitHubConfig = self.injectConfigByName('github_config') def CreateNewCheck(self): - resp = self._github.rest.checks.async_create( - owner = self._owner, - repo = self._repo, + resp = self._github.rest.checks.create( + head_sha = self._gitHubConfig['SHA'], + owner = self._gitHubConfig['REPOSITORY_OWNER'], + repo = self._gitHubConfig['REPOSITORY'], name = self._checkName, external_id = self._externalId, status = 'completed', @@ -32,5 +35,8 @@ def CreateNewCheck(self): "text": "", } ) + + pprint(resp) + pass \ No newline at end of file diff --git a/src/services/MapperDotnetFormatService.py b/src/services/MapperDotnetFormatService.py index 0fab5c7..08c7df7 100644 --- a/src/services/MapperDotnetFormatService.py +++ b/src/services/MapperDotnetFormatService.py @@ -4,7 +4,7 @@ from inspect import getmembers class MapperDotnetFormatService(ServiceAbstract): - def __init__(self, di = None): + def __init__(self, di = None, app = None): """The MapperDotnetFormatService class is responsible for mapping raw data transformed from a JSON string into a list of objects in the MapperDotnetFormatService format. This service encapsulates the logic for transforming JSON data into a specific format defined by the MapperDotnetFormatService, providing a convenient and reusable way @@ -14,7 +14,7 @@ def __init__(self, di = None): di (DepedencyInjection, optional): _description_. Defaults to None. """ - super().__init__(di) + super().__init__(di, app) def mapDocumentsCollectionFromJson(self, rawData): """Maps a collection of documents from raw JSON data to an array of objects in the DotnetFormatDocument format. diff --git a/src/services/ServiceAbstract.py b/src/services/ServiceAbstract.py index de9669f..bb86a83 100644 --- a/src/services/ServiceAbstract.py +++ b/src/services/ServiceAbstract.py @@ -1,9 +1,15 @@ class ServiceAbstract(): _di = None + _app = None - def __init__(self, di = None): + def __init__(self, di = None, app = None): self._di = di + self._app = app pass def injectService(self, serviceName): - return self._di.getService(serviceName) + return self._di.getService(serviceName, self._app) + + def injectConfigByName(self, configName): + return self._app.getArgumentByName(configName) + From e46e44478008f3ba1c6d12440c585d9e9c8ceb2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 15:16:21 +0100 Subject: [PATCH 24/41] Poc v1 --- .github/workflows/test-dotnet-format-results.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test-dotnet-format-results.yml b/.github/workflows/test-dotnet-format-results.yml index b53541c..67a7e94 100644 --- a/.github/workflows/test-dotnet-format-results.yml +++ b/.github/workflows/test-dotnet-format-results.yml @@ -9,6 +9,8 @@ jobs: uses: actions/checkout@v4 - name: "Uses" id: output-convert + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} uses: ./ with: json-results: '[{"DocumentId":{"ProjectId":{"Id":"f307936d-8b40-4e7c-897c-0f16889c4163"},"Id":"70e32bdf-23e9-4482-a949-65384ce65fce"},"FileName":"WeatherForecastRepository.cs","FilePath":"F:\\Projekty\\crontab-registry\\src\\CrontabRegistry\\Infrastructure\\Repositories\\WeatherForecastRepository.cs","FileChanges":[{"LineNumber":13,"CharNumber":28,"DiagnosticId":"WHITESPACE","FormatDescription":"Napraw formatowanie odstępów. Replace 1 characters with ''\\r\\n\\s\\s\\s\\s\\s\\s\\s\\s''."}]}]' From f1054054e55c85422bb7743f3e144fce4f1063e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 15:18:07 +0100 Subject: [PATCH 25/41] Poc v1 --- docker/entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 97c2484..6a62a94 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -14,6 +14,7 @@ echo "GITHUB_REPOSITORY_OWNER: ${GITHUB_REPOSITORY_OWNER} \n" echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY} \n" echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF} \n" echo "GITHUB_ACTION_REF: ${GITHUB_ACTION_REF} \n" +echo "GITHUB_TOKEN: ${GITHUB_TOKEN} \n" gitHubConfig="{\"SHA\": \"${GITHUB_SHA}\", \"REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\", \"REPOSITORY\": \"${GITHUB_REPOSITORY}\"}" From f634523df529e536914838967e3ef532c689e139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 15:20:02 +0100 Subject: [PATCH 26/41] Poc v1 --- src/services/GitHubChecksService.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/services/GitHubChecksService.py b/src/services/GitHubChecksService.py index 8a10eec..9b1f2fa 100644 --- a/src/services/GitHubChecksService.py +++ b/src/services/GitHubChecksService.py @@ -28,12 +28,7 @@ def CreateNewCheck(self): name = self._checkName, external_id = self._externalId, status = 'completed', - conclusion = 'skipped', - output = { - "title": ".NET Format Results [beta]", - "summary": "", - "text": "", - } + conclusion = 'skipped' ) pprint(resp) From 261a04d9277711846a7718b9ea7ef0492a0df45d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 15:21:19 +0100 Subject: [PATCH 27/41] Poc v1 --- src/services/GitHubChecksService.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/GitHubChecksService.py b/src/services/GitHubChecksService.py index 9b1f2fa..baea818 100644 --- a/src/services/GitHubChecksService.py +++ b/src/services/GitHubChecksService.py @@ -21,7 +21,7 @@ def __init__(self, di = None, app = None): self._gitHubConfig = self.injectConfigByName('github_config') def CreateNewCheck(self): - resp = self._github.rest.checks.create( + resp = self._github.rest.checks.async_create( head_sha = self._gitHubConfig['SHA'], owner = self._gitHubConfig['REPOSITORY_OWNER'], repo = self._gitHubConfig['REPOSITORY'], From e486315753cef2fe3888b17bfdb6279813e8c996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 15:26:44 +0100 Subject: [PATCH 28/41] Poc v1 --- src/actions/CreateReportAction.py | 4 ++-- src/main.py | 3 ++- src/myApp.py | 4 ++-- src/services/GitHubChecksService.py | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/actions/CreateReportAction.py b/src/actions/CreateReportAction.py index b4fce66..8a30127 100644 --- a/src/actions/CreateReportAction.py +++ b/src/actions/CreateReportAction.py @@ -13,10 +13,10 @@ def __init__(self, app): self.fileJsonEncoderService = self.injectService('FileJsonEncoderService') self.gitHubChecksService = self.injectService('GitHubChecksService') - def exec(self): + async def exec(self): json_input = self._app.getArgumentByName('json_input') documentsCollection = self.fileJsonEncoderService.loadDocumentCollestionFromText(json_input) - self.gitHubChecksService.CreateNewCheck() + await self.gitHubChecksService.CreateNewCheck() #pprint(documentsCollection) diff --git a/src/main.py b/src/main.py index 8dbca37..431b84f 100644 --- a/src/main.py +++ b/src/main.py @@ -2,9 +2,10 @@ from myApp import MyApp; from pprint import pprint from inspect import getmembers +import asyncio # from githubkit import GitHub, ActionAuthStrategy # github = GitHub(ActionAuthStrategy()) containers = [] -MyApp.startUp(sys.argv, containers, 'CreateReportAction') \ No newline at end of file +asyncio.run(MyApp.startUp(sys.argv, containers, 'CreateReportAction')) \ No newline at end of file diff --git a/src/myApp.py b/src/myApp.py index adb6934..80f434f 100644 --- a/src/myApp.py +++ b/src/myApp.py @@ -8,14 +8,14 @@ def __init__(self,appName = '', args=[], services={}): super().__init__(appName, args, services) @staticmethod - def startUp(argv, containers, entrypointAction = 'index'): + async def startUp(argv, containers, entrypointAction = 'index'): argumentsCollection = MyApp.prepareArgumentsCollection(argv) di = DepedencyInjection(containers); app = MyApp('dotnet-format-results', argumentsCollection, di) - app.runAction(entrypointAction) + await app.runAction(entrypointAction) pass @staticmethod diff --git a/src/services/GitHubChecksService.py b/src/services/GitHubChecksService.py index baea818..4fd854b 100644 --- a/src/services/GitHubChecksService.py +++ b/src/services/GitHubChecksService.py @@ -20,8 +20,8 @@ def __init__(self, di = None, app = None): self._github = GitHub(ActionAuthStrategy()) self._gitHubConfig = self.injectConfigByName('github_config') - def CreateNewCheck(self): - resp = self._github.rest.checks.async_create( + async def CreateNewCheck(self): + resp = await self._github.rest.checks.async_create( head_sha = self._gitHubConfig['SHA'], owner = self._gitHubConfig['REPOSITORY_OWNER'], repo = self._gitHubConfig['REPOSITORY'], From 1629aabddf8f215d16860048736f02c4d656099b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 16:44:52 +0100 Subject: [PATCH 29/41] Poc v1 --- docker/entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 6a62a94..125a4cc 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -15,6 +15,8 @@ echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY} \n" echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF} \n" echo "GITHUB_ACTION_REF: ${GITHUB_ACTION_REF} \n" echo "GITHUB_TOKEN: ${GITHUB_TOKEN} \n" +echo "GITHUB_REF: ${GITHUB_REF} \n" +echo "GITHUB_REF_NAME: ${GITHUB_REF_NAME} \n" gitHubConfig="{\"SHA\": \"${GITHUB_SHA}\", \"REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\", \"REPOSITORY\": \"${GITHUB_REPOSITORY}\"}" From aa1b7c592af7ab4baca50f77a0442ff2e9513b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 16:56:51 +0100 Subject: [PATCH 30/41] Poc v1 --- docker/entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 125a4cc..1cc77b1 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -17,6 +17,9 @@ echo "GITHUB_ACTION_REF: ${GITHUB_ACTION_REF} \n" echo "GITHUB_TOKEN: ${GITHUB_TOKEN} \n" echo "GITHUB_REF: ${GITHUB_REF} \n" echo "GITHUB_REF_NAME: ${GITHUB_REF_NAME} \n" +echo "GITHUB_ACTION_REPOSITORY: ${GITHUB_ACTION_REPOSITORY} \n" +echo "GITHUB_ACTION_REF: ${GITHUB_ACTION_REF} \n" +echo "GITHUB_ACTION: ${GITHUB_ACTION} \n" gitHubConfig="{\"SHA\": \"${GITHUB_SHA}\", \"REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\", \"REPOSITORY\": \"${GITHUB_REPOSITORY}\"}" From 99cdf01fdb0439e5e1634ddf08c4dde5c9e8219b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 17:07:52 +0100 Subject: [PATCH 31/41] Poc v1 --- src/actions/CreateReportAction.py | 2 +- src/services/GitHubChecksService.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/actions/CreateReportAction.py b/src/actions/CreateReportAction.py index 8a30127..c6ee2f4 100644 --- a/src/actions/CreateReportAction.py +++ b/src/actions/CreateReportAction.py @@ -16,7 +16,7 @@ def __init__(self, app): async def exec(self): json_input = self._app.getArgumentByName('json_input') documentsCollection = self.fileJsonEncoderService.loadDocumentCollestionFromText(json_input) - await self.gitHubChecksService.CreateNewCheck() + await self.gitHubChecksService.createNewCheck() #pprint(documentsCollection) diff --git a/src/services/GitHubChecksService.py b/src/services/GitHubChecksService.py index 4fd854b..b808b90 100644 --- a/src/services/GitHubChecksService.py +++ b/src/services/GitHubChecksService.py @@ -20,11 +20,13 @@ def __init__(self, di = None, app = None): self._github = GitHub(ActionAuthStrategy()) self._gitHubConfig = self.injectConfigByName('github_config') - async def CreateNewCheck(self): + async def createNewCheck(self): + repositoryMetadata = self._getRepositoryName(self._gitHubConfig['REPOSITORY']) + resp = await self._github.rest.checks.async_create( head_sha = self._gitHubConfig['SHA'], - owner = self._gitHubConfig['REPOSITORY_OWNER'], - repo = self._gitHubConfig['REPOSITORY'], + owner = repositoryMetadata['owner'], + repo = repositoryMetadata['repository'], name = self._checkName, external_id = self._externalId, status = 'completed', @@ -34,4 +36,13 @@ async def CreateNewCheck(self): pprint(resp) pass + + def _getRepositoryName(ownerAndRepositorySetting): + splitData = ownerAndRepositorySetting.split('/') + + return { + "owner": splitData[0], + "repository": splitData[0], + "full": ownerAndRepositorySetting + } \ No newline at end of file From cefd198e79c666847a1183b7fcbc60a1729181ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 17:19:02 +0100 Subject: [PATCH 32/41] Poc v1 --- src/services/GitHubChecksService.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/GitHubChecksService.py b/src/services/GitHubChecksService.py index b808b90..35838f0 100644 --- a/src/services/GitHubChecksService.py +++ b/src/services/GitHubChecksService.py @@ -37,12 +37,12 @@ async def createNewCheck(self): pass - def _getRepositoryName(ownerAndRepositorySetting): + def _getRepositoryName(self, ownerAndRepositorySetting): splitData = ownerAndRepositorySetting.split('/') return { "owner": splitData[0], - "repository": splitData[0], + "repository": splitData[1], "full": ownerAndRepositorySetting } \ No newline at end of file From 460b3066df74fc05cc30ff6addecb93547ec68d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 17:23:22 +0100 Subject: [PATCH 33/41] Poc v1 --- src/services/GitHubChecksService.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/services/GitHubChecksService.py b/src/services/GitHubChecksService.py index 35838f0..7710ea2 100644 --- a/src/services/GitHubChecksService.py +++ b/src/services/GitHubChecksService.py @@ -33,8 +33,6 @@ async def createNewCheck(self): conclusion = 'skipped' ) - pprint(resp) - pass def _getRepositoryName(self, ownerAndRepositorySetting): From 0a4d40d36d51bcaaa3e31456550a2feb0ddfe06a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 17:29:09 +0100 Subject: [PATCH 34/41] Poc v1 --- src/services/GitHubChecksService.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/services/GitHubChecksService.py b/src/services/GitHubChecksService.py index 7710ea2..f1bfb6b 100644 --- a/src/services/GitHubChecksService.py +++ b/src/services/GitHubChecksService.py @@ -30,7 +30,12 @@ async def createNewCheck(self): name = self._checkName, external_id = self._externalId, status = 'completed', - conclusion = 'skipped' + conclusion = 'success' + output = { + "title": self._checkName, + "summary": "summary OK", + "text": "text OK" + } ) pass From 7cd09c75d1d37c4da4b70e3d85e5d9f0c9bc8994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 17:30:34 +0100 Subject: [PATCH 35/41] Poc v1 --- src/services/GitHubChecksService.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/GitHubChecksService.py b/src/services/GitHubChecksService.py index f1bfb6b..1bae4b7 100644 --- a/src/services/GitHubChecksService.py +++ b/src/services/GitHubChecksService.py @@ -30,7 +30,7 @@ async def createNewCheck(self): name = self._checkName, external_id = self._externalId, status = 'completed', - conclusion = 'success' + conclusion = 'success', output = { "title": self._checkName, "summary": "summary OK", From 9a6837bdd124b14b01191442d89c58846dd962bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 17:43:30 +0100 Subject: [PATCH 36/41] Poc v1 --- docker/entrypoint.sh | 6 +++++- src/myApp.py | 12 ++++++++++++ src/services/GitHubChecksService.py | 6 +++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 1cc77b1..39986e1 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -23,7 +23,11 @@ echo "GITHUB_ACTION: ${GITHUB_ACTION} \n" gitHubConfig="{\"SHA\": \"${GITHUB_SHA}\", \"REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\", \"REPOSITORY\": \"${GITHUB_REPOSITORY}\"}" -if html_output=$(python /action/src/main.py "$1" "$2" "${gitHubConfig}"); then +debug_output=$(python /action/src/main.py "$1" "$2" "${gitHubConfig}" "1") + + + +if html_output=$(python /action/src/main.py "$1" "$2" "${gitHubConfig}" "0"); then echo "html-output=$html_output" >> $GITHUB_OUTPUT else echo "Unable return HTML output" diff --git a/src/myApp.py b/src/myApp.py index 80f434f..1ad7d50 100644 --- a/src/myApp.py +++ b/src/myApp.py @@ -36,8 +36,20 @@ def prepareArgumentsCollection(argv): collection = argumentsCollection ) + argumentsCollection = MyApp.createArgumentsCollection( + arg = MyApp.createArgument('debug', MyApp.getBooleanValueArgument(argv[4])), + collection = argumentsCollection + ) + return argumentsCollection @staticmethod def readJsonConfig(rawText): return json.loads(rawText) + + @staticmethod + def getBooleanValueArgument(value): + if value == '0': + return False + else: + return True diff --git a/src/services/GitHubChecksService.py b/src/services/GitHubChecksService.py index 1bae4b7..8296b48 100644 --- a/src/services/GitHubChecksService.py +++ b/src/services/GitHubChecksService.py @@ -8,6 +8,7 @@ class GitHubChecksService(ServiceAbstract): _gitHubConfig = None _checkName = ".NET Format Results [beta]" _externalId = "action-dotnet-format-results" + _debug = False def __init__(self, di = None, app = None): """_summary_ @@ -19,6 +20,7 @@ def __init__(self, di = None, app = None): super().__init__(di, app) self._github = GitHub(ActionAuthStrategy()) self._gitHubConfig = self.injectConfigByName('github_config') + self._debug = self.injectConfigByName('debug') async def createNewCheck(self): repositoryMetadata = self._getRepositoryName(self._gitHubConfig['REPOSITORY']) @@ -28,7 +30,6 @@ async def createNewCheck(self): owner = repositoryMetadata['owner'], repo = repositoryMetadata['repository'], name = self._checkName, - external_id = self._externalId, status = 'completed', conclusion = 'success', output = { @@ -38,6 +39,9 @@ async def createNewCheck(self): } ) + if self._debug: + pprint(resp) + pass def _getRepositoryName(self, ownerAndRepositorySetting): From be41c13647bdd576960716926cc0d0fd6467361e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 17:46:16 +0100 Subject: [PATCH 37/41] Poc v1 --- docker/entrypoint.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 39986e1..a57c964 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -24,10 +24,11 @@ echo "GITHUB_ACTION: ${GITHUB_ACTION} \n" gitHubConfig="{\"SHA\": \"${GITHUB_SHA}\", \"REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\", \"REPOSITORY\": \"${GITHUB_REPOSITORY}\"}" debug_output=$(python /action/src/main.py "$1" "$2" "${gitHubConfig}" "1") - - +echo "Run With Debug:" +echo "$debug_output" if html_output=$(python /action/src/main.py "$1" "$2" "${gitHubConfig}" "0"); then + echo "Prepare output" echo "html-output=$html_output" >> $GITHUB_OUTPUT else echo "Unable return HTML output" From de75862884eb8f6c30ec4499f70215119b8de596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 18:13:39 +0100 Subject: [PATCH 38/41] Poc v1 --- docker/entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index a57c964..5fe27e0 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -20,6 +20,8 @@ echo "GITHUB_REF_NAME: ${GITHUB_REF_NAME} \n" echo "GITHUB_ACTION_REPOSITORY: ${GITHUB_ACTION_REPOSITORY} \n" echo "GITHUB_ACTION_REF: ${GITHUB_ACTION_REF} \n" echo "GITHUB_ACTION: ${GITHUB_ACTION} \n" +echo "GITHUB_WORKFLOW_SHA: ${GITHUB_WORKFLOW_SHA} \n" +echo "GITHUB_REF_TYPE: ${GITHUB_REF_TYPE} \n" gitHubConfig="{\"SHA\": \"${GITHUB_SHA}\", \"REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\", \"REPOSITORY\": \"${GITHUB_REPOSITORY}\"}" From 1ccc3db4fa66fccf9f490c7c1d810746491661b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 18:24:46 +0100 Subject: [PATCH 39/41] Poc v1 --- docker/entrypoint.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 5fe27e0..e18b356 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -25,9 +25,9 @@ echo "GITHUB_REF_TYPE: ${GITHUB_REF_TYPE} \n" gitHubConfig="{\"SHA\": \"${GITHUB_SHA}\", \"REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\", \"REPOSITORY\": \"${GITHUB_REPOSITORY}\"}" -debug_output=$(python /action/src/main.py "$1" "$2" "${gitHubConfig}" "1") -echo "Run With Debug:" -echo "$debug_output" +# debug_output=$(python /action/src/main.py "$1" "$2" "${gitHubConfig}" "1") +# echo "Run With Debug:" +# echo "$debug_output" if html_output=$(python /action/src/main.py "$1" "$2" "${gitHubConfig}" "0"); then echo "Prepare output" From 151c9ebe6613ce40501ead3086a6f4ccced6e137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 18:39:52 +0100 Subject: [PATCH 40/41] Poc v1 --- action.yaml | 2 ++ docker/entrypoint.sh | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/action.yaml b/action.yaml index 2474c99..a13c027 100644 --- a/action.yaml +++ b/action.yaml @@ -25,3 +25,5 @@ runs: args: - ${{ inputs.json-results }} - ${{ inputs.runner-workdir }} + - ${{ github.head_ref }} + - ${{ github.sha }} diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index e18b356..65abe46 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -3,11 +3,8 @@ echo "JSON Input $1" echo "Runner work directory $2" -if pip install githubkit; then - echo "[OK] pip install githubkit" -else - echo "[KO] pip install githubkit" -fi +echo "head_ref: $3" +echo "sha: $4" echo "GITHUB_SHA: ${GITHUB_SHA} \n" echo "GITHUB_REPOSITORY_OWNER: ${GITHUB_REPOSITORY_OWNER} \n" @@ -23,6 +20,13 @@ echo "GITHUB_ACTION: ${GITHUB_ACTION} \n" echo "GITHUB_WORKFLOW_SHA: ${GITHUB_WORKFLOW_SHA} \n" echo "GITHUB_REF_TYPE: ${GITHUB_REF_TYPE} \n" + +if pip install githubkit; then + echo "[OK] pip install githubkit" +else + echo "[KO] pip install githubkit" +fi + gitHubConfig="{\"SHA\": \"${GITHUB_SHA}\", \"REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\", \"REPOSITORY\": \"${GITHUB_REPOSITORY}\"}" # debug_output=$(python /action/src/main.py "$1" "$2" "${gitHubConfig}" "1") From 161fb7ce69f89b68a2ba6885846e76a2526c8ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Salamon?= Date: Sun, 4 Feb 2024 18:46:29 +0100 Subject: [PATCH 41/41] Poc v1 --- action.yaml | 2 -- docker/entrypoint.sh | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/action.yaml b/action.yaml index a13c027..2474c99 100644 --- a/action.yaml +++ b/action.yaml @@ -25,5 +25,3 @@ runs: args: - ${{ inputs.json-results }} - ${{ inputs.runner-workdir }} - - ${{ github.head_ref }} - - ${{ github.sha }} diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 65abe46..235128a 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -3,9 +3,6 @@ echo "JSON Input $1" echo "Runner work directory $2" -echo "head_ref: $3" -echo "sha: $4" - echo "GITHUB_SHA: ${GITHUB_SHA} \n" echo "GITHUB_REPOSITORY_OWNER: ${GITHUB_REPOSITORY_OWNER} \n" echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY} \n" @@ -27,7 +24,7 @@ else echo "[KO] pip install githubkit" fi -gitHubConfig="{\"SHA\": \"${GITHUB_SHA}\", \"REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\", \"REPOSITORY\": \"${GITHUB_REPOSITORY}\"}" +gitHubConfig="{\"SHA\": \"${GITHUB_WORKFLOW_SHA}\", \"REPOSITORY_OWNER\": \"${GITHUB_REPOSITORY_OWNER}\", \"REPOSITORY\": \"${GITHUB_REPOSITORY}\"}" # debug_output=$(python /action/src/main.py "$1" "$2" "${gitHubConfig}" "1") # echo "Run With Debug:"