Skip to content

Commit 45549dc

Browse files
committed
feat: use pflag, remove docker, update ci (#83)
1 parent 358b2db commit 45549dc

File tree

12 files changed

+201
-306
lines changed

12 files changed

+201
-306
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
2222
restore-keys: ${{ runner.os }}-go-
2323
- name: Build service
24-
run: go build .
24+
run: make build
2525
lint:
2626
name: Lint
2727
runs-on: ubuntu-latest
@@ -39,6 +39,7 @@ jobs:
3939
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
4040
restore-keys: ${{ runner.os }}-go-
4141
- name: Lint
42-
run: |
43-
go get -u golang.org/x/lint/golint
44-
golint -set_exit_status
42+
uses: golangci/golangci-lint-action@v2
43+
with:
44+
args: --enable dupl,gofmt,revive
45+
skip-go-installation: true

.github/workflows/nightly-release.yaml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/release.yaml

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ on:
44
branches:
55
- main
66
jobs:
7-
build-tag-release:
8-
name: Build, tag, and release Docker image
7+
release-please:
8+
name: Build, tag, and publish assets
99
runs-on: ubuntu-latest
10+
outputs:
11+
release-created: ${{ steps.release.outputs.release_created }}
12+
upload-url: ${{ steps.release.outputs.upload_url }}
1013
steps:
1114
- name: Checkout repository
1215
uses: actions/checkout@v2
@@ -16,21 +19,51 @@ jobs:
1619
with:
1720
token: ${{ secrets.GITHUB_TOKEN }}
1821
release-type: simple
19-
changelog-path: CHANGELOG.md
2022
package-name: audit-org-keys
21-
- name: Login into GitHub Container Registry
22-
if: ${{ steps.release.outputs.release_created }}
23-
run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
24-
- name: Build Docker image
25-
if: ${{ steps.release.outputs.release_created }}
26-
run: |
27-
docker build \
28-
-t "ghcr.io/${GITHUB_REPOSITORY}:${TAG_NAME}" \
29-
-t "ghcr.io/${GITHUB_REPOSITORY}:latest" .
23+
build-publish:
24+
name: Build and publish assets
25+
runs-on: ubuntu-latest
26+
needs: release-please
27+
if: needs.release-please.outputs.release-created
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v2
31+
- name: Setup Go
32+
uses: actions/setup-go@v2
33+
with:
34+
go-version: '1.16'
35+
- name: Setup build cache
36+
uses: actions/cache@v2
37+
with:
38+
path: ~/go/pkg/mod
39+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
40+
restore-keys: ${{ runner.os }}-go-
41+
- name: Build release assets
42+
run: make dist
43+
- name: Upload Windows asset
44+
uses: actions/upload-release-asset@v1
3045
env:
31-
TAG_NAME: ${{ steps.release.outputs.tag_name }}
32-
- name: Release Docker image
33-
if: ${{ steps.release.outputs.release_created }}
34-
run: |
35-
docker push "ghcr.io/${GITHUB_REPOSITORY}:${TAG_NAME}"
36-
docker push "ghcr.io/${GITHUB_REPOSITORY}:latest"
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
with:
48+
upload_url: ${{ needs.release-please.outputs.upload-url }}
49+
asset_path: ./audit-org-keys-windows-amd64.exe
50+
asset_name: audit-org-keys-windows-amd64.exe
51+
asset_content_type: application/octet-stream
52+
- name: Upload Linux asset
53+
uses: actions/upload-release-asset@v1
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
with:
57+
upload_url: ${{ needs.release-please.outputs.upload-url }}
58+
asset_path: ./audit-org-keys-linux-amd64
59+
asset_name: audit-org-keys-linux-amd64
60+
asset_content_type: application/octet-stream
61+
- name: Upload macOS asset
62+
uses: actions/upload-release-asset@v1
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
with:
66+
upload_url: ${{ needs.release-please.outputs.upload-url }}
67+
asset_path: ./audit-org-keys-darwin-amd64
68+
asset_name: audit-org-keys-darwin-amd64
69+
asset_content_type: application/octet-stream

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
.idea/
2-
audit-org-keys
2+
bin/

Dockerfile

Lines changed: 0 additions & 26 deletions
This file was deleted.

Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
PROJECT_NAME=audit-org-keys
2+
3+
GOCMD=$(shell pwd)/cmd/$(subst -,_,$(PROJECT_NAME))
4+
GOBIN=$(shell pwd)/bin/$(subst -,_,$(PROJECT_NAME))
5+
GOREPORTS=$(shell pwd)/bin
6+
GO_MAJOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
7+
GO_MINOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
8+
MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
9+
MINIMUM_SUPPORTED_GO_MINOR_VERSION = 16
10+
GO_VERSION_VALIDATION_ERR_MSG = Golang version is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION)
11+
.SILENT:
12+
13+
.DEFAULT:
14+
build: validate-go-version
15+
go build -o $(GOBIN) $(GOCMD)
16+
17+
dist: validate-go-version
18+
GOOS=darwin GOARCH=amd64 go build -o $(PROJECT_NAME)-darwin-amd64 $(GOCMD)
19+
GOOS=linux GOARCH=amd64 go build -o $(PROJECT_NAME)-linux-amd64 $(GOCMD)
20+
GOOS=windows GOARCH=amd64 go build -o $(PROJECT_NAME)-windows-amd64.exe $(GOCMD)
21+
22+
fmt: validate-go-version
23+
gofmt -s -w .
24+
25+
lint: validate-go-version
26+
golangci-lint run --enable dupl,gofmt,revive
27+
28+
test: validate-go-version
29+
mkdir -p $(GOREPORTS)
30+
go test -v ./... -coverprofile=$(GOREPORTS)/coverage.out -json > $(GOREPORTS)/report.json
31+
32+
validate-go-version:
33+
if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
34+
exit 0 ;\
35+
elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
36+
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
37+
exit 1; \
38+
elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \
39+
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
40+
exit 1; \
41+
fi

