Skip to content

Commit

Permalink
mesh-1684: pipelines and ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-mercer committed Sep 23, 2023
1 parent 6ca4f75 commit a7bacbf
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 110 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: create-release
on:
push:
tags:
- "v*"

jobs:

coverage:
runs-on: ubuntu-latest
if: github.repository == 'NHSDigital/terraform-aws-mesh-client' && !contains(github.event.head_commit.message, 'tag release version:')
steps:
- name: checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: setup python
uses: actions/setup-python@v4
with:
python-version-file: "pyproject.toml"

- name: setup poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.5.1

- name: get tag
run: |
VERSION="$(git describe --tags)
echo "VERSION=${VERSION}" >> $GITHUB_ENV
- name: create release
id: create_release
uses: actions/create-release@v1
continue-on-error: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }}
8 changes: 4 additions & 4 deletions .github/workflows/merge-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ jobs:

coverage:
runs-on: ubuntu-latest
if: github.repository == 'NHSDigital/mesh-client-aws-serverless' && !contains(github.event.head_commit.message, 'tag release version:')
if: github.repository == 'NHSDigital/terraform-aws-mesh-client' && !contains(github.event.head_commit.message, 'tag release version:')
steps:
- name: checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: setup python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: "3.8"
python-version-file: "pyproject.toml"

- name: setup poetry
uses: abatilo/actions-poetry@v2
Expand All @@ -30,7 +30,7 @@ jobs:
with:
path: |
.venv
key: ${{ runner.os }}-poetry-v2-py3.8-${{ hashFiles('./poetry.lock') }}
key: ${{ runner.os }}-poetry-v2-py3.9-${{ hashFiles('./poetry.lock') }}

- name: git reset
run: git reset --hard
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

coverage:
runs-on: ubuntu-latest
if: github.repository == 'NHSDigital/mesh-client-aws-serverless'
if: github.repository == 'NHSDigital/terraform-aws-mesh-client'
steps:
- name: checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -40,9 +40,9 @@ jobs:
git merge --ff-only "${{ github.event.pull_request.head.sha }}"
- name: setup python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: "3.8"
python-version-file: "pyproject.toml"

- name: setup poetry
uses: abatilo/actions-poetry@v2
Expand All @@ -58,7 +58,7 @@ jobs:
with:
path: |
.venv
key: ${{ runner.os }}-poetry-v2-py3.8-${{ hashFiles('./poetry.lock') }}
key: ${{ runner.os }}-poetry-v2-py3.9-${{ hashFiles('./poetry.lock') }}

- name: git reset
run: git reset --hard
Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:

lint:
runs-on: ubuntu-latest
if: github.repository == 'NHSDigital/mesh-client-aws-serverless'
if: github.repository == 'NHSDigital/terraform-aws-mesh-client'
steps:
- name: checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -165,9 +165,9 @@ jobs:
./tfsec terraform --config-file tfsec.yml
- name: setup python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: "3.8"
python-version-file: "pyproject.toml"

- name: setup poetry
uses: abatilo/actions-poetry@v2
Expand All @@ -179,7 +179,7 @@ jobs:
with:
path: |
.venv
key: ${{ runner.os }}-poetry-v2-py3.8-${{ hashFiles('./poetry.lock') }}
key: ${{ runner.os }}-poetry-v2-py3.9-${{ hashFiles('./poetry.lock') }}

- name: git reset
run: git reset --hard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ def _handle_report_message(self):
"message_id": self.message_id,
"s3_bucket": self.s3_bucket,
"s3_key": self.s3_key,
}
},
)
buffer = json.dumps(dict(self.http_response.headers)).encode("utf-8")
self.http_headers_bytes_read = len(buffer)
self._upload_to_s3(buffer, s3_key=self.s3_key)
self.mailbox.acknowledge_message(self.message_id)
self._update_response_and_mailbox_cleanup(complete=True)
self.log_object.write_log(
"MESHFETCH0012", None, {"message_id": self.message_id}
"MESHFETCH0012", None, {"message_id": self.message_id}
)

