Skip to content

build-release

build-release #25

Workflow file for this run

name: Build operator image for release
on:
repository_dispatch:
types: [build-release]
concurrency:
group: operator-${{ github.event.client_payload.version }}
cancel-in-progress: true
jobs:
build:
name: 🔨 Build Binaries and Docker Image
strategy:
matrix:
include:
- platform: linux/amd64
runs-on: ubuntu-24.04
arch: amd64
- platform: linux/arm64
runs-on: ubuntu-24.04-arm
arch: arm64
runs-on: ${{ matrix.runs-on }}
env:
GITHUB_RUN_ID: ${{ github.run_id }}
steps:
- uses: actions/checkout@v4
- name: Setup Go with cache
uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
if: success()
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
provenance: false
push: true
file: ./Dockerfile
tags: ghcr.io/unbindapp/unbind-operator:${{ github.event.client_payload.version }}-${{ matrix.arch }}
create_manifest:
name: 📦 Create and Push Multi-Arch Manifest
runs-on: ubuntu-24.04
needs: [build]
env:
GITHUB_RUN_ID: ${{ github.run_id }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history for changelog generation
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push API manifest
run: |
docker manifest create ghcr.io/unbindapp/unbind-operator:${{ github.event.client_payload.version }} \
--amend ghcr.io/unbindapp/unbind-operator:${{ github.event.client_payload.version }}-amd64 \
--amend ghcr.io/unbindapp/unbind-operator:${{ github.event.client_payload.version }}-arm64
docker manifest annotate --arch amd64 --os linux ghcr.io/unbindapp/unbind-operator:${{ github.event.client_payload.version }} ghcr.io/unbindapp/unbind-operator:${{ github.event.client_payload.version }}-amd64
docker manifest annotate --arch arm64 --os linux ghcr.io/unbindapp/unbind-operator:${{ github.event.client_payload.version }} ghcr.io/unbindapp/unbind-operator:${{ github.event.client_payload.version }}-arm64
docker manifest push ghcr.io/unbindapp/unbind-operator:${{ github.event.client_payload.version }}
# Create git tag
- name: Create Git Tag
if: success()
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git tag -a ${{ github.event.client_payload.version }} -m "Release ${{ github.event.client_payload.version }}"
git push origin ${{ github.event.client_payload.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Generate changelog
- name: Generate Changelog
if: success()
id: changelog
run: |
# Get the previous tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$PREVIOUS_TAG" ]; then
echo "No previous tag found, using all commits"
CHANGELOG=$(git log --oneline --pretty=format:"- %s (%h)" | head -50)
else
echo "Generating changelog from $PREVIOUS_TAG to HEAD"
CHANGELOG=$(git log --oneline --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD)
fi
# Create the changelog with proper formatting
cat > CHANGELOG.md << EOF
## What's Changed
$CHANGELOG
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREVIOUS_TAG}...${{ github.event.client_payload.version }}
EOF
# Set output for use in release step
echo "changelog<<EOF" >> $GITHUB_OUTPUT
cat CHANGELOG.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Create GitHub Release
- name: Create GitHub Release
if: success()
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.client_payload.version }}
release_name: Release ${{ github.event.client_payload.version }}
body: ${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: ${{ contains(github.event.client_payload.version, '-') }}
# Notify meta repo that the operator image is ready
- name: Notify meta repo that the operator image is ready
if: success()
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.PAT_TOKEN }}
repository: unbindapp/unbind-releases
event-type: image-ready
client-payload: |
{
"component": "operator",
"version": "${{ github.event.client_payload.version }}",
"release_id": "${{ github.event.client_payload.release_id }}"
}