From c8835bbd37be7d0eb741d8aa956c39e9ebb927c9 Mon Sep 17 00:00:00 2001 From: kianaza Date: Wed, 5 Jun 2024 00:44:53 +0330 Subject: [PATCH] feat: Update CI and release workflows --- .github/workflows/ci.yaml | 59 ++++++++++++++++--------------- .github/workflows/release.yaml | 31 +++++++++++++++++ .gitignore | 3 +- .goreleaser.yaml | 63 ++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/release.yaml create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 798920b..9ead338 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,31 +1,36 @@ --- - name: ci - on: - - push - jobs: - lint: - name: lint - runs-on: ubuntu-latest - steps: +name: ci +on: + push: + branches: + - main + pull_request: + branches: + - main +jobs: + lint: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: '1.22' + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.58 + test: + name: test + runs-on: ubuntu-latest + steps: - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 + - uses: actions/setup-go@v4 with: - go-version: '1.22' - - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + go-version: 1.22 + - run: go test -v ./... -covermode=atomic -coverprofile=coverage.out + - uses: codecov/codecov-action@v4.0.1 with: - version: v1.58 - test: - name: test - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 - with: - go-version: 1.22 - - run: go test -v ./... -covermode=atomic -coverprofile=coverage.out - - uses: codecov/codecov-action@v4.0.1 - with: - files: coverage.out - token: ${{ secrets.CODECOV_TOKEN }} - slug: snapp-incubator/nats-blackbox-exporter \ No newline at end of file + files: coverage.out + token: ${{ secrets.CODECOV_TOKEN }} + slug: snapp-incubator/nats-blackbox-exporter \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..0b3214f --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,31 @@ +name: Release + +on: + push: + tags: + - 'v*.*.*' + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.22' + + - name: Install dependencies + run: go mod download + + - name: Install Goreleaser + run: | + curl -sSfL https://raw.githubusercontent.com/goreleaser/goreleaser/main/scripts/install.sh | sh + + - name: Run Goreleaser + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: goreleaser release --rm-dist diff --git a/.gitignore b/.gitignore index 3f7c05a..6039a56 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,5 @@ # config config.yaml -.DS_Store \ No newline at end of file +.DS_Store +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..1189e9a --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,63 @@ +project_name: nats-blackbox-exporter + +release: + draft: true + github: + owner: snappcloud + name: nats-blackbox-exporter + + name_template: 'Release {{.Tag}}' + +builds: + - main: ./cmd/nats-blackbox-exporter + id: nats-blackbox-exporter + binary: nats-blackbox-exporter + ldflags: + - "-s -w -X github.com/nats-io/nats-blackbox-exporter/cmd.Version={{ .Tag }}" + env: + - GO111MODULE=on + - CGO_ENABLED=0 + goos: + - linux + - darwin + - windows + goarch: + - 386 + - amd64 + - arm + - arm64 + goarm: + - 6 + - 7 + ignore: + - goos: darwin + goarch: 386 + +archives: + - id: zipfiles + wrap_in_directory: true + name_template: '{{ .ProjectName }}-v{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm + }}v{{ .Arm }}{{ end }}' + format: zip + files: + - LICENSE + - README.md + - nats-blackbox-exporter* + +nfpms: + - formats: + - deb + file_name_template: '{{ .ProjectName }}-v{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm + }}v{{ .Arm }}{{ end }}' + bindir: /usr/local/bin + description: A Simplified Prometheus Monitoring Solution for NATS + vendor: nats.io + maintainer: Colin Sullivan + homepage: https://nats.io + license: Apache 2.0 + +snapshot: + name_template: SNAPSHOT-{{ .Commit }} + +checksum: + name_template: '{{ .ProjectName }}-v{{ .Version }}-checksums.txt'