Skip to content

Commit d3b50d1

Browse files
authored
Merge pull request #3 from oauth2-proxy/e2e-tests
Add tests and configure GitHub repository
2 parents 2fb06fc + 2e18d09 commit d3b50d1

24 files changed

+802
-6
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Default owner should be a core org reviewers unless overridden by later rules in this file
2+
* @oauth2-proxy/reviewers

.github/ISSUE_TEMPLATE.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!--- Provide a general summary of the issue in the Title above -->
2+
3+
## Expected Behavior
4+
5+
<!--- If you're describing a bug, tell us what should happen -->
6+
<!--- If you're suggesting a change/improvement, tell us how it should work -->
7+
8+
## Current Behavior
9+
10+
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
11+
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
12+
13+
## Possible Solution
14+
15+
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
16+
<!--- or ideas how to implement the addition or change -->
17+
18+
## Steps to Reproduce (for bugs)
19+
20+
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
21+
<!--- reproduce this bug. Include code to reproduce, if relevant -->
22+
23+
1. <!--- Step 1 --->
24+
2. <!--- Step 2 --->
25+
3. <!--- Step 3 --->
26+
4. <!--- Step 4 --->
27+
28+
## Context
29+
30+
<!--- How has this issue affected you? What are you trying to accomplish? -->
31+
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
32+
33+
## Your Environment
34+
35+
<!--- Include as many relevant details about the environment you experienced the bug in -->
36+
37+
- Version used:

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!--- Provide a general summary of your changes in the Title above -->
2+
3+
## Description
4+
5+
<!--- Describe your changes in detail -->
6+
7+
## Motivation and Context
8+
9+
<!--- Why is this change required? What problem does it solve? -->
10+
<!--- If it fixes an open issue, please link to the issue here. -->
11+
12+
## How Has This Been Tested?
13+
14+
<!--- Please describe in detail how you tested your changes. -->
15+
<!--- Include details of your testing environment, and the tests you ran to -->
16+
<!--- see how your change affects other areas of the code, etc. -->

.github/workflows/ci.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Continuous Integration
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
# - $default-branch
8+
pull_request:
9+
branches:
10+
- '**'
11+
# - $default-branch
12+
13+
jobs:
14+
build:
15+
env:
16+
COVER: true
17+
runs-on: ubuntu-20.04
18+
steps:
19+
20+
- name: Check out code
21+
uses: actions/checkout@v2
22+
23+
- name: Set up Go 1.17
24+
uses: actions/setup-go@v2
25+
with:
26+
go-version: 1.17.x
27+
id: go
28+
29+
- name: Get dependencies
30+
run: |
31+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.36.0
32+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
33+
chmod +x ./cc-test-reporter
34+
35+
- name: Lint
36+
run: |
37+
make lint
38+
39+
- name: Test
40+
env:
41+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
42+
run: |
43+
./.github/workflows/test.sh

.github/workflows/codeql.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: "Code scanning - action"
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
# The branches below must be a subset of the branches above
8+
branches: [main]
9+
schedule:
10+
- cron: '0 15 * * 2'
11+
12+
jobs:
13+
CodeQL-Build:
14+
15+
strategy:
16+
fail-fast: false
17+
18+
# CodeQL runs on ubuntu-latest and windows-latest
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v2
24+
with:
25+
# We must fetch at least the immediate parents so that if this is
26+
# a pull request then we can checkout the head.
27+
fetch-depth: 2
28+
29+
# If this run was triggered by a pull request event, then checkout
30+
# the head of the pull request instead of the merge commit.
31+
- run: git checkout HEAD^2
32+
if: ${{ github.event_name == 'pull_request' }}
33+
34+
# Initializes the CodeQL tools for scanning.
35+
- name: Initialize CodeQL
36+
uses: github/codeql-action/init@v1
37+
with:
38+
languages: go
39+
40+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
41+
# If this step fails, then you should remove it and run the build manually (see below)
42+
- name: Autobuild
43+
uses: github/codeql-action/autobuild@v1
44+
45+
# ℹ️ Command-line programs to run using the OS shell.
46+
# 📚 https://git.io/JvXDl
47+
48+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
49+
# and modify them (or add more) to build your code if your project
50+
# uses a compiled language
51+
52+
#- run: |
53+
# make bootstrap
54+
# make release
55+
56+
- name: Perform CodeQL Analysis
57+
uses: github/codeql-action/analyze@v1

