From 1cc1fcd106f6e9bcf8d1688347118a80b57f6004 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 16 Dec 2023 01:20:01 +0000 Subject: [PATCH] ci(release): setup CI workflows and release please (#1) --- .github/.release-please-manifest.json | 3 ++ .github/release-please-config.json | 14 ++++++++ .github/workflows/ci.yml | 47 +++++++++++++++++++++++++ .goreleaser.yml | 49 +++++++++++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 .github/.release-please-manifest.json create mode 100644 .github/release-please-config.json create mode 100644 .github/workflows/ci.yml create mode 100644 .goreleaser.yml diff --git a/.github/.release-please-manifest.json b/.github/.release-please-manifest.json new file mode 100644 index 0000000..e18ee07 --- /dev/null +++ b/.github/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.0.0" +} diff --git a/.github/release-please-config.json b/.github/release-please-config.json new file mode 100644 index 0000000..be9754e --- /dev/null +++ b/.github/release-please-config.json @@ -0,0 +1,14 @@ +{ + "initial-version": "0.0.1", + "packages": { + ".": { + "release-type": "go", + "changelog-path": "CHANGELOG.md", + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": true, + "draft": false, + "prerelease": false + } + }, + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json" +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..99b9a45 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,47 @@ +--- +name: CI +on: [push] + +jobs: + build: + name: build + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: "1.21" + - name: Build binary + run: make + - name: Print version + run: | + ./bin/macos-battery-exporter -v + + release-please: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + outputs: + release_created: ${{ steps.release-please.outputs.release_created }} + version: ${{ steps.release-please.outputs.version }} + steps: + - uses: jimeh/release-please-manifest-action@v1 + id: release-please + + release: + runs-on: ubuntu-latest + needs: [build, release-please] + if: needs.release-please.outputs.release_created + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-go@v4 + with: + go-version: "1.21" + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BREW_TAP_TOKEN: ${{ secrets.BREW_TAP_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..4b270ec --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,49 @@ +before: + hooks: + - go mod tidy +builds: + - env: + - CGO_ENABLED=0 + mod_timestamp: "{{ .CommitTimestamp }}" + flags: + - -trimpath + ldflags: + - "-s -w -X main.version={{ .Version }} -X main.commit={{ .Commit }}" + goos: + - "darwin" + goarch: + - "amd64" + - "arm64" + +universal_binaries: + - replace: true + +archives: + - format: tar.gz + name_template: |- + {{ .ProjectName }}-{{ .Version }}_{{ .Os }}_{{ if eq .Arch "all" }}universal{{ else }}{{ .Arch }}{{ end }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }} + wrap_in_directory: true + +checksum: + name_template: "checksums.txt" +snapshot: + name_template: "{{ .Tag }}-next" + +changelog: + skip: true + +brews: + - name: macos-battery-exporter + homepage: "https://github.com/jimeh/macos-battery-exporter" + description: "Prometheus exporter for detailed battery metrics on macOS." + license: "MIT" + skip_upload: auto + service: | + run [bin/"macos-battery-exporter"] + test: | + system "#{bin}/macos-battery-exporter -v" + repository: + owner: jimeh + name: homebrew-macos-battery-exporter + branch: main + token: "{{ .Env.BREW_TAP_TOKEN }}"