diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6de6244..5110f1c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,14 +2,13 @@ name: release on: workflow_dispatch: - workflow_run: - workflows: - - test - branches: - - main - types: - - completed + push: + tags: + - "v*" +permissions: + contents: write + packages: write jobs: run: @@ -17,18 +16,26 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 + - run: git fetch --force --tags + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - + - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v5 + + - uses: goreleaser/goreleaser-action@v5 with: - push: true - tags: docker.io/notnmeyer/mockpi:latest + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d839fb7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# keep .git out of telescope pickers +.git + +.env +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..40eed54 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,59 @@ +# 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: 1 + +before: + hooks: + - go mod tidy + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - 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 }} + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +dockers: + - image_templates: + - "notnmeyer/mockpi:{{ .Tag }}-amd64" + use: buildx + build_flag_templates: + - "--pull" + - "--platform=linux/amd64" + - image_templates: + - "notnmeyer/mockpi:{{ .Tag }}-arm64" + use: buildx + build_flag_templates: + - "--pull" + - "--platform=linux/arm64" + goarch: arm64 + +docker_manifests: + - name_template: "notnmeyer/mockpi:{{ .Tag }}" + image_templates: + - "notnmeyer/mockpi:{{ .Tag }}-amd64" + - "notnmeyer/mockpi:{{ .Tag }}-arm64" diff --git a/Dockerfile b/Dockerfile index 53a0155..51367fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,3 @@ -FROM docker.io/golang:1.21 as builder -ENV CGO_ENABLED=0 \ - GOOS=linux \ - GOARCH=amd64 -WORKDIR /build -COPY *.go . -COPY go.mod . -RUN go mod tidy -RUN go build -o dist/mockpi ./main.go - FROM scratch -COPY --from=builder /build/dist/mockpi /usr/local/bin/ -CMD ["/usr/local/bin/mockpi"] +COPY mockpi / +ENTRYPOINT ["/mockpi"] diff --git a/tasks.toml b/tasks.toml new file mode 100644 index 0000000..8f7e3eb --- /dev/null +++ b/tasks.toml @@ -0,0 +1,21 @@ +[tasks.run] +cmds = ["go run main.go {{.CLI_ARGS}}"] + +[tasks.test] +cmds = ["go test ./... {{.CLI_ARGS}}"] + +[tasks.build] +dotenv = ".env" +cmds = [ + "docker context use default", + "goreleaser build --clean --snapshot {{.CLI_ARGS}}", +] + +# `tsk release -- --snapshot` to build images without publishing +[tasks.release] +dotenv = ".env" +cmds = [ + "docker context use default", + "goreleaser release --clean {{.CLI_ARGS}}", +] +