mirror of
https://github.com/warmbly/warmbly.git
synced 2026-08-22 00:01:25 +00:00
348 lines
11 KiB
YAML
348 lines
11 KiB
YAML
name: Release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*.*.*"
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_PREFIX: ghcr.io/${{ github.repository_owner }}/warmbly
|
|
|
|
jobs:
|
|
validate-tag:
|
|
name: Validate Tag
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
version: ${{ steps.version.outputs.version }}
|
|
major: ${{ steps.version.outputs.major }}
|
|
minor: ${{ steps.version.outputs.minor }}
|
|
steps:
|
|
- name: Extract version
|
|
id: version
|
|
run: |
|
|
TAG="${{ github.ref_name }}"
|
|
# Remove 'v' prefix
|
|
VERSION="${TAG#v}"
|
|
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
|
|
|
# Extract major and minor
|
|
MAJOR=$(echo "$VERSION" | cut -d. -f1)
|
|
MINOR=$(echo "$VERSION" | cut -d. -f1-2)
|
|
echo "major=${MAJOR}" >> $GITHUB_OUTPUT
|
|
echo "minor=${MINOR}" >> $GITHUB_OUTPUT
|
|
|
|
echo "Release version: ${VERSION}"
|
|
echo "Major: ${MAJOR}, Minor: ${MINOR}"
|
|
|
|
build-backend:
|
|
name: Build Backend
|
|
needs: validate-tag
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: deploy/docker/backend.Dockerfile
|
|
push: true
|
|
tags: |
|
|
${{ env.IMAGE_PREFIX }}/backend:${{ github.ref_name }}
|
|
${{ env.IMAGE_PREFIX }}/backend:v${{ needs.validate-tag.outputs.minor }}
|
|
${{ env.IMAGE_PREFIX }}/backend:v${{ needs.validate-tag.outputs.major }}
|
|
${{ env.IMAGE_PREFIX }}/backend:prod
|
|
platforms: linux/amd64,linux/arm64
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
build-args: |
|
|
SERVICE=backend
|
|
VERSION=${{ needs.validate-tag.outputs.version }}
|
|
|
|
build-consumer:
|
|
name: Build Consumer
|
|
needs: validate-tag
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: deploy/docker/consumer.Dockerfile
|
|
push: true
|
|
tags: |
|
|
${{ env.IMAGE_PREFIX }}/consumer:${{ github.ref_name }}
|
|
${{ env.IMAGE_PREFIX }}/consumer:v${{ needs.validate-tag.outputs.minor }}
|
|
${{ env.IMAGE_PREFIX }}/consumer:v${{ needs.validate-tag.outputs.major }}
|
|
${{ env.IMAGE_PREFIX }}/consumer:prod
|
|
platforms: linux/amd64,linux/arm64
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
build-args: |
|
|
SERVICE=consumer
|
|
VERSION=${{ needs.validate-tag.outputs.version }}
|
|
|
|
build-worker:
|
|
name: Build Worker
|
|
needs: validate-tag
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: deploy/docker/worker.Dockerfile
|
|
push: true
|
|
tags: |
|
|
${{ env.IMAGE_PREFIX }}/worker:${{ github.ref_name }}
|
|
${{ env.IMAGE_PREFIX }}/worker:v${{ needs.validate-tag.outputs.minor }}
|
|
${{ env.IMAGE_PREFIX }}/worker:v${{ needs.validate-tag.outputs.major }}
|
|
${{ env.IMAGE_PREFIX }}/worker:prod
|
|
platforms: linux/amd64,linux/arm64
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
build-args: |
|
|
SERVICE=worker
|
|
VERSION=${{ needs.validate-tag.outputs.version }}
|
|
|
|
build-tracking:
|
|
name: Build Tracking
|
|
needs: validate-tag
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: ./tracking
|
|
file: ./tracking/Dockerfile
|
|
push: true
|
|
tags: |
|
|
${{ env.IMAGE_PREFIX }}/tracking:${{ github.ref_name }}
|
|
${{ env.IMAGE_PREFIX }}/tracking:v${{ needs.validate-tag.outputs.minor }}
|
|
${{ env.IMAGE_PREFIX }}/tracking:v${{ needs.validate-tag.outputs.major }}
|
|
${{ env.IMAGE_PREFIX }}/tracking:prod
|
|
platforms: linux/amd64,linux/arm64
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
build-args: |
|
|
VERSION=${{ needs.validate-tag.outputs.version }}
|
|
|
|
# Elixir has no cross-compiler, so an emulated arm64 `mix release` under QEMU
|
|
# runs for hours. Build each arch on a native runner and merge the digests
|
|
# into one manifest (the Docker-documented multi-runner pattern).
|
|
build-realtime:
|
|
name: Build Realtime
|
|
needs: validate-tag
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- platform: linux/amd64
|
|
runner: ubuntu-latest
|
|
- platform: linux/arm64
|
|
runner: ubuntu-24.04-arm
|
|
runs-on: ${{ matrix.runner }}
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Prepare platform pair
|
|
id: prep
|
|
run: echo "pair=${PLATFORM//\//-}" >> "$GITHUB_OUTPUT"
|
|
env:
|
|
PLATFORM: ${{ matrix.platform }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build and push by digest
|
|
id: build
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: deploy/docker/realtime.Dockerfile
|
|
platforms: ${{ matrix.platform }}
|
|
cache-from: type=gha,scope=realtime-${{ steps.prep.outputs.pair }}
|
|
cache-to: type=gha,mode=max,scope=realtime-${{ steps.prep.outputs.pair }}
|
|
outputs: type=image,name=${{ env.IMAGE_PREFIX }}/realtime,push-by-digest=true,name-canonical=true,push=true
|
|
build-args: |
|
|
VERSION=${{ needs.validate-tag.outputs.version }}
|
|
|
|
- name: Export digest
|
|
run: |
|
|
mkdir -p /tmp/digests
|
|
digest="${{ steps.build.outputs.digest }}"
|
|
touch "/tmp/digests/${digest#sha256:}"
|
|
|
|
- name: Upload digest
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: digests-realtime-${{ steps.prep.outputs.pair }}
|
|
path: /tmp/digests/*
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
merge-realtime:
|
|
name: Merge Realtime manifest
|
|
needs: [validate-tag, build-realtime]
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- name: Download digests
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
path: /tmp/digests
|
|
pattern: digests-realtime-*
|
|
merge-multiple: true
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Create manifest list and push
|
|
working-directory: /tmp/digests
|
|
run: |
|
|
docker buildx imagetools create \
|
|
-t ${{ env.IMAGE_PREFIX }}/realtime:${{ github.ref_name }} \
|
|
-t ${{ env.IMAGE_PREFIX }}/realtime:v${{ needs.validate-tag.outputs.minor }} \
|
|
-t ${{ env.IMAGE_PREFIX }}/realtime:v${{ needs.validate-tag.outputs.major }} \
|
|
-t ${{ env.IMAGE_PREFIX }}/realtime:prod \
|
|
$(printf '${{ env.IMAGE_PREFIX }}/realtime@sha256:%s ' *)
|
|
|
|
create-release:
|
|
name: Create GitHub Release
|
|
needs: [validate-tag, build-backend, build-consumer, build-worker, build-tracking, merge-realtime]
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Generate changelog
|
|
id: changelog
|
|
run: |
|
|
# Get previous tag
|
|
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
|
|
|
|
if [[ -n "$PREV_TAG" ]]; then
|
|
echo "Generating changelog from $PREV_TAG to ${{ github.ref_name }}"
|
|
CHANGELOG=$(git log --pretty=format:"- %s (%h)" $PREV_TAG..${{ github.ref_name }} | head -50)
|
|
else
|
|
echo "No previous tag found, generating from beginning"
|
|
CHANGELOG=$(git log --pretty=format:"- %s (%h)" | head -50)
|
|
fi
|
|
|
|
# Escape for GitHub Actions
|
|
CHANGELOG="${CHANGELOG//'%'/'%25'}"
|
|
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
|
|
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
|
|
|
|
echo "changelog=${CHANGELOG}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Create Release
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
tag_name: ${{ github.ref_name }}
|
|
name: Release ${{ github.ref_name }}
|
|
body: |
|
|
## What's Changed
|
|
|
|
${{ steps.changelog.outputs.changelog }}
|
|
|
|
## Docker Images
|
|
|
|
All images are available at `ghcr.io/${{ github.repository_owner }}/warmbly`:
|
|
|
|
| Service | Image |
|
|
|---------|-------|
|
|
| Backend | `${{ env.IMAGE_PREFIX }}/backend:${{ github.ref_name }}` |
|
|
| Consumer | `${{ env.IMAGE_PREFIX }}/consumer:${{ github.ref_name }}` |
|
|
| Worker | `${{ env.IMAGE_PREFIX }}/worker:${{ github.ref_name }}` |
|
|
| Tracking | `${{ env.IMAGE_PREFIX }}/tracking:${{ github.ref_name }}` |
|
|
| Realtime | `${{ env.IMAGE_PREFIX }}/realtime:${{ github.ref_name }}` |
|
|
|
|
## Deployment
|
|
|
|
This release will be automatically deployed to production.
|
|
draft: false
|
|
prerelease: ${{ contains(github.ref_name, '-') }}
|
|
generate_release_notes: true
|