Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add branding for publishing #12

Merged
merged 3 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ outputs:
runs:
using: "docker"
image: "Dockerfile"
branding:
icon: 'crosshair'
color: 'green'
42 changes: 31 additions & 11 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ runtime will be billed as 1 minute on Ubuntu, 10 minutes on MacOS, and 2 minutes
minutes and costs can soon build up. It turned out, this was the cause of our high usage. Top tip: don't build MacOS
machines in GitHub.

## What the Action Does

So I wrote this action to address the problems above, in the following way:

- give clear visibility of GitHub Action billing usage to all users
Expand Down Expand Up @@ -81,18 +83,36 @@ in the prettyprint formatted ASCII tables like this:
+-------------------------------+---------------------+--------+-------+---------+
```

## How Does it Work?

The action calls GitHub REST API endpoints to get the required information, and then prettyprint for formatting.

To get the number of repos, it
calls [GitHub Organisation API](https://docs.github.com/en/rest/orgs/orgs#get-an-organization). For information on each
repo, it
calls [GitHub List Organisational Repos API](https://docs.github.com/en/rest/repos/repos#list-organization-repositories)
. For repository workflows, it
calls [GitHub List Repository Workflow API](https://docs.github.com/en/rest/actions/workflows#list-repository-workflows)
. For workflow usage, it
calls [GitHub Get Workflow Usage API](https://docs.github.com/en/rest/actions/workflows#get-workflow-usage). Finally for
days left in the billing cycle , it
calls [GitHub Get shared storage billing for an organization API](https://docs.github.com/en/rest/billing#get-shared-storage-billing-for-an-organization)
.

## Prerequisites to Run as an GH Action

- an organisation or repo secret called `ORGANISATION` with the value of your organisation
- a secret called `GITHUBAPIKEY` with the value being a personal access token (PAT) with scope `read:org` - for public
repos and `repo:full` - for private repos
- a secret called `GITHUBAPIKEY` with the value being a personal access token (PAT) with scope `read:org` for reading
public repos and `repo:full` for reading private repos.

## Usage

### As a GitHub Action

Create a file called `gha-audit.yml` in your `workflows` directory, paste the following as the contents and you are good
to go
to
go. [GHA best practices](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-third-party-actions)
recommend using a commit SHA, rather than a version.

```
name: GHA Billable Audit
Expand All @@ -102,7 +122,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: GitHub Actions Billable Usage Audit
uses: fergusmacd/[email protected]
uses: fergusmacd/[email protected] # use a commit SHA
# pass user input as arguments
with:
organisation: ${{secrets.ORGANISATION}}
Expand All @@ -116,7 +136,7 @@ The docker file and python script can both be run locally in the following ways.

### Running with Python

For python, from the python directory
For python, from the python directory:

```shell
pip install -r requirements.txt
Expand All @@ -132,7 +152,7 @@ python main.py

### Running with Docker

For Docker, run from the root directory
For Docker, run from the root directory:

```shell
# from root directory
Expand All @@ -146,15 +166,15 @@ docker run -v $PWD:/app/results -e INPUT_LOGLEVEL=${INPUT_LOGLEVEL} -e INPUT_ORG

## Common Errors

When problems happen, the best thing to do is set the log level to `debug` like this locally
When problems happen, the best thing to do is set the log level to `debug` like this locally:

```shell
export LOGLEVEL="debug"
```

Or change the loglevel input in the GHA
Or change the loglevel input in the GHA.

The following one happens when running locally and the `INPUT_GITHUBAPIKEY` environment variable has not been exported
The following one happens when running locally and the `INPUT_GITHUBAPIKEY` environment variable has not been exported:

```shell
python3 main.py
Expand All @@ -171,7 +191,7 @@ KeyError: 'INPUT_GITHUBAPIKEY'

```

This error happens when the PAT has expired or does not have sufficient permissions
This error happens when the PAT has expired or does not have sufficient permissions:

```shell
python3 main.py
Expand Down Expand Up @@ -199,7 +219,7 @@ The following APIs are used:
- [GitHub Get Workflow Usage API](https://docs.github.com/en/rest/actions/workflows#get-workflow-usage) - for workflow
usage
- [GitHub Get shared storage billing for an organization API](https://docs.github.com/en/rest/billing#get-shared-storage-billing-for-an-organization)
- for days left in billing cycle
- for days left in billing cycle

There are plenty of tutorials on prettyprint, I used this one:

Expand Down