From 4dc583761aa1f4fe7a9989cc024a4f786cf4dd44 Mon Sep 17 00:00:00 2001 From: miyamo2 <79917704+miyamo2@users.noreply.github.com> Date: Sat, 16 Mar 2024 10:19:51 +0900 Subject: [PATCH] [Chore] #7 Add CI/CD --- .github/workflows/ci.yaml | 60 ++++++++++++++++++++++++++++++++++ .github/workflows/release.yaml | 51 +++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..52eb711 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,60 @@ +name: ci + +on: + push: + branches: + - "feat/**" + - "refactor/**" + - "fix/**" + pull_request: + branches: + - "main" + workflow_call: + +permissions: write-all + +jobs: + ci: + runs-on: ubuntu-latest + strategy: + matrix: + goversion: [ ">=1.21.0"] + + steps: + - uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.goversion }} + cache: true + cache-dependency-path: go.sum + + - name: Setup mockgen + run: | + go install go.uber.org/mock/mockgen@latest + + - name: Go Generate + run: | + go mod tidy + go generate ./... + git diff --exit-code + + - name: Setup reviewdog + uses: reviewdog/action-setup@v1 + with: + reviewdog_version: latest + + - name: Setup staticcheck + run: | + go install honnef.co/go/tools/cmd/staticcheck@latest + + - name: staticcheck with reviewdog + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + staticcheck ./... | reviewdog -f=staticcheck -reporter=github-pr-check -level warning + + - name: Go Test + run: | + go test ./... -v diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..4689094 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,51 @@ +name: release + +on: + push: + tags: + - "v*" + +permissions: write-all + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: ">=1.21.0" + cache: true + cache-dependency-path: go.sum + + - name: Setup mockgen + run: | + go install go.uber.org/mock/mockgen@latest + + - name: Go Generate + run: | + go mod tidy + go generate ./... + git diff --exit-code + + - name: Go Test + run: | + TARGET=$(go list ./... | grep -v "mock") + go test $TARGET -v -coverpkg=$TARGET -coverprofile=coverage.out + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: coverage.out + fail_ci_if_error: false + verbose: true + + - name: Release + uses: softprops/action-gh-release@v1 + with: + name: ${{ github.ref_name }} + generate_release_notes: true