Skip to content

Commit

Permalink
cleanup workflows/actions; add check for valid json; add types
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelbaker-cisa committed Jul 31, 2024
1 parent 93dad44 commit 3119e64
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 62 deletions.
14 changes: 0 additions & 14 deletions .github/actions/setup-dependencies-macos/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,10 @@ inputs:
opa-version:
required: true
default: "0.60.0"
credentials:
required: true

runs:
using: "composite"
steps:
#- name: Setup credentials for service account
# id: create-json
# uses: jsdaniell/[email protected]
# with:
# name: "credentials.json"
# json: ${{ inputs.credentials }}
#
#- name: Setup credentials for service account
# shell: bash
# run: |
# ls -la

- name: Setup virtualenv
shell: bash
run: |
Expand Down
8 changes: 1 addition & 7 deletions .github/actions/setup-dependencies-windows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ inputs:
opa-version:
required: true
default: "0.60.0"
credentials:
required: true

runs:
using: "composite"
Expand All @@ -30,8 +28,4 @@ runs:
- name: Download OPA executable
shell: powershell
run: python download_opa.py -v ${{ inputs.opa-version }} -os ${{ inputs.operating-system }}

#- name: Setup credentials for service account
# shell: powershell
# run: Set-Content -Path credentials.json -Value ${{ inputs.credentials }}
run: python download_opa.py -v ${{ inputs.opa-version }} -os ${{ inputs.operating-system }}
9 changes: 1 addition & 8 deletions .github/workflows/run_smoke_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ on:
- "main"
- "*smoke*"

#env:
# GWS_SUBJECT_EMAIL: ${{ secrets.GWS_SUBJECT_EMAIL }}
# GWS_GITHUB_AUTOMATION_CREDS: ${{ secrets.GWS_GITHUB_AUTOMATION_CREDS }}

jobs:
smoke-test:
strategy:
Expand All @@ -46,15 +42,13 @@ jobs:
with:
operating-system: "windows"
opa-version: "0.60.0"
credentials: ${{ secrets.GWS_GITHUB_AUTOMATION_CREDS }}

- name: Setup Dependencies (macOS)
if: ${{ matrix.os == 'macos-latest' }}
uses: ./.github/actions/setup-dependencies-macos
with:
operating-system: "macos"
opa-version: "0.60.0"
credentials: ${{ secrets.GWS_GITHUB_AUTOMATION_CREDS }}

- name: Setup credentials for service account
id: create-json
Expand All @@ -64,5 +58,4 @@ jobs:
json: ${{ secrets.GWS_GITHUB_AUTOMATION_CREDS }}

- name: Execute ScubaGoggles and check for correct output
run: |
pytest -s ./Testing/Functional/SmokeTests/ --subjectemail="${{ secrets.GWS_SUBJECT_EMAIL }}"
run: pytest -s ./Testing/Functional/SmokeTests/ --subjectemail="${{ secrets.GWS_SUBJECT_EMAIL }}"
34 changes: 8 additions & 26 deletions Testing/Functional/SmokeTests/smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,19 @@
from smoke_test_utils import verify_all_outputs_exist, verify_output_type

class SmokeTest:
def test_venv_creation(self):
def test_scubagoggles_output(self, subjectemail):
try:
result = subprocess.run(["ls", ".venv"], shell=True, capture_output=True, text=True, check=True)
if "Scripts" in result.stdout:
assert True
except subprocess.CalledProcessError as e:
pytest.fail(f"An error occurred, {e}")

def test_scubagoggles(self, subjectemail):
try:
command = f"scubagoggles gws --subjectemail {subjectemail} --quiet"
command: str = f"scubagoggles gws --subjectemail {subjectemail} --quiet"
subprocess.run(command, shell=True)

prefix = "GWSBaselineConformance"
directories = [d for d in os.listdir() if os.path.isdir(d) and d.startswith(prefix)]
prefix: str = "GWSBaselineConformance"
directories: list[str] = [d for d in os.listdir() if os.path.isdir(d) and d.startswith(prefix)]
directories.sort(key=lambda d: os.path.getctime(d), reverse=True)

cwd = os.getcwd()
output_path = os.path.join(cwd, directories[0])
contents = verify_output_type(output_path, [])
# Access the latest output directory at the 0th index after sorting
cwd: str = os.getcwd()
output_path: str = os.path.join(cwd, directories[0])
contents: list[str] = verify_output_type(output_path, [])
verify_all_outputs_exist(contents)
except (OSError, ValueError, Exception) as e:
pytest.fail(f"An error occurred, {e}")

#def create_venv(env):
# result = subprocess.run(["python", "-m", "venv", env])
# if result.returncode == 0:
# raise RuntimeError(f"Failed to create virtual environment, {result.stderr}")
#
#def activate_venv(env):
# command = f"{env}\\Scripts\\activate"
# result = subprocess.run(command)
# if result.returncode == 0:
# raise RuntimeError(f"Failed to activate virtual environment, {result.stderr}")
19 changes: 12 additions & 7 deletions Testing/Functional/SmokeTests/smoke_test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import os
import json

required_contents = [
"BaselineReports.html",
Expand All @@ -21,25 +22,29 @@
"triangle-exclamation-solid.svg"
]

def verify_output_type(output_path, contents):
entries = os.listdir(output_path)

def verify_output_type(output_path: str, contents: list[str]) -> list[str]:
entries: list[str] = os.listdir(output_path)
for entry in entries:
contents.append(entry)

# Check if entry is a valid directory or file
child_path = os.path.join(output_path, entry)
child_path: str = os.path.join(output_path, entry)
if os.path.isdir(child_path):
assert True
verify_output_type(child_path, contents)
elif os.path.isfile(child_path):
# Check for valid json
if child_path.endswith(".json"):
try:
with open(child_path) as jsonfile:
json.load(jsonfile)
except ValueError as e:
pytest.fail(f"Invalid json, ${e}")
assert True
else:
raise OSError(f"Entry is not a directory or file (symlink, etc.)")

return contents

def verify_all_outputs_exist(contents):
def verify_all_outputs_exist(contents: list[str]):
for required_content in required_contents:
if required_content in contents:
assert True
Expand Down

0 comments on commit 3119e64

Please sign in to comment.