diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index d88a458..d9d049c 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -5,6 +5,7 @@ on: branches: [main] pull_request: branches: [main] + workflow_call: permissions: contents: read @@ -66,7 +67,7 @@ jobs: with: go-version-file: 'go.mod' - name: Build - run: go build -o /dev/null ./cmd/zettelkasten-exporter/main.go + run: go build -o /dev/null test: needs: build runs-on: ubuntu-latest diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..6768382 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,66 @@ +name: Release + +on: + push: + tags: + - "v*.*.*" + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + check: + uses: ./.github/workflows/check.yaml + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + attestations: write + id-token: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Log in to the container registry + uses: docker/login-action@v5 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build and push Docker image + id: push + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true + create-release: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v5 + - name: Run goreleaser + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: '~> v2' + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index ba077a4..e73981d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ bin +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..f0ff055 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,46 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +# The lines below are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 2 + +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + # you may remove this if you don't need go generate + - go generate ./... + +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 + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/Dockerfile b/Dockerfile index abb74ae..33404a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ RUN go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux go build -o /zettelkasten-exporter ./cmd/zettelkasten-exporter/main.go +RUN CGO_ENABLED=0 GOOS=linux go build -o /zettelkasten-exporter FROM gcr.io/distroless/base-debian12 AS release-stage diff --git a/Makefile b/Makefile index 0d30245..2aab284 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ BINARY_NAME=zettelkasten-exporter -.PHONY: all clean format vet lint test get build run +.PHONY: all clean format vet lint test build run -all: format vet test build +all: format vet build test clean: go clean @@ -20,11 +20,8 @@ lint: test: go test ./... -get: - go get ./... - -build: get - go build -o bin/$(BINARY_NAME) ./cmd/zettelkasten-exporter/main.go +build: + go build -o bin/$(BINARY_NAME) run: build LOG_LEVEL=INFO \ diff --git a/cmd/zettelkasten-exporter/main.go b/main.go similarity index 100% rename from cmd/zettelkasten-exporter/main.go rename to main.go