diff --git a/.github/workflows/test-action.yaml b/.github/workflows/test-action.yaml index d61cd0b..4d2176e 100644 --- a/.github/workflows/test-action.yaml +++ b/.github/workflows/test-action.yaml @@ -19,4 +19,5 @@ jobs: gitHubAPIKey: ${{secrets.GITHUBAPIKEY}} # default token in GitHub Workflow loglevel: debug raisealarmremainingminutes: 100 + skipReposWithoutUsage: false diff --git a/.gitignore b/.gitignore index 34b3ba0..00f7817 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # Local .terraform directories # ################### **/.terraform/* - +.env # .tfstate files # ################### *.tfstate @@ -83,4 +83,4 @@ local.properties .cproject .buildpath nbproject/ -*.iml \ No newline at end of file +*.iml diff --git a/Dockerfile b/Dockerfile index f7dd0f5..98d2c0b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,12 @@ FROM python:3-slim AS builder -ADD . /app +ADD ./python/requirements.txt /app/python/requirements.txt WORKDIR /app # We are installing a dependency here directly into our app source dir RUN python -m pip install --upgrade pip RUN pip install --target=/app -r ./python/requirements.txt +ADD . /app # A distroless container image with Python and some basics like SSL certificates # https://github.com/GoogleContainerTools/distroless FROM gcr.io/distroless/python3-debian11 diff --git a/README.md b/README.md index ecbc115..0a7505c 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,7 @@ jobs: gitHubAPIKey: ${{secrets.GITHUBAPIKEY}} # default token in GitHub Workflow loglevel: error # not required, change to debug if misbehaving raisealarmremainingminutes: 100 # not required, defaults to 100 + skipReposWithoutUsage: false ``` ### Running Locally @@ -174,7 +175,8 @@ export INPUT_LOGLEVEL=debug|info|warning|error export INPUT_ORGANISATION="myorg" export INPUT_GITHUBAPIKEY="***" export INPUT_RAISEALARMREMAININGMINUTES="150" - +export INPUT_SKIPREPOSWITHOUTUSAGE="false" +export # from python directory you can run python main.py ``` @@ -191,7 +193,8 @@ export INPUT_LOGLEVEL=debug|info|warning|error export INPUT_ORGANISATION="myorg" export INPUT_GITHUBAPIKEY="***" export INPUT_RAISEALARMREMAININGMINUTES="150" -docker run -v $PWD:/app/results -e INPUT_RAISEALARMREMAININGMINUTES=${INPUT_RAISEALARMREMAININGMINUTES} -e INPUT_LOGLEVEL=${INPUT_LOGLEVEL} -e INPUT_ORGANISATION=${INPUT_ORGANISATION} -e INPUT_GITHUBAPIKEY=${INPUT_GITHUBAPIKEY} -it gha-billable-usage +export INPUT_SKIPREPOSWITHOUTUSAGE="false" +docker run -v $PWD:/app/results -e INPUT_RAISEALARMREMAININGMINUTES=${INPUT_RAISEALARMREMAININGMINUTES} -e INPUT_LOGLEVEL=${INPUT_LOGLEVEL} -e INPUT_ORGANISATION=${INPUT_ORGANISATION} -e INPUT_GITHUBAPIKEY=${INPUT_GITHUBAPIKEY} -e INPUT_SKIPREPOSWITHOUTUSAGE=${INPUT_SKIPREPOSWITHOUTUSAGE} -it gha-billable-usage ``` ## Common Errors diff --git a/action.yaml b/action.yaml index 9f23180..dd9b170 100644 --- a/action.yaml +++ b/action.yaml @@ -19,6 +19,10 @@ inputs: fail based on the default of 100 minutes remaining" required: false default: "100" + skipReposWithoutUsage: + description: "Don't print information about repos that have no workflow runs" + required: false + default: "False" outputs: warnings: diff --git a/python/main.py b/python/main.py index 746be5b..5f04f2d 100644 --- a/python/main.py +++ b/python/main.py @@ -43,14 +43,17 @@ def main(): billing_days_left = getremainingdaysinbillingperiod(org) repos_usage = [] total_costs = dict.fromkeys(['UBUNTU', 'MACOS', 'WINDOWS'], 0) + ignore_empty = True if os.environ['INPUT_SKIPREPOSWITHOUTUSAGE'] == 'true' else False # Collect the data from each repo for repo_name in repo_names: actions = [] repo_data = RepoData(repo_name, dict.fromkeys(['UBUNTU', 'MACOS', 'WINDOWS'], 0), actions) logger.info(f"*************** Repo Name {repo_data.name} ***************") getrepoworkflows(org, repo_data) - repos_usage.append(repo_data) logger.info(f"*************** Repo Usage Summary {repo_data.usage} ***************") + if not ignore_empty or repo_data.usage["UBUNTU"] > 0 or repo_data.usage["MACOS"] > 0 or repo_data.usage["WINDOWS"] > 0: + repos_usage.append(repo_data) + total_costs["UBUNTU"] += repo_data.usage["UBUNTU"] total_costs["MACOS"] += repo_data.usage["MACOS"] total_costs["WINDOWS"] += repo_data.usage["WINDOWS"]