Skip to content

build-new-release

build-new-release #12

name: Build and Push Docker Image
on:
repository_dispatch:
types: [build-new-release]
workflow_dispatch:
inputs:
version:
description: 'Version to build'
required: true
type: string
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/picoclaw
jobs:
build-push:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout your repository
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT_TOKEN }} # Needed to push Dockerfile updates
ref: main
- name: Checkout upstream repository
uses: actions/checkout@v4
with:
repository: sipeed/picoclaw
ref: ${{ github.event.client_payload.version || github.event.inputs.version }}
path: upstream
- name: Extract Go version from upstream go.mod
id: goversion
run: |
GO_VERSION=$(grep '^go ' upstream/go.mod | awk '{print $2}')
echo "go_version=$GO_VERSION" >> $GITHUB_OUTPUT
echo "Detected Go version: $GO_VERSION"
- name: Update Dockerfile with new versions
env:
NEW_VERSION: ${{ github.event.client_payload.version || github.event.inputs.version }}
GO_VERSION: ${{ steps.goversion.outputs.go_version }}
run: |
# Update Go version in FROM line
sed -i "s|FROM golang:[^[:space:]]*-alpine|FROM golang:${GO_VERSION}-alpine|g" Dockerfile
# Update PICOCLAW_VERSION ARG
sed -i "s|ARG PICOCLAW_VERSION=.*|ARG PICOCLAW_VERSION=${NEW_VERSION}|g" Dockerfile
echo "Updated Dockerfile:"
grep -E 'FROM golang:|ARG PICOCLAW_VERSION=' Dockerfile
- name: Commit Dockerfile updates
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add Dockerfile
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Update Dockerfile for picoclaw ${{ github.event.client_payload.version || github.event.inputs.version }}"
git push
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
build-args: |
PICOCLAW_VERSION=${{ github.event.client_payload.version || github.event.inputs.version }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.event.client_payload.version || github.event.inputs.version }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Update version tracking
run: |
echo "${{ github.event.client_payload.version || github.event.inputs.version }}" > .last-build-version
git add .last-build-version
if git diff --staged --quiet; then
echo "Version already tracked"
else
git commit -m "Built version ${{ github.event.client_payload.version || github.event.inputs.version }}"
git push
fi
- name: Trigger Helm Chart Update
if: success()
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
event-type: docker-image-published
client-payload: |
{"version": "${{ github.event.client_payload.version || github.event.inputs.version }}"}