Skip to content

Build and publish

Build and publish #65

Workflow file for this run

name: Build and publish
on:
push:
tags:
- '*'
workflow_dispatch:
inputs:
tag:
description: Release tag to publish, for example v0.2.0
required: true
type: string
permissions:
contents: write
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Prepare release metadata
id: prepare
env:
INPUT_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
run: |
set -euo pipefail
tag="${INPUT_TAG#refs/tags/}"
if [[ -z "$tag" || "$tag" == "main" ]]; then
echo "Missing release tag. Provide workflow_dispatch input 'tag' or push a tag."
exit 1
fi
version="${tag#codex-pooler-}"
version="${version#v}"
major_minor="$(awk -F. '{print $1 "." $2}' <<<"$version")"
{
echo "release_tag=$tag"
echo "checkout_ref=refs/tags/$tag"
echo "version=$version"
echo "major_minor=$major_minor"
} >>"$GITHUB_OUTPUT"
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ steps.prepare.outputs.checkout_ref }}
- name: Resolve checked-out revision
id: revision
run: echo "sha=$(git rev-parse HEAD)" >>"$GITHUB_OUTPUT"
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/icoretech/codex-pooler
labels: |
org.opencontainers.image.title=Codex Pooler
org.opencontainers.image.description=Managed pools of Codex accounts with OpenAI-compatible client routes
org.opencontainers.image.source=https://github.com/icoretech/codex-pooler
org.opencontainers.image.documentation=https://github.com/icoretech/codex-pooler/blob/main/README.md
org.opencontainers.image.vendor=iCoreTech, Inc.
org.opencontainers.image.revision=${{ steps.revision.outputs.sha }}
org.opencontainers.image.version=${{ steps.prepare.outputs.version }}
tags: |
type=raw,value=${{ steps.prepare.outputs.version }}
type=raw,value=${{ steps.prepare.outputs.major_minor }}
type=raw,value=latest
- name: Login to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
id: build
uses: docker/build-push-action@v7
with:
platforms: linux/amd64,linux/arm64
pull: true
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
- name: Prepare release assets
env:
RELEASE_TAG: ${{ steps.prepare.outputs.release_tag }}
VERSION: ${{ steps.prepare.outputs.version }}
IMAGE_DIGEST: ${{ steps.build.outputs.digest }}
IMAGE_TAGS: ${{ steps.meta.outputs.tags }}
run: |
set -euo pipefail
asset_base="codex-pooler-self-host-${VERSION}"
asset_dir="dist/${asset_base}"
mkdir -p "${asset_dir}/scripts/self-host"
cp README.md docker-compose.yml .env.example "${asset_dir}/"
cp scripts/self-host/generate-env.sh "${asset_dir}/scripts/self-host/"
tar -C dist -czf "dist/${asset_base}.tar.gz" "${asset_base}"
(
cd dist
sha256sum "${asset_base}.tar.gz" > "${asset_base}.tar.gz.sha256"
)
digest_file="dist/codex-pooler-image-digests-${VERSION}.txt"
{
echo "release_tag=${RELEASE_TAG}"
echo "image_digest=${IMAGE_DIGEST}"
echo
echo "published_tags:"
printf '%s\n' "${IMAGE_TAGS}"
} > "${digest_file}"
- name: Upload release assets
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ steps.prepare.outputs.release_tag }}
run: |
set -euo pipefail
gh release upload "${RELEASE_TAG}" \
dist/codex-pooler-self-host-*.tar.gz \
dist/codex-pooler-self-host-*.tar.gz.sha256 \
dist/codex-pooler-image-digests-*.txt \
--repo "${GITHUB_REPOSITORY}" \
--clobber