Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
533b79f
PoC version #3
salamonrafal Jan 28, 2024
22ffed5
PoC version #3
salamonrafal Jan 28, 2024
420749e
PoC version #3
salamonrafal Jan 28, 2024
dae94b2
PoC version #3
salamonrafal Jan 28, 2024
5d22fed
PoC version #3
salamonrafal Jan 28, 2024
07b6eb6
PoC version #3
salamonrafal Jan 28, 2024
ce171ea
PoC version #3
salamonrafal Jan 28, 2024
25652b9
PoC version #3
salamonrafal Jan 28, 2024
d7f7f10
PoC version #3
salamonrafal Jan 28, 2024
9742376
PoC version #3
salamonrafal Jan 28, 2024
126c93a
PoC version #3
salamonrafal Jan 28, 2024
e5e32d9
PoC version #3
salamonrafal Jan 28, 2024
7da8e6f
PoC version #3
salamonrafal Jan 28, 2024
9a460b2
PoC version #3
salamonrafal Feb 1, 2024
479944f
PoC version #3
salamonrafal Feb 1, 2024
1ccb17d
Added workdirectory parameter
salamonrafal Feb 3, 2024
975c97f
Poc v1
salamonrafal Feb 3, 2024
145417d
Poc v1
salamonrafal Feb 3, 2024
3e7ff08
Poc v1
salamonrafal Feb 3, 2024
f5f6b98
Poc v1
salamonrafal Feb 4, 2024
d912484
Poc v1
salamonrafal Feb 4, 2024
c356e9c
Poc v1
salamonrafal Feb 4, 2024
8d560bc
Poc v1
salamonrafal Feb 4, 2024
e46e444
Poc v1
salamonrafal Feb 4, 2024
f105405
Poc v1
salamonrafal Feb 4, 2024
f634523
Poc v1
salamonrafal Feb 4, 2024
261a04d
Poc v1
salamonrafal Feb 4, 2024
e486315
Poc v1
salamonrafal Feb 4, 2024
1629aab
Poc v1
salamonrafal Feb 4, 2024
aa1b7c5
Poc v1
salamonrafal Feb 4, 2024
99cdf01
Poc v1
salamonrafal Feb 4, 2024
cefd198
Poc v1
salamonrafal Feb 4, 2024
460b306
Poc v1
salamonrafal Feb 4, 2024
0a4d40d
Poc v1
salamonrafal Feb 4, 2024
7cd09c7
Poc v1
salamonrafal Feb 4, 2024
9a6837b
Poc v1
salamonrafal Feb 4, 2024
be41c13
Poc v1
salamonrafal Feb 4, 2024
de75862
Poc v1
salamonrafal Feb 4, 2024
1ccc3db
Poc v1
salamonrafal Feb 4, 2024
151c9eb
Poc v1
salamonrafal Feb 4, 2024
161fb7c
Poc v1
salamonrafal Feb 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/test-dotnet-format-results.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Test use workflow"
on: [push]
jobs:
defult_test_job:
runs-on: ubuntu-latest
name: "Test basic usage"
steps:
- name: Checkout
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''."}]}]'
- name: "Display Results"
run: echo "HTML output is ${{ steps.output-convert.outputs.html-output }} "
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.11-bullseye

COPY docker/entrypoint.sh /entrypoint.sh
WORKDIR /action

COPY . .

ENTRYPOINT ["/entrypoint.sh"]
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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''."}]}]'
```
27 changes: 27 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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: '[]'
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.

runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.json-results }}
- ${{ inputs.runner-workdir }}
39 changes: 39 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh -l

echo "JSON Input $1"
echo "Runner work directory $2"

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"
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"
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_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:"
# 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"
exit 1
fi
Empty file added src/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions src/actions/Action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Action():
_app = None

def __init__(self, app):
self._app = app
pass

def exec(self):
pass

def injectService(self, serviceName):
return self._app._di.getService(serviceName, self._app)

def injectConfigByName(self, configName):
return self._app.getArgumentByName(configName)
26 changes: 26 additions & 0 deletions src/actions/CreateReportAction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from actions.Action import Action
from pprint import pprint
from inspect import getmembers

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')

async def exec(self):
json_input = self._app.getArgumentByName('json_input')
documentsCollection = self.fileJsonEncoderService.loadDocumentCollestionFromText(json_input)
await self.gitHubChecksService.createNewCheck()

#pprint(documentsCollection)

htmlOutput = self.exampleService.createSampleText(json_input)

print(htmlOutput)
pass
1 change: 1 addition & 0 deletions src/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from actions.CreateReportAction import CreateReportAction
40 changes: 40 additions & 0 deletions src/app/Application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from models import Argument
from actions import *

class Application():
_appName = ''
_args = []
_di = None
_action_module = 'actions'
_service_module = 'services'

def __init__(self, appName = '', args = [], di = {}):
self._appName = appName
self._args = args
self._di = di
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 runAction(self, actionName):
module = __import__(self._action_module)
actionClass = getattr(module, actionName)
return actionClass(self).exec()
30 changes: 30 additions & 0 deletions src/app/DepedencyInjection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class DepedencyInjection():
_di_services = []
_service_module = 'services'

def __init__(self, containers):
self._di_services = containers
pass

def registryService(self, serviceName, app):
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, app)
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, app):
self.registryService(serviceName, app)
return self._di_services[0][serviceName]
2 changes: 2 additions & 0 deletions src/app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from app.Application import Application
from app.DepedencyInjection import DepedencyInjection
11 changes: 11 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sys
from myApp import MyApp;
from pprint import pprint
from inspect import getmembers
import asyncio

# from githubkit import GitHub, ActionAuthStrategy
# github = GitHub(ActionAuthStrategy())

containers = []
asyncio.run(MyApp.startUp(sys.argv, containers, 'CreateReportAction'))
12 changes: 12 additions & 0 deletions src/models/Argument.py
Original file line number Diff line number Diff line change
@@ -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

30 changes: 30 additions & 0 deletions src/models/DotnetFormatChange.py
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions src/models/DotnetFormatDocument.py
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions src/models/DotnetFormatDocumentId.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions src/models/DotnetFormatProjectId.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class DotnetFormatProjectId():
_id = ''

def __init__(self, id):
self._id = id
pass

def getId(self):
return self._id
5 changes: 5 additions & 0 deletions src/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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
Loading