.github/workflows/stale.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Mark stale issues and pull requests
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *"
6+
7+
jobs:
8+
stale:
9+
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/stale@v1
14+
with:
15+
repo-token: ${{ secrets.GITHUB_TOKEN }}
16+
stale-issue-message: 'This issue has been inactive for 60 days. If the issue is still relevant please comment to re-activate the issue. If no action is taken within 7 days, the issue will be marked closed.'
17+
stale-pr-message: 'This pull request has been inactive for 60 days. If the pull request is still relevant please comment to re-activate the pull request. If no action is taken within 7 days, the pull request will be marked closed.'

.github/workflows/test.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
# manually exiting from script, because after-build needs to run always
3+
set +e
4+
5+
tools=reference-gen
6+
test_reporter=$PWD/cc-test-reporter
7+
8+
for tool in ${tools}; do
9+
pushd ${tool}
10+
11+
if [ -z $CC_TEST_REPORTER_ID ]; then
12+
echo "1. CC_TEST_REPORTER_ID is unset, skipping"
13+
else
14+
echo "1. Running before-build"
15+
${test_reporter} before-build
16+
fi
17+
18+
echo "2. Running test"
19+
make test
20+
TEST_STATUS=$?
21+
22+
if [ -z $CC_TEST_REPORTER_ID ]; then
23+
echo "3. CC_TEST_REPORTER_ID is unset, skipping"
24+
else
25+
echo "3. Running after-build"
26+
${test_reporter} after-build --exit-code $TEST_STATUS -t gocov --prefix $(go list -m)
27+
fi
28+
29+
if [ "$TEST_STATUS" -ne 0 ]; then
30+
echo "Test failed, status code: $TEST_STATUS"
31+
exit $TEST_STATUS
32+
fi
33+
34+
popd
35+
done

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tools = reference-gen
2+
3+
%:
4+
@ for tool in ${tools}; do \
5+
make -C $${tool} $* ; \
6+
done

reference-gen/Makefile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
GO ?= go
2+
GOLANGCILINT ?= golangci-lint
3+
4+
GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
5+
GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
6+
MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
7+
MINIMUM_SUPPORTED_GO_MINOR_VERSION = 17
8+
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)
9+
10+
ifeq ($(COVER),true)
11+
TESTCOVER ?= -coverprofile c.out
12+
endif
13+
14+
.PHONY: lint
15+
lint: validate-go-version check-golangci-lint
16+
GO111MODULE=on $(GOLANGCILINT) run
17+
18+
.PHONY: test
19+
test: lint
20+
$(GO) test $(TESTCOVER) -v ./...
21+
22+
.PHONY: validate-go-version
23+
validate-go-version:
24+
@if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
25+
exit 0 ;\
26+
elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
27+
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
28+
exit 1; \
29+
elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \
30+
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
31+
exit 1; \
32+
fi
33+
34+
.PHONY: check-golangci-lint
35+
check-golangci-lint:
36+
@ if [ ! $$(which golangci-lint) ]; then \
37+
echo "Missing golangci-lint, please install from https://golangci-lint.run/usage/install/ before linting"; \
38+
exit 1; \
39+
fi

reference-gen/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Reference Gen
2+
3+
This is a utility for generating markdown references from Go structs.
4+
It is used to generate part of the documentation of the [OAuth2 Proxy](https://github.com/oauth2-proxy/oauth2-proxy) project.
5+
6+
For example, a struct as below:
7+
8+
```golang
9+
// MyStruct contains a collection of fields.
10+
type MyStruct struct {
11+
// Name is the name of the MyStruct.
12+
Name string `json:"name"`
13+
14+
// Data is a slice of raw byte data.
15+
Data []byte `json:"bytes"`
16+
}
17+
```
18+
19+
Would be turned into markdown such as:
20+
21+
```markdown
22+
### MyStruct
23+
24+
MyStruct contains a collection of fields.
25+
26+
| Field | Type | Description |
27+
| ----- | ---- | ----------- |
28+
| `name` | _string_ | Name is the name of the MyStruct. |
29+
| `data` | _[]byte_ | Data is a slice of raw byte data. |
30+
```
31+
32+
Where a struct contains another struct, the other structs will also be included
33+
in the api references. Check out the [test data](https://github.com/oauth2-proxy/tools/tree/master/reference-gen/pkg/generator/testdata)
34+
for full examples of more complex struct documentation generation.
35+
36+
## Running tests
37+
38+
Tests can be executed using the `test` target from the Makefile.
39+
40+
```bash
41+
make test
42+
```
43+
44+
The tests will also run the `lint` target which requires [golangci-lint](https://golangci-lint.run/usage/install/).
45+
You will be prompted to install it should it not already be installed.

0 commit comments

Comments
 (0)