def _get_filename(self):
Expand Down
111 changes: 27 additions & 84 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@ importlib-metadata = "6.6.0"
requests = "2.28.2"
urllib3 = "1.26.15"
spine-aws-common = "^0.2.13"
ruff = "^0.0.291"



[tool.poetry.group.dev.dependencies]
# ci / testing dependencies
boto3 = "1.26.54"
black = "^22.12.0"
isort = "^5.12.0"
mypy = "^1.4.0"
coverage = "^7.2.7"
pytest = "^7.3.1"
pytest-asyncio = "^0.21.0"
flake8 = "^6.0.0"
flake8-pyproject = "^1.2.3"

requests-mock = "^1.11.0"
moto = {extras = ["s3", "ssm", "stepfunctions", "secretsmanager"], version = "4.1.0"}
Expand Down
28 changes: 22 additions & 6 deletions scripts/sonar_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def _get_test_suites(test_src: str) -> List[dom.Element]:
raise NotImplementedError(src_root.nodeName)


def _add_test_detail_if_present(case_src: dom.Element, case_out: dom.Element, dom_out: dom.Document):
def _add_test_detail_if_present(
case_src: dom.Element, case_out: dom.Element, dom_out: dom.Document
):
failures = [node for node in case_src.childNodes if node.nodeName == "failure"]
skipped = [node for node in case_src.childNodes if node.nodeName == "skipped"]
errors = [node for node in case_src.childNodes if node.nodeName == "error"]
Expand All @@ -37,7 +39,9 @@ def _add_test_detail_if_present(case_src: dom.Element, case_out: dom.Element, do
message = f"{detail_type}{message}"
detail_out = dom_out.createElement(detail_node.nodeName)
detail_out.setAttribute("message", message)
detail_text = "".join([node.nodeValue for node in detail_node.childNodes if node.nodeValue])
detail_text = "".join(
[node.nodeValue for node in detail_node.childNodes if node.nodeValue]
)
if detail_text:
cdata = dom.CDATASection()
cdata.nodeValue = detail_text
Expand All @@ -52,8 +56,16 @@ def _translate_test_case(
test_name = case_src.getAttribute("name")
duration = round(float(case_src.getAttribute("time") or "0") * 1000, 0)
classname_dotsplit = classname.split(".")
test_file = f"features/{classname_dotsplit[0]}.py" if is_feature_file else f"{'/'.join(classname_dotsplit)}.py"
test_name = f"{'.'.join(classname_dotsplit[1:])} - {test_name}" if is_feature_file else test_name
test_file = (
f"features/{classname_dotsplit[0]}.py"
if is_feature_file
else f"{'/'.join(classname_dotsplit)}.py"
)
test_name = (
f"{'.'.join(classname_dotsplit[1:])} - {test_name}"
if is_feature_file
else test_name
)
case_out = dom_out.createElement("testCase")
case_out.setAttribute("name", test_name)
case_out.setAttribute("duration", str(duration))
Expand All @@ -62,14 +74,18 @@ def _translate_test_case(
return test_file, case_out


def _get_tests_from_file(test_src: str, dom_out: dom.Document) -> Dict[str, List[dom.Element]]:
def _get_tests_from_file(
test_src: str, dom_out: dom.Document
) -> Dict[str, List[dom.Element]]:

is_feature_file = os.path.basename(test_src).startswith("TESTS-")
test_suites = _get_test_suites(test_src)

test_cases = []
for suite in test_suites:
test_cases.extend([node for node in suite.childNodes if node.nodeName == "testcase"])
test_cases.extend(
[node for node in suite.childNodes if node.nodeName == "testcase"]
)

print(test_src, "suites", len(test_suites), "cases", len(test_cases))

Expand Down
Loading

0 comments on commit a7bacbf

Please sign in to comment.