Skip to content

Commit e9e9d59

Browse files
authored
Merge pull request #20 from alicefr/release
Add GHA for create automatic release based on the tag
2 parents f14980d + f779cc4 commit e9e9d59

5 files changed

Lines changed: 120 additions & 4 deletions

File tree

.github/workflows/release.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
packages: write
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Extract version from tag
22+
id: version
23+
run: echo "version=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
24+
25+
- name: Log in to GHCR
26+
run: podman login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} ${{ env.REGISTRY }}
27+
28+
- name: Build bink binary
29+
run: |
30+
podman build --build-arg VERSION=${{ steps.version.outputs.version }} \
31+
--target builder -t localhost/bink-builder:latest -f Containerfile .
32+
podman create --name bink-builder-tmp localhost/bink-builder:latest
33+
podman cp bink-builder-tmp:/output/bink ./bink
34+
podman rm bink-builder-tmp
35+
chmod +x ./bink
36+
./bink version
37+
38+
- name: Build and push bink image
39+
run: |
40+
make build-bink-image VERSION=${{ steps.version.outputs.version }}
41+
podman tag ${{ env.REGISTRY }}/${{ github.repository }}/bink:latest \
42+
${{ env.REGISTRY }}/${{ github.repository }}/bink:${{ steps.version.outputs.version }}
43+
podman push ${{ env.REGISTRY }}/${{ github.repository }}/bink:${{ steps.version.outputs.version }}
44+
podman push ${{ env.REGISTRY }}/${{ github.repository }}/bink:latest
45+
46+
- name: Build and push cluster image
47+
run: |
48+
make build-cluster-image
49+
podman tag ${{ env.REGISTRY }}/${{ github.repository }}/cluster:latest \
50+
${{ env.REGISTRY }}/${{ github.repository }}/cluster:${{ steps.version.outputs.version }}
51+
podman push ${{ env.REGISTRY }}/${{ github.repository }}/cluster:${{ steps.version.outputs.version }}
52+
podman push ${{ env.REGISTRY }}/${{ github.repository }}/cluster:latest
53+
54+
- name: Build and push dns image
55+
run: |
56+
make build-dns-image
57+
podman tag ${{ env.REGISTRY }}/${{ github.repository }}/dns:latest \
58+
${{ env.REGISTRY }}/${{ github.repository }}/dns:${{ steps.version.outputs.version }}
59+
podman push ${{ env.REGISTRY }}/${{ github.repository }}/dns:${{ steps.version.outputs.version }}
60+
podman push ${{ env.REGISTRY }}/${{ github.repository }}/dns:latest
61+
62+
- name: Create GitHub Release
63+
env:
64+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
run: |
66+
gh release create ${{ steps.version.outputs.version }} \
67+
./bink \
68+
--title "${{ steps.version.outputs.version }}" \
69+
--generate-notes

Containerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@ RUN --mount=type=cache,target=/go/pkg/mod \
1919
go mod download
2020

2121
# Copy source and build
22+
ARG VERSION=dev
2223
COPY . /src
2324
WORKDIR /output
2425
RUN --mount=type=cache,target=/root/.cache/go-build \
2526
--mount=type=cache,target=/go/pkg/mod \
26-
cd /src && CGO_ENABLED=1 go build -o /output/bink ./cmd/bink
27+
GIT_COMMIT=$(cd /src && git rev-parse --short HEAD 2>/dev/null || echo "") && \
28+
BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) && \
29+
VERSION_PKG=github.com/bootc-dev/bink/internal/version && \
30+
cd /src && CGO_ENABLED=1 go build \
31+
-ldflags "-X ${VERSION_PKG}.Version=${VERSION} -X ${VERSION_PKG}.GitCommit=${GIT_COMMIT} -X ${VERSION_PKG}.BuildDate=${BUILD_DATE}" \
32+
-o /output/bink ./cmd/bink
2733

2834
# Runtime image with just the binary and required C runtime libraries
2935
FROM quay.io/fedora/fedora-minimal:${FEDORA_VERSION}

Makefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ FEDORA_VERSION := $(call extract,FedoraVersion )
1212
# Binary
1313
BINK_BINARY := bink
1414

15+
# Version info (overridable, e.g. make build-bink VERSION=v0.1.0)
16+
VERSION ?= dev
17+
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null)
18+
BUILD_DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
19+
VERSION_PKG := github.com/bootc-dev/bink/internal/version
20+
LDFLAGS := -X $(VERSION_PKG).Version=$(VERSION) \
21+
-X $(VERSION_PKG).GitCommit=$(GIT_COMMIT) \
22+
-X $(VERSION_PKG).BuildDate=$(BUILD_DATE)
23+
1524
# Directories
1625
VM_DIR := containerfiles/cluster-image
1726

@@ -20,14 +29,15 @@ all: build-bink
2029
# Build the bink CLI binary
2130
build-bink:
2231
@echo "=== Building bink CLI binary ==="
23-
go build -o $(BINK_BINARY) ./cmd/bink
32+
go build -ldflags "$(LDFLAGS)" -o $(BINK_BINARY) ./cmd/bink
2433
@echo "✅ bink binary built: $(BINK_BINARY)"
2534

35+
2636
# Build the bink CLI container image
2737
build-bink-image:
2838
@echo "=== Building bink CLI container image ==="
29-
podman build --build-arg FEDORA_VERSION=$(FEDORA_VERSION) --target builder -t localhost/bink-builder:latest -f Containerfile .
30-
podman build --build-arg FEDORA_VERSION=$(FEDORA_VERSION) -t $(BINK_IMAGE) -f Containerfile .
39+
podman build --build-arg FEDORA_VERSION=$(FEDORA_VERSION) --build-arg VERSION=$(VERSION) --target builder -t localhost/bink-builder:latest -f Containerfile .
40+
podman build --build-arg FEDORA_VERSION=$(FEDORA_VERSION) --build-arg VERSION=$(VERSION) -t $(BINK_IMAGE) -f Containerfile .
3141
@echo "✅ Bink CLI image built: $(BINK_IMAGE)"
3242

3343
# Build the cluster container image

cmd/bink/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/bootc-dev/bink/internal/cli/node"
1313
"github.com/bootc-dev/bink/internal/cli/registry"
1414
"github.com/bootc-dev/bink/internal/config"
15+
"github.com/bootc-dev/bink/internal/version"
1516
"github.com/sirupsen/logrus"
1617
"github.com/spf13/cobra"
1718
"github.com/spf13/viper"
@@ -65,6 +66,13 @@ func init() {
6566
rootCmd.AddCommand(node.NewNodeCmd())
6667
rootCmd.AddCommand(api.NewAPICmd())
6768
rootCmd.AddCommand(registry.NewRegistryCmd())
69+
rootCmd.AddCommand(&cobra.Command{
70+
Use: "version",
71+
Short: "Print the version",
72+
Run: func(cmd *cobra.Command, args []string) {
73+
fmt.Println(version.Print())
74+
},
75+
})
6876
}
6977

7078
func initConfig() {

internal/version/version.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-FileCopyrightText: 2026 The bink Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package version
5+
6+
import "fmt"
7+
8+
var (
9+
Version = "dev"
10+
GitCommit = ""
11+
BuildDate = ""
12+
)
13+
14+
func Print() string {
15+
s := fmt.Sprintf("bink version %s", Version)
16+
if GitCommit != "" {
17+
s += fmt.Sprintf("\n commit: %s", GitCommit)
18+
}
19+
if BuildDate != "" {
20+
s += fmt.Sprintf("\n built: %s", BuildDate)
21+
}
22+
return s
23+
}

0 commit comments

Comments
 (0)