Skip to content

Commit

Permalink
Merge pull request #19 from cakeinpanic/main
Browse files Browse the repository at this point in the history
feature: add option to not output repos which had 0 minutes used
  • Loading branch information
mononokehime authored May 4, 2023
2 parents f679c97 + 0e58e03 commit e69769d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ jobs:
gitHubAPIKey: ${{secrets.GITHUBAPIKEY}} # default token in GitHub Workflow
loglevel: debug
raisealarmremainingminutes: 100
skipReposWithoutUsage: false

4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Local .terraform directories #
###################
**/.terraform/*

.env
# .tfstate files #
###################
*.tfstate
Expand Down Expand Up @@ -83,4 +83,4 @@ local.properties
.cproject
.buildpath
nbproject/
*.iml
*.iml
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit e69769d

Please sign in to comment.