Repository navigation
start tune-up of the project #189
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
Open
aperezg
wants to merge
8
commits into
main
Choose a base branch
from
release/0.6.0
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a2a11ab
start tune-up of the project
aperezg 6e11f75
upgrade library versions
aperezg 6dc4282
Expand acceptance coverage for configuration, matching, proxying, and…
aperezg 3964a75
Simplify acceptance tests
aperezg 67918a7
Bug fix on yaml with schema files
aperezg 651f2c4
Add acceptance coverage for HTTPS, response delays, and graceful shut…
aperezg 4b99d36
Update .github/workflows/ci-test.yaml
aperezg e383b30
Merge pull request #190 from friendsofgo/chore/improve-releaser
aperezg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .git | ||
| bin | ||
| dist |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| name: Test & Build | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| validate: | ||
| uses: ./.github/workflows/validate.yml | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| name: Validate | ||
|
|
||
| on: | ||
| workflow_call: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| env: | ||
| GO_VERSION: '1.27' | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| - name: Set up Go | ||
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 | ||
| with: | ||
| go-version: ${{ env.GO_VERSION }} | ||
| - name: Run unit tests | ||
| run: go test -race ./... | ||
| - name: Run static checks | ||
| run: | | ||
| go vet ./... | ||
| go vet -tags=acceptance ./acceptance/... | ||
| - name: Run acceptance tests | ||
| run: make acceptance | ||
| - name: Check for vulnerabilities | ||
| run: | | ||
| go run golang.org/x/vuln/cmd/govulncheck@v1.9.0 ./... | ||
| go run golang.org/x/vuln/cmd/govulncheck@v1.9.0 -tags=acceptance ./... | ||
|
|
||
| package: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Set up Go | ||
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 | ||
| with: | ||
| go-version: ${{ env.GO_VERSION }} | ||
| - name: Install GoReleaser | ||
| uses: goreleaser/goreleaser-action@a4f02ab5355a589de60d917a659ce617ed19b3de # v7.3.0 | ||
| with: | ||
| version: v2.19.0 | ||
| install-only: true | ||
| - name: Validate release configuration and build snapshot | ||
| run: | | ||
| goreleaser check | ||
| goreleaser release --snapshot --clean | ||
| python3 scripts/check-release-artifacts.py | ||
| - name: Run acceptance tests against packaged Linux binary | ||
| run: | | ||
| mkdir -p bin | ||
| tar -xzf dist/*_linux_x86_64.tar.gz -C bin killgrave | ||
| ./bin/killgrave --version | ||
| cd acceptance | ||
| go test -count=1 -tags=acceptance ./... | ||
|
|
||
| docker: | ||
| strategy: | ||
| matrix: | ||
| arch: [amd64, arm64] | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| - name: Set up QEMU | ||
| uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0 | ||
| - name: Set up Buildx | ||
| uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 | ||
| - name: Build image without publishing | ||
| uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 | ||
| with: | ||
| context: . | ||
| platforms: linux/${{ matrix.arch }} | ||
| build-args: VERSION=validation | ||
| push: false | ||
| load: true | ||
| tags: killgrave:validation | ||
| - name: Check image version and fixture response | ||
| run: | | ||
| docker run --rm --platform linux/${{ matrix.arch }} killgrave:validation --version | grep -Fx 'Killgrave version: docker-validation' | ||
| mkdir -p "$RUNNER_TEMP/imposters" | ||
| cat > "$RUNNER_TEMP/imposters/smoke.imp.json" <<'JSON' | ||
| [{"request":{"method":"GET","endpoint":"/release-check"},"response":{"status":200,"body":"release-ok"}}] | ||
| JSON | ||
| container=$(docker run -d --platform linux/${{ matrix.arch }} -p 127.0.0.1:3000:3000 -v "$RUNNER_TEMP/imposters:/imposters:ro" killgrave:validation --host 0.0.0.0 --imposters /imposters) | ||
| trap 'docker logs "$container"; docker rm -f "$container"' EXIT | ||
| for attempt in $(seq 1 30); do | ||
| if curl --fail --silent http://127.0.0.1:3000/release-check > "$RUNNER_TEMP/response"; then break; fi | ||
| sleep 1 | ||
| done | ||
| test "$(cat "$RUNNER_TEMP/response")" = release-ok |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Repository Guidelines | ||
|
|
||
| ## Project Structure & Module Organization | ||
|
|
||
| Killgrave is a Go HTTP mock server. `cmd/killgrave/main.go` is the executable entry point; `internal/app/` wires the application together, and `internal/app/cmd/` defines the Cobra CLI. Configuration and file watching live in `internal/`; HTTP routing, imposters, proxying, and response handling live in `internal/server/http/`. | ||
|
|
||
| Unit tests sit beside source files as `*_test.go`. Fixtures live in `internal/test/testdata/` and `internal/server/http/test/testdata/`. Process-level acceptance tests and `.txtar` fixtures live in `acceptance/`. Consult `README.md` for configuration and imposter examples. | ||
|
|
||
| ## Build, Test, and Development Commands | ||
|
|
||
| Use Go 1.27, matching `go.mod` and CI. | ||
|
|
||
| - `make build`: produce `bin/killgrave` with branch and commit version metadata. | ||
| - `./bin/killgrave --imposters ./internal/server/http/test/testdata/imposters`: run locally with existing fixtures on localhost:3000. | ||
| - `go test ./...`: run the default unit test suite. | ||
| - `go test -v -vet=off -race ./...`: reproduce the CI unit test command with race detection. | ||
| - `make acceptance`: build the executable, then run acceptance tests with the `acceptance` build tag. | ||
| - `gofmt -w path/to/changed.go`: format changed Go files; use `go vet ./...` for static checks. | ||
|
|
||
| ## Coding Style & Naming Conventions | ||
|
|
||
| Follow existing Go conventions: use `gofmt` formatting and tab indentation, short lowercase package names, exported `CamelCase` identifiers, and unexported `camelCase` identifiers. Keep related behavior in the existing packages. Group standard-library, external, and repository imports consistently with nearby code. Name imposter fixtures with `.imp.json`, `.imp.yml`, or `.imp.yaml` extensions. | ||
|
|
||
| ## Testing Guidelines | ||
|
|
||
| Use Go's `testing` package with Testify assertions. Name tests `Test<Behavior>` and use descriptive table-driven subtests for input variations. Add regression coverage for behavior changes, including error cases. Each acceptance scenario is one `acceptance/tests/<scenario>.txtar` archive containing setup files, optional `scenario.json`, and named `http/<step>/req.http` and `res.http` entries. See `acceptance/README.md` for the format. Run unit and acceptance suites before submitting. No numeric coverage threshold is configured. | ||
|
|
||
| ## Commit & Pull Request Guidelines | ||
|
|
||
| Recent commits use concise action-oriented subjects, such as `Fix imposters search` and `Replace spf13/afero with io/fs`; merged subjects often include a PR number. Follow that style. | ||
|
|
||
| Follow `CONTRIBUTING.md`: ask to take an issue, confirm its milestone, and base work on the milestone branch. PR descriptions should explain the change, link the issue, and list validation performed. For bugs, include reproduction steps, expected versus actual behavior, and relevant configuration or imposters. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,21 @@ | ||
| FROM golang:1.21-alpine AS build | ||
| FROM --platform=$BUILDPLATFORM golang:1.27-alpine AS build | ||
|
|
||
| LABEL MAINTAINER = 'Friends of Go (it@friendsofgo.tech)' | ||
| LABEL maintainer="Friends of Go (it@friendsofgo.tech)" | ||
|
|
||
| ARG TARGETOS=linux | ||
| ARG TARGETARCH=amd64 | ||
|
|
||
| RUN apk add --update git | ||
| RUN apk add ca-certificates | ||
| RUN apk add --no-cache ca-certificates | ||
| WORKDIR /go/src/github.com/friendsofgo/killgrave | ||
| COPY go.mod go.sum ./ | ||
| RUN go mod download | ||
| COPY . . | ||
| RUN go mod tidy && TAG=$(git describe --tags --abbrev=0) \ | ||
| && LDFLAGS=$(echo "-s -w -X github.com/friendsofgo/killgrave/internal/app/cmd._version="docker-$TAG) \ | ||
| && CGO_ENABLED=0 GOOS="${TARGETOS}" GOARCH="${TARGETARCH}" go build -a -installsuffix cgo -o /go/bin/killgrave -ldflags "$LDFLAGS" cmd/killgrave/main.go | ||
| ARG TARGETOS=linux | ||
| ARG TARGETARCH=amd64 | ||
| ARG VERSION=dev | ||
| RUN CGO_ENABLED=0 GOOS="${TARGETOS}" GOARCH="${TARGETARCH}" go build \ | ||
| -buildvcs=false -trimpath \ | ||
| -ldflags "-s -w -X github.com/friendsofgo/killgrave/internal/app/cmd._version=docker-${VERSION}" \ | ||
| -o /go/bin/killgrave ./cmd/killgrave | ||
|
|
||
| # Building image with the binary | ||
| FROM scratch | ||
| COPY --from=build /go/bin/killgrave /go/bin/killgrave | ||
| COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
| ENTRYPOINT ["/go/bin/killgrave"] | ||
| ENTRYPOINT ["/go/bin/killgrave"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.