-
-
Notifications
You must be signed in to change notification settings - Fork 4
145 lines (122 loc) · 4.58 KB
/
Copy pathbuild.yml
File metadata and controls
145 lines (122 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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