Skip to content

Commit

Permalink
Add GHA
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Feb 27, 2023
1 parent 30aad0b commit d5088a7
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 6 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: build

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 1
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
- name: Make all
run: make all
26 changes: 26 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: publish

on:
push:
tags:
- '*'

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 1
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
- name: Make all
run: make all
- name: Upload release binaries
uses: alexellis/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
with:
asset_paths: '["./bin/gha-usage*"]'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin/
/actions-usage
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
SOURCE_DIRS = main.go
export GO111MODULE=on
export LDFLAGS="-s -w"

.PHONY: all
all: gofmt test build dist hash

.PHONY: build
build:
go build

.PHONY: gofmt
gofmt:
@test -z $(shell gofmt -l -s $(SOURCE_DIRS) ./ | tee /dev/stderr) || (echo "[WARN] Fix formatting issues with 'make gofmt'" && exit 1)

.PHONY: test
test:
CGO_ENABLED=0 go test $(shell go list ./... | grep -v /vendor/|xargs echo) -cover

.PHONY: e2e
e2e:
CGO_ENABLED=0 go test github.com/self-actuated/actions-usage/pkg/get -cover --tags e2e -v

.PHONY: dist
dist:
mkdir -p bin
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags $(LDFLAGS) -o bin/actions-usage
CGO_ENABLED=0 GOOS=darwin go build -ldflags $(LDFLAGS) -o bin/actions-usage-darwin
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -a -ldflags $(LDFLAGS) -installsuffix cgo -o bin/actions-usage-darwin-arm64
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -ldflags $(LDFLAGS) -o bin/actions-usage-armhf
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags $(LDFLAGS) -o bin/actions-usage-arm64
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags $(LDFLAGS) -o bin/actions-usage.exe
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
## gha-usage
## actions-usage

Find your GitHub Actions usage across a given organisation.

Includes total runtime of all workflow runs and workflow jobs, including where the jobs were run within inclusive, free, billed minutes, or on self-hosted runners.

## Usage

Create a Fine-grained personal access token with access to the given organisation, a regular personal access token doesn't have privileges to list repositories within an organisation.
Or create a [Classic Token](https://github.com/settings/tokens) with: repo and admin:org and save it to ~/pat.txt. Create a short lived duration for good measure.

```bash
git clone https://github.com/actuated/actions-usage --depth=1
cd actions-usage

go run . --org actuated-samples --token $(cat ~/pat.txt)
```

Expand All @@ -21,3 +24,7 @@ Total workflow runs: 245
Total workflow jobs: 255
Total usage: 9h10m17s
```

## Author

This tool was created as part of [actuated.dev](https://actuated.dev) by OpenFaaS Ltd.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/alexellis/gha-usage
module github.com/self-actuated/actions-stats

go 1.19

Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ func main() {
}
}

fmt.Printf("Total repos: %d", len(allRepos))
fmt.Printf("Total private repos: %d", totalPrivate)
fmt.Printf("Total public repos: %d", totalPublic)
fmt.Printf("Total repos: %d\n", len(allRepos))
fmt.Printf("Total private repos: %d\n", totalPrivate)
fmt.Printf("Total public repos: %d\n", totalPublic)
fmt.Println()
fmt.Printf("Total workflow runs: %d\n", totalRuns)
fmt.Printf("Total workflow jobs: %d\n", totalJobs)
Expand Down

0 comments on commit d5088a7

Please sign in to comment.