From 19acf0e0c7fa7e41bff659d5742d1f165b38028c Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 15 Jun 2022 11:24:51 +0200 Subject: [PATCH] chore: add CI --- .github/workflows/ci.yml | 54 +++++++++++++++++++++++++++++++++ .github/workflows/go-cross.yml | 55 ++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 44 +++++++++++++++++++++++++++ Makefile | 2 +- 4 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/go-cross.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..aaa019b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,54 @@ +name: Main + +on: + push: + branches: + - master + pull_request: + +jobs: + + main: + name: Main Process + runs-on: ubuntu-latest + env: + GO_VERSION: 1.18 + GOLANGCI_LINT_VERSION: v1.46.2 + CGO_ENABLED: 0 + + steps: + + # https://github.com/marketplace/actions/setup-go-environment + - name: Set up Go ${{ env.GO_VERSION }} + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + + # https://github.com/marketplace/actions/checkout + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + # https://github.com/marketplace/actions/cache + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Check and get dependencies + run: | + go mod download + go mod tidy + git diff --exit-code go.mod + git diff --exit-code go.sum + + # https://golangci-lint.run/usage/install#other-ci + - name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }} + run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION} + + - name: Make + run: make diff --git a/.github/workflows/go-cross.yml b/.github/workflows/go-cross.yml new file mode 100644 index 0000000..6911b2a --- /dev/null +++ b/.github/workflows/go-cross.yml @@ -0,0 +1,55 @@ +name: Go Matrix + +on: + push: + branches: + - master + pull_request: + +jobs: + + cross: + name: Go + runs-on: ${{ matrix.os }} + env: + CGO_ENABLED: 0 + + strategy: + matrix: + go-version: [ 1.17, 1.x ] + os: [ubuntu-latest, macos-latest, windows-latest] + + steps: + # https://github.com/marketplace/actions/setup-go-environment + - name: Set up Go ${{ matrix.go-version }} + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + + # https://github.com/marketplace/actions/checkout + - name: Checkout code + uses: actions/checkout@v2 + + # https://github.com/marketplace/actions/cache + - name: Cache Go modules + uses: actions/cache@v2 + with: + # In order: + # * Module download cache + # * Build cache (Linux) + # * Build cache (Mac) + # * Build cache (Windows) + path: | + ~/go/pkg/mod + ~/.cache/go-build + ~/Library/Caches/go-build + %LocalAppData%\go-build + key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.go-version }}-go- + + - name: Test + run: go test -v -cover ./... + + - name: Build + run: go build -v -ldflags "-s -w" -trimpath diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c201bfc --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,44 @@ +name: "Release a tag" +on: + push: + tags: + - v* + +jobs: + release: + name: Release Process + runs-on: ubuntu-latest + env: + GO_VERSION: 1.18 + CGO_ENABLED: 0 + + steps: + + # https://github.com/marketplace/actions/setup-go-environment + - name: Set up Go ${{ env.GO_VERSION }} + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + + # https://github.com/marketplace/actions/checkout + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + # https://github.com/marketplace/actions/cache + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-release-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go-release- + + # https://goreleaser.com/ci/actions/ + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO }} diff --git a/Makefile b/Makefile index 039277d..97b7323 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ clean: rm -rf cover.out test: clean - go test -v -race -cover ./... + go test -v -cover ./... build: clean CGO_ENABLED=0 go build -trimpath -ldflags '-w -s'