Skip to content

Commit

Permalink
Merge pull request #64 from steven-deboer/main
Browse files Browse the repository at this point in the history
Fixed linting and improved workflow (separate publish workflow for release)
  • Loading branch information
steven-deboer authored Jun 23, 2022
2 parents 2928a53 + 906dcc2 commit 109c31c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Prisma Cloud CLI Workflow
name: Prisma Cloud CLI Build Workflow

on:
push:
Expand Down Expand Up @@ -131,34 +131,3 @@ jobs:
PC_SECRET_KEY: ${{ secrets.PC_SECRET_KEY }}
run: |
pc --config environment alert list --unit hour --amount 1 > /dev/null
deploy:
needs: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.8"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
pip install pylint
pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
- name: Build package
run: python -m build

- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Upload Python Package

on:
release:
types: [created]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.8"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
pip install pylint
pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
- name: Install flake8
run: |
pip install flake8
- name: Analysing the code with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# execute overall flake8 scan
flake8 . --count --statistics
- name: Build package
run: python -m build

- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Prisma Cloud CLI

[![Code Quality Check](https://github.com/steven-deboer/prismacloud-cli/actions/workflows/quality.yml/badge.svg)](https://github.com/steven-deboer/prismacloud-cli/actions/workflows/quality.yml)
[![Code Quality Check](https://github.com/steven-deboer/prismacloud-cli/actions/workflows/build.yml/badge.svg)](https://github.com/steven-deboer/prismacloud-cli/actions/workflows/quality.yml)

The Prisma Cloud CLI is a command line interface for [Prisma Cloud](https://www.paloaltonetworks.com/prisma/cloud) by [Palo Alto Networks](https://www.paloaltonetworks.com/).

Expand Down
10 changes: 5 additions & 5 deletions prismacloud/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def cli_output(data, sort_values=False):
# normalize = True
try:
data_frame_normalized = pd.json_normalize(data)
except Exception as _exc: # pylint:disable=broad-except
except Exception as _exc: # pylint:disable=broad-except
logging.error("Error converting data via json_normalize(): %s", _exc)
sys.exit(1)

Expand All @@ -218,7 +218,7 @@ def cli_output(data, sort_values=False):
else:
try:
data_frame = pd.DataFrame(data)
except Exception as _exc: # pylint:disable=broad-except
except Exception as _exc: # pylint:disable=broad-except
logging.error("Error converting data via DataFrame(): %s", _exc)
sys.exit(1)

Expand All @@ -240,7 +240,7 @@ def cli_output(data, sort_values=False):
if params["query_filter"]:
try:
data_frame = data_frame.query(params["query_filter"])
except Exception as _exc: # pylint:disable=broad-except
except Exception as _exc: # pylint:disable=broad-except
logging.error("Error applying query filter: %s", _exc)
logging.error("You might be filtering on a dynamic column.")
logging.error("For example, if a certain tag does not exist, there is no way to filter on it.")
Expand All @@ -257,7 +257,7 @@ def cli_output(data, sort_values=False):
if "workloadsPurchased" in data_frame.columns:
data_frame["usage"] = data_frame["used"] / data_frame["workloadsPurchased"] * 100
# Extra columns are added, proceed.
except Exception as _exc: # pylint:disable=broad-except
except Exception as _exc: # pylint:disable=broad-except
logging.debug("Error calculating columns: %s", _exc)

# Change all nan values to empty string
Expand Down Expand Up @@ -285,7 +285,7 @@ def cli_output(data, sort_values=False):
# Convert all columns to string
data_frame = data_frame.applymap(str)
data_frame = data_frame.drop_duplicates()
except Exception as _exc: # pylint:disable=broad-except
except Exception as _exc: # pylint:disable=broad-except
logging.debug("Error dropping duplicates: %s", _exc)

# Drop all rows after max_rows
Expand Down

0 comments on commit 109c31c

Please sign in to comment.