From 13d9fef38bbf658618e2a9c64db9c80faf1bbb8c Mon Sep 17 00:00:00 2001 From: 0xste Date: Fri, 17 Nov 2023 22:51:17 +0000 Subject: [PATCH] chore: added goreleaser workflow --- .github/workflows/go.yml | 25 -------------- .github/workflows/gorelease.yml | 55 ++++++++++++++++++++++++++++++ .github/workflows/test.yml | 59 +++++++++++++++++++++++++++++++++ .gitignore | 2 +- .goreleaser.yaml | 48 +++++++++++++++++++++++++++ 5 files changed, 163 insertions(+), 26 deletions(-) delete mode 100644 .github/workflows/go.yml create mode 100644 .github/workflows/gorelease.yml create mode 100644 .github/workflows/test.yml create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index a4536bb..0000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Go - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.21 - - - name: Build - run: go build -v ./... - - - name: Test - run: go test -v ./... diff --git a/.github/workflows/gorelease.yml b/.github/workflows/gorelease.yml new file mode 100644 index 0000000..47e5a23 --- /dev/null +++ b/.github/workflows/gorelease.yml @@ -0,0 +1,55 @@ +# Gorelease comments public API changes to pull request. +name: gorelease +on: + push: + branches: + - main + +# Cancel the workflow in progress in newer build is about to start. +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +env: + GO_VERSION: 1.21.x +jobs: + gorelease: + runs-on: ubuntu-latest + steps: + + - name: Install Go stable + if: env.GO_VERSION != 'tip' + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Gorelease cache + uses: actions/cache@v3 + with: + path: | + ~/go/bin/gorelease + key: ${{ runner.os }}-gorelease-generic + + - name: Gorelease + id: gorelease + run: | + test -e ~/go/bin/gorelease || go install golang.org/x/exp/cmd/gorelease@latest + OUTPUT=$(gorelease 2>&1 || exit 0) + echo "${OUTPUT}" + OUTPUT="${OUTPUT//$'\n'/%0A}" + echo "::set-output name=report::$OUTPUT" + + - name: Comment Report + continue-on-error: true + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: gorelease + message: | + ### Go API Changes + +
+            ${{ steps.gorelease.outputs.report }}
+            
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..75c4f53 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,59 @@ +name: test +on: + push: + branches: + - main +jobs: + test: + strategy: + matrix: + go-version: [ 1.16.x, 1.17.x, 1.19.x, 1.20.x, 1.21.x ] # Lowest supported and current stable versions. + runs-on: ubuntu-latest + steps: + + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Go cache + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-cache + + - name: Run gofmt + run: gofmt -d -e . 2>&1 | tee outfile && test -z "$(cat outfile)" && rm outfile + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + + - name: Run staticcheck + if: matrix.go-version == '1.21.x' + uses: dominikh/staticcheck-action@v1.3.0 + with: + version: "2023.1.3" + install-go: false + cache-key: ${{ matrix.go }} + + - name: Run go vet + run: | + go vet ./... + + - name: Run go test + run: | + go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... + + + - name: Report on code coverage + if: matrix.go-version == '1.21.x' + uses: codecov/codecov-action@v3 + with: + file: ./coverage.txt diff --git a/.gitignore b/.gitignore index cb80438..71bbfa8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .idea -gocuke.iml \ No newline at end of file +gocuke.iml diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..e813944 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,48 @@ +project_name: "gocuke" + +before: + hooks: + - go mod tidy + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of uname. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + +checksum: + name_template: 'checksums.txt' + +snapshot: + name_template: "{{ incpatch .Version }}-next" + +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + - '^MERGE' + - "{{ .Tag }}" + +release: + github: + owner: "regen-network" + name: "gocuke"