ci: use goreleaser to release docker and binary (#180)

Signed-off-by: Guoguo <i@qwq.trade>
This commit is contained in:
Guoguo
2026-02-16 10:35:31 +08:00
committed by GitHub
parent 1d748fb742
commit 0d18210803
4 changed files with 102 additions and 61 deletions

View File

@@ -1,12 +1,18 @@
name: 🐳 Build & Push Docker Image name: 🐳 Build & Push Docker Image
on: on:
release: workflow_call:
types: [published] inputs:
tag:
description: "Release tag"
required: true
type: string
env: env:
REGISTRY: ghcr.io GHCR_REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/picoclaw GHCR_IMAGE_NAME: ${{ github.repository_owner }}/picoclaw
DOCKERHUB_REGISTRY: docker.io
DOCKERHUB_IMAGE_NAME: ${{ vars.DOCKERHUB_REPOSITORY }}
jobs: jobs:
build: build:
@@ -20,6 +26,8 @@ jobs:
# ── Checkout ────────────────────────────── # ── Checkout ──────────────────────────────
- name: 📥 Checkout repository - name: 📥 Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}
# ── Docker Buildx ───────────────────────── # ── Docker Buildx ─────────────────────────
- name: 🔧 Set up Docker Buildx - name: 🔧 Set up Docker Buildx
@@ -27,36 +35,42 @@ jobs:
# ── Login to GHCR ───────────────────────── # ── Login to GHCR ─────────────────────────
- name: 🔑 Login to GitHub Container Registry - name: 🔑 Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: ${{ env.REGISTRY }} registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
# ── Metadata (tags & labels) ────────────── # ── Login to Docker Hub ────────────────────
- name: 🏷️ Extract Docker metadata - name: 🔑 Login to Docker Hub
id: meta uses: docker/login-action@v3
uses: docker/metadata-action@v5
with: with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} registry: ${{ env.DOCKERHUB_REGISTRY }}
tags: | username: ${{ secrets.DOCKERHUB_USERNAME }}
type=ref,event=branch password: ${{ secrets.DOCKERHUB_TOKEN }}
type=ref,event=pr
type=semver,pattern={{version}} # ── Metadata (tags & labels) ──────────────
type=semver,pattern={{major}}.{{minor}} - name: 🏷️ Prepare image tags
type=sha,prefix= id: tags
type=raw,value=latest,enable={{is_default_branch}} shell: bash
type=raw,value={{date 'YYYYMMDD-HHmmss'}},enable={{is_default_branch}} run: |
tag="${{ inputs.tag }}"
echo "ghcr_tag=${{ env.GHCR_REGISTRY }}/${{ env.GHCR_IMAGE_NAME }}:${tag}" >> "$GITHUB_OUTPUT"
echo "ghcr_latest=${{ env.GHCR_REGISTRY }}/${{ env.GHCR_IMAGE_NAME }}:latest" >> "$GITHUB_OUTPUT"
echo "dockerhub_tag=${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE_NAME }}:${tag}" >> "$GITHUB_OUTPUT"
echo "dockerhub_latest=${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE_NAME }}:latest" >> "$GITHUB_OUTPUT"
# ── Build & Push ────────────────────────── # ── Build & Push ──────────────────────────
- name: 🚀 Build and push Docker image - name: 🚀 Build and push Docker image
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
context: . context: .
push: ${{ github.event_name != 'pull_request' }} push: true
tags: ${{ steps.meta.outputs.tags }} tags: |
labels: ${{ steps.meta.outputs.labels }} ${{ steps.tags.outputs.ghcr_tag }}
${{ steps.tags.outputs.ghcr_latest }}
${{ steps.tags.outputs.dockerhub_tag }}
${{ steps.tags.outputs.dockerhub_latest }}
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64,linux/riscv64

View File

@@ -38,14 +38,18 @@ jobs:
git tag -a "${{ inputs.tag }}" -m "Release ${{ inputs.tag }}" git tag -a "${{ inputs.tag }}" -m "Release ${{ inputs.tag }}"
git push origin "${{ inputs.tag }}" git push origin "${{ inputs.tag }}"
build-binaries: release:
name: Build Release Binaries name: GoReleaser Release
needs: create-tag needs: create-tag
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps: steps:
- name: Checkout tag - name: Checkout tag
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 0
ref: ${{ inputs.tag }} ref: ${{ inputs.tag }}
- name: Setup Go from go.mod - name: Setup Go from go.mod
@@ -53,47 +57,42 @@ jobs:
with: with:
go-version-file: go.mod go-version-file: go.mod
- name: Build all binaries - name: Set up QEMU
run: make build-all uses: docker/setup-qemu-action@v3
- name: Generate checksums - name: Set up Docker Buildx
shell: bash uses: docker/setup-buildx-action@v3
run: |
shasum -a 256 build/picoclaw-* > build/sha256sums.txt
- name: Upload release binaries artifact - name: Login to GitHub Container Registry
uses: actions/upload-artifact@v4 uses: docker/login-action@v3
with: with:
name: picoclaw-binaries registry: ghcr.io
path: | username: ${{ github.actor }}
build/picoclaw-* password: ${{ secrets.GITHUB_TOKEN }}
build/sha256sums.txt
if-no-files-found: error
create-release: - name: Login to Docker Hub
name: Create GitHub Release uses: docker/login-action@v3
needs: [create-tag, build-binaries]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with: with:
path: release-artifacts registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Show downloaded files - name: Run GoReleaser
run: ls -R release-artifacts uses: goreleaser/goreleaser-action@v6
- name: Create release
uses: softprops/action-gh-release@v2
with: with:
tag_name: ${{ inputs.tag }} distribution: goreleaser
name: ${{ inputs.tag }} version: ~> v2
draft: ${{ inputs.draft }} args: release --clean
prerelease: ${{ inputs.prerelease }}
files: |
release-artifacts/**/*
generate_release_notes: true
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
DOCKERHUB_IMAGE_NAME: ${{ vars.DOCKERHUB_REPOSITORY }}
- name: Apply release flags
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release edit "${{ inputs.tag }}" \
--draft=${{ inputs.draft }} \
--prerelease=${{ inputs.prerelease }}

View File

@@ -5,9 +5,11 @@ version: 2
before: before:
hooks: hooks:
- go mod tidy - go mod tidy
- go generate ./cmd/picoclaw
builds: builds:
- env: - id: picoclaw
env:
- CGO_ENABLED=0 - CGO_ENABLED=0
goos: goos:
- linux - linux
@@ -26,6 +28,22 @@ builds:
- goos: windows - goos: windows
goarch: arm goarch: arm
dockers_v2:
- id: picoclaw
dockerfile: Dockerfile.goreleaser
ids:
- picoclaw
images:
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY_OWNER }}/picoclaw"
- "docker.io/{{ .Env.DOCKERHUB_IMAGE_NAME }}"
tags:
- "{{ .Tag }}"
- "latest"
platforms:
- linux/amd64
- linux/arm64
- linux/riscv64
archives: archives:
- formats: [tar.gz] - formats: [tar.gz]
# this name template makes the OS and Arch compatible with the results of `uname`. # this name template makes the OS and Arch compatible with the results of `uname`.

10
Dockerfile.goreleaser Normal file
View File

@@ -0,0 +1,10 @@
FROM alpine:3.21
ARG TARGETPLATFORM
RUN apk add --no-cache ca-certificates tzdata
COPY $TARGETPLATFORM/picoclaw /usr/local/bin/picoclaw
ENTRYPOINT ["picoclaw"]
CMD ["gateway"]