Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Release

on: push

jobs:
binary:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.24.x
stable: true

- run: go get -v -t -d ./...
- run: make VERSION=${GITHUB_REF/refs\/tags\/v/} clean build

- uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: build/*
tag: ${{ github.ref }}
overwrite: true
file_glob: true

image:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, this is run for each push but not on pull_requests. I'll change this to master & tag pushes only and add another step to check.yml which only builds one platform to have a faster build.

if: ${{ startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/tags/v') }}
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
attestations: write
id-token: write

steps:
- uses: actions/checkout@v4

- if: startsWith(github.ref, 'refs/tags/v')
run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV
- run: echo "DOCKER_BUILD_PUSH=true" >> $GITHUB_ENV

- uses: docker/setup-buildx-action@v3
- uses: docker/setup-qemu-action@v3
- uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- run: |
make REGISTRY=docker.io build-docker-multiarch
make REGISTRY=ghcr.io build-docker-multiarch
12 changes: 8 additions & 4 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ on: [push, pull_request]
jobs:
check:
runs-on: ubuntu-latest
strategy:
matrix:
go: [1.20.x, 1.21.x, 1.22.x]
steps:
- name: Setup Go environment
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
go-version: 1.24.x
stable: true

- name: Check out code into the Go module directory
Expand All @@ -21,3 +18,10 @@ jobs:

- name: Test
run: go test ./...
image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- run: |
make PLATFORM=linux/amd64 build-docker-multiarch
37 changes: 0 additions & 37 deletions .github/workflows/release.yml

This file was deleted.

28 changes: 0 additions & 28 deletions Dockerfile

This file was deleted.

43 changes: 39 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,46 @@
BUILD_DIR=./build
SHELL := /bin/bash

# Env var inputs for container image builds
# REGISTRY: The registry to which the build image should be pushed to.
# IMAGE: The name of the image to build and publish in the afore mentioned registry.
# PLATFORM: The platform for which the image should be built
REGISTRY ?= docker.io
IMAGE ?= gotify/cli
PLATFORM ?= linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/riscv64

# Env var inputs for all builds
# VERSION: The version for which the container image or the binary is being built.
# When it is not provided, no version will be specified in the built package.
# COMMIT: The commit of this project for which the cli is being built, for reference in the tool's "version" command.
# LD_FLAGS: Build flags, for the tool's "version" command.
COMMIT ?= $(shell git rev-parse --verify HEAD)
LD_FLAGS ?= $(if $(VERSION),-X main.Version=${VERSION}) \
-X main.BuildDate=$(shell date "+%F-%T") \
-X main.Commit=${COMMIT}

ifdef GOTOOLCHAIN
GO_VERSION=$(GOTOOLCHAIN)
else
GO_VERSION=$(shell go mod edit -json | jq -r .Toolchain | sed -e 's/go//')
endif

build-docker-multiarch:
docker buildx build \
$(if $(DOCKER_BUILD_PUSH),--push) \
-t ${REGISTRY}/${IMAGE}:master \
$(if $(VERSION),-t ${REGISTRY}/${IMAGE}:latest) \
$(if $(VERSION),-t ${REGISTRY}/${IMAGE}:${VERSION}) \
$(if $(VERSION),-t ${REGISTRY}/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -2)) \
$(if $(VERSION),-t ${REGISTRY}/${IMAGE}:$(shell echo $(VERSION) | cut -d '.' -f -1)) \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg LD_FLAGS="$(LD_FLAGS)" \
--platform $(PLATFORM) \
-f docker/Dockerfile .

clean:
rm -rf ${BUILD_DIR}
rm -rf build

build:
if [ '$(shell echo "${GIT_TAG}" | cut -c 1 )' != 'v' ]; then exit 1; fi;
$(eval LD_FLAGS := -X main.Version=$(shell echo ${GIT_TAG} | cut -c 2-) -X main.BuildDate=$(shell date "+%F-%T") -X main.Commit=$(shell git rev-parse --verify HEAD))
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="${LD_FLAGS}" -o build/gotify-cli-windows-amd64.exe cli.go
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags="${LD_FLAGS}" -o build/gotify-cli-windows-386.exe cli.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="${LD_FLAGS}" -o build/gotify-cli-linux-amd64 cli.go
Expand Down
26 changes: 26 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ARG BUILDKIT_SBOM_SCAN_CONTEXT=true
ARG GO_VERSION=PLEASE_PROVIDE_GO_VERSION
ARG BUILDPLATFORM

FROM --platform=${BUILDPLATFORM} docker.io/golang:${GO_VERSION}-alpine AS builder

ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG LD_FLAGS

WORKDIR /src
COPY . /src

RUN GOOS=${TARGETOS} \
GOARCH=${TARGETARCH} \
GOARM=$(echo $TARGETPLATFORM | sed -En 's|^linux/arm/v(.*)|\1|p') \
go build -mod=readonly -a -installsuffix cgo -ldflags "${LD_FLAGS}" -o /target/app/gotify-cli

FROM docker.io/library/alpine:latest

RUN apk add --no-cache ca-certificates

COPY --from=builder /target/app/gotify-cli /gotify-cli

ENTRYPOINT ["/gotify-cli"]
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/gotify/cli/v2

go 1.18
go 1.23

toolchain go1.24.1

require (
github.com/adrg/xdg v0.4.0
Expand Down
Loading