README.md

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,33 @@ The point of this project is to help demonstrate that users of GitHub could pote
44

55
Programs like `ssh2john` from **John the Ripper** can best demonstrate how fast an SSH private key can be solved from a _not so_ complex algorithm with low key lengths (think RSA < 1024 bits).
66

7-
## Getting started
7+
## Installation
88

9-
### Releases
9+
`go get -u github.com/jef/audit-org-keys`
1010

11-
| Tag | Description |
12-
|:---:|---|
13-
| `latest` | Built against tagged releases; stable
14-
| `nightly` | Built against HEAD; generally considered stable, but could have problems |
15-
16-
```
17-
GITHUB_ORGANIZATION=actions
18-
GITHUB_PAT=mysecrettoken
19-
20-
docker run --rm -it \
21-
--env "GITHUB_ORGANIZATION=$GITHUB_ORGANIZATION" \
22-
--env "GITHUB_PAT=$GITHUB_PAT" \
23-
"docker.pkg.github.com/jef/audit-org-keys/audit-org-keys:<tag>"
24-
```
25-
26-
> :point_right: View [Available arguments](#available-arguments) and [Available environment variables](#available-environment-variables) below if you'd like to customize input and output
27-
28-
### Development
29-
30-
#### Requirements
11+
Also available under [GitHub Releases](https://github.com/jef/audit-org-keys/releases) as an executable.
3112

32-
- Go 1.14+ or Docker
13+
## Usage
3314

34-
#### Running
15+
It is required that you use a GitHub Personal Access Token (PAT). You can generate one [here](https://github.com/settings/tokens/new). The required scopes are `['read:org']`. Set your PAT to environment variable `GITHUB_TOKEN`. If `GITHUB_TOKEN` isn't set, then you may not get the results you expect.
3516

36-
```sh
37-
GITHUB_ORGANIZATION=actions
38-
GITHUB_PAT=mysecrettoken
39-
40-
# Golang
41-
go build
42-
./audit-org-keys
43-
44-
# show users with multiple keys
45-
./audit-org-keys -show-users=multiple
46-
47-
# Docker
48-
docker build -t audit-org-keys:localhost .
49-
50-
docker run --rm -it \
51-
--env "GITHUB_ORGANIZATION=$GITHUB_ORGANIZATION" \
52-
--env "GITHUB_PAT=$GITHUB_PAT" \
53-
audit-org-keys:localhost
54-
55-
# show users without keys
56-
docker run --rm -it \
57-
--env "GITHUB_ORGANIZATION=$GITHUB_ORGANIZATION" \
58-
--env "GITHUB_PAT=$GITHUB_PAT" \
59-
audit-org-keys:localhost -show-users=without
17+
```shell
18+
Usage of audit_org_keys:
19+
-o, --organization string [required] GitHub organization provided to inspect
20+
-s, --show-users all display users with filter (all, `with`, `without`, `multiple`)
6021
```
6122

62-
##### Available arguments
23+
### Examples
6324

64-
- `-show-users=<filter>`: display users with filter (`all`, `with`, `without`, `multiple`)
25+
- `audit-org-keys --organization="actions"`
26+
- `audit-org-keys --organization="actions" --show-users="all"`
6527

66-
##### Available environment variables
28+
## Releases
6729

68-
- `GITHUB_ORGANIZATION`*: The organization under audit
69-
- `GITHUB_PAT`*: GitHub Personal Access Token
70-
- [Create a PAT](https://github.com/settings/tokens) with `read:org` scope
71-
- Some organizations have SSO; if yours does, then you also need to enable it
72-
- `LOG_LEVEL`: Sets zap log level
73-
74-
> :point_right: Required denoted by `*`
30+
| Tag | Description |
31+
|:---:|---|
32+
| `latest` | Built against tagged releases; stable
33+
| `nightly` | Built against HEAD; generally considered stable, but could have problems |
7534

7635
### Acknowledgments
7736

0 commit comments

Comments
 (0)