Skip to content

Commit

Permalink
Merge pull request #6 from ne-sachirou/ci
Browse files Browse the repository at this point in the history
CI
  • Loading branch information
ne-sachirou authored Nov 7, 2023
2 parents 8984251 + 4f952b9 commit 0e29f4d
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: Pull Request の CI
"on":
pull_request:

jobs:
test-actions:
uses: ./.github/workflows/wf-test-actions.yml

test-go:
uses: ./.github/workflows/wf-test-go.yml
13 changes: 13 additions & 0 deletions .github/workflows/on-push-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: main branch に commit された時の CI
"on":
push:
branches:
- main

jobs:
test-actions:
uses: ./.github/workflows/wf-test-actions.yml

test-go:
uses: ./.github/workflows/wf-test-go.yml
12 changes: 12 additions & 0 deletions .github/workflows/wf-test-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: GitHub Actions の test
"on":
workflow_call:

jobs:
actionlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actionshub/yamllint@main
- uses: reviewdog/action-actionlint@v1
21 changes: 21 additions & 0 deletions .github/workflows/wf-test-go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Go の test
"on":
workflow_call:

jobs:
test-go:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- uses: golangci/golangci-lint-action@v3
- name: go generate の生成漏れが無いか確認
run: |
set -e
go generate ./...
git diff --exit-code
- name: go test
run: go test ./...
9 changes: 8 additions & 1 deletion cmd/example-grpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ func main() {
srv := grpc.NewServer(opts...)
reflection.Register(srv)

gracefulgrpc.ListenAndServe(ctx, ":4317", srv, graceful.GracefulShutdownTimeout(time.Second))
if err := gracefulgrpc.ListenAndServe(
ctx,
":4317",
srv,
graceful.GracefulShutdownTimeout(time.Second),
); err != nil {
panic(err)
}
}
16 changes: 14 additions & 2 deletions cmd/example-http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main

import (
"context"
"fmt"
"net/http"
"time"

Expand All @@ -14,7 +15,18 @@ func main() {
ctx := context.Background()

mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello, World!")) })
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if _, err := w.Write([]byte("Hello, World!")); err != nil {
fmt.Printf("failed to write response: %v\n", err)
}
})

gracefulhttp.ListenAndServe(ctx, ":8000", mux, graceful.GracefulShutdownTimeout(time.Second))
if err := gracefulhttp.ListenAndServe(
ctx,
":8000",
mux,
graceful.GracefulShutdownTimeout(time.Second),
); err != nil {
panic(err)
}
}

0 comments on commit 0e29f4d

Please sign in to comment.