Skip to content

Commit

Permalink
upgrade to v2 (#12)
Browse files Browse the repository at this point in the history
- upgrade go version
- improve rake tasks
- upgrade docker dependencies
- upgrade github actions
  • Loading branch information
vigo authored Aug 27, 2023
1 parent bfdc26e commit 8ce99c4
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 52 deletions.
76 changes: 37 additions & 39 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
name: build and test

on:
pull_request:
push:
branches:
- main
- ST-*
pull_request:
- main
tags-ignore:
- '**'

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.19
uses: actions/setup-go@v3
with:
go-version: 1.19
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Get dependencies
run: go mod download

- name: Run tests
run: go test -race -count=1 -coverprofile=coverage.txt -covermode=atomic ./...

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3

- name: Build app
id: build_go_app
run: |
go build -v .
echo ::set-output name=exit_code::$?
- name: Notify Slack on success
if: steps.build_go_app.outputs.exit_code == 0
id: slack_notification
uses: ravsamhq/notify-slack-action@v1
with:
status: ${{ job.status }}
notification_title: 'Build succeeded'
message_format: 'Statoo build succeeded. <{repo_url}|{repo}@{branch}> on <{commit_url}|{commit_sha}>'
footer: 'repo: <{repo_url}|{repo}>'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
id: go

- name: Run tests
run: go test -race -count=1 -coverprofile=coverage.txt -covermode=atomic ./...

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3

- name: Build app
id: build_go_app
run: |
go build -v .
echo ::set-output name=exit_code::$?
- name: Notify Slack on success
if: steps.build_go_app.outputs.exit_code == 0
id: slack_notification
uses: ravsamhq/notify-slack-action@v1
with:
status: ${{ job.status }}
notification_title: 'Build succeeded'
message_format: 'Statoo build succeeded. <{repo_url}|{repo}@{branch}> on <{commit_url}|{commit_sha}>'
footer: 'repo: <{repo_url}|{repo}>'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM golang:1.19-alpine AS builder
FROM golang:1.21-alpine AS builder
WORKDIR /go/src/github.com/vigo/statoo
COPY . .
RUN apk add --no-cache git=2.36.3-r0 \
ca-certificates=20220614-r0 \
RUN apk add --no-cache git=2.40.1-r0 \
ca-certificates=20230506-r0 \
&& CGO_ENABLED=0 \
GOOS=linux \
go build -ldflags="-X 'github.com/vigo/statoo/app/version.CommitHash=$(git rev-parse HEAD)'" -a -installsuffix cgo -o statoo .
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ you can make the same kind of request and get a kind-of same response since
You can install from the source;

```bash
go install github.com/vigo/statoo@latest
go install github.com/vigo/statoo/v2@latest
```

or, you can install from `brew`:
Expand Down Expand Up @@ -211,7 +211,9 @@ statoo -commithash
$ rake -T
rake default # show avaliable tasks (default task)
rake docker:build # Build image (locally)
rake docker:lint # lint Dockerfile
rake docker:run[param] # Run image (locally)
rake release[revision] # release new version major,minor,patch, default: patch
rake test:run[verbose] # run tests, generate coverage
rake test:show_coverage # show coverage after running tests
Expand All @@ -230,6 +232,14 @@ docker run vigo/statoo -h
docker run vigo/statoo -json -find "Meetup organization" https://vigo.io
```
to run docker locally via rake task:
```bash
rake docker:build
rake docker:run["-h"]
rake docker:run["https://ugur.ozyilmazel.com"]
```
---
## Contributor(s)
Expand Down
24 changes: 24 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,34 @@ end

# docker
# -----------------------------------------------------------------------------
DOCKER_IMAGE_TAG = 'statoo:latest'
namespace :docker do
desc "lint Dockerfile"
task :lint do
system "hadolint Dockerfile"
end

desc "Run image (locally)"
task :run, [:param] do |_, args|
cmd_args = [args.param] + args.extras
system %{
docker run #{DOCKER_IMAGE_TAG} #{cmd_args.join(' ')}
}
exit $?.exitstatus
end

desc "Build image (locally)"
task :build do
git_commit_hash = `git rev-parse HEAD`.chomp
goos =`go env GOOS`.chomp
goarch =`go env GOARCH`.chomp
build_commit_hash = "#{git_commit_hash}-#{goos}-#{goarch}"

system %{
docker build --build-arg="BUILD_INFORMATION=#{build_commit_hash}" \
-t #{DOCKER_IMAGE_TAG} .
}
exit $?.exitstatus
end
end
# -----------------------------------------------------------------------------
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"strings"
"time"

"github.com/vigo/statoo/app/flags"
"github.com/vigo/statoo/app/version"
"github.com/vigo/statoo/v2/app/flags"
"github.com/vigo/statoo/v2/app/version"
)

const (
Expand Down
6 changes: 3 additions & 3 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"strings"
"testing"

"github.com/vigo/statoo/app"
"github.com/vigo/statoo/app/flags"
"github.com/vigo/statoo/app/version"
"github.com/vigo/statoo/v2/app"
"github.com/vigo/statoo/v2/app/flags"
"github.com/vigo/statoo/v2/app/version"
)

type gzipResponseWriter struct {
Expand Down
2 changes: 1 addition & 1 deletion app/flags/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"flag"
"testing"

"github.com/vigo/statoo/app/flags"
"github.com/vigo/statoo/v2/app/flags"
)

func TestCustomRequestHeadersFlag(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/vigo/statoo
module github.com/vigo/statoo/v2

go 1.19
go 1.21
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/vigo/statoo/app"
"github.com/vigo/statoo/v2/app"
)

func main() {
Expand Down

0 comments on commit 8ce99c4

Please sign in to comment.