-
Notifications
You must be signed in to change notification settings - Fork 1.3k
140 lines (123 loc) · 5.16 KB
/
build-distributions.yml
File metadata and controls
140 lines (123 loc) · 5.16 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
name: Build Distribution Images
on:
workflow_dispatch:
inputs:
version:
description: 'Distribution version tag (e.g., "0.2.12" or "latest")'
required: true
type: string
distributions:
description: 'Comma-separated list of distributions to build (leave empty for all)'
required: false
type: string
platforms:
description: 'Comma-separated list of platforms (default: linux/amd64,linux/arm64)'
required: false
type: string
default: 'linux/amd64,linux/arm64'
permissions:
contents: read
actions: write
env:
IMAGE_PREFIX: ogx/distribution
jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
distros: ${{ steps.set-matrix.outputs.distros }}
version: ${{ steps.set-version.outputs.version }}
platforms: ${{ steps.set-platforms.outputs.platforms }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set version
id: set-version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
version="${{ github.event.inputs.version }}"
else
# Extract version from tag (e.g., v0.2.12 -> 0.2.12)
version="${GITHUB_REF#refs/tags/v}"
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "Building for version: $version"
- name: Set platforms
id: set-platforms
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.platforms }}" ]; then
platforms="${{ github.event.inputs.platforms }}"
else
platforms="linux/amd64,linux/arm64"
fi
echo "platforms=$platforms" >> "$GITHUB_OUTPUT"
echo "Building for platforms: $platforms"
- name: Generate Distribution List
id: set-matrix
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.distributions }}" ]; then
# Use provided distributions
distros=$(echo "${{ github.event.inputs.distributions }}" | tr ',' '\n' | jq -R -s -c 'split("\n") | map(select(length > 0))')
else
# Get all distributions, excluding ci-tests and __pycache__
distros=$(find src/ogx/distributions -mindepth 2 -maxdepth 2 -name '*build.yaml' 2>/dev/null | \
awk -F'/' '{print $(NF-1)}' | \
grep -v '^ci-tests$' | \
grep -v '^__pycache__$' | \
jq -R -s -c 'split("\n") | map(select(length > 0))')
fi
echo "distros=$distros" >> "$GITHUB_OUTPUT"
echo "Building distributions: $distros"
build:
needs: generate-matrix
runs-on: ubuntu-24.04
strategy:
matrix:
distro: ${{ fromJson(needs.generate-matrix.outputs.distros) }}
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Install dependencies
uses: ./.github/actions/setup-runner
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5
- name: Build distribution image
env:
DISTRO_NAME: ${{ matrix.distro }}
IMAGE_TAG: ${{ needs.generate-matrix.outputs.version }}
PLATFORMS: ${{ needs.generate-matrix.outputs.platforms }}
run: |
LOCAL_IMAGE_NAME="${IMAGE_PREFIX}-${DISTRO_NAME}:${IMAGE_TAG}"
echo "Verifying build for: ${LOCAL_IMAGE_NAME}"
echo "Requested platforms: ${PLATFORMS}"
# Generate config labels (one per line, read into array)
echo "Generating config labels..."
CONFIG_LABELS=$(bash scripts/generate-config-labels.sh "$DISTRO_NAME" "$IMAGE_TAG")
mapfile -t LABEL_ARGS <<< "$CONFIG_LABELS"
# Build arguments
BUILD_ARGS=(--build-arg "INSTALL_MODE=pypi" --build-arg "DISTRO_NAME=${DISTRO_NAME}")
# Add UV index configuration if available (for release branches)
if [ -n "${UV_EXTRA_INDEX_URL:-}" ]; then
BUILD_ARGS+=(--build-arg "UV_EXTRA_INDEX_URL=${UV_EXTRA_INDEX_URL}")
fi
if [ -n "${UV_INDEX_STRATEGY:-}" ]; then
BUILD_ARGS+=(--build-arg "UV_INDEX_STRATEGY=${UV_INDEX_STRATEGY}")
fi
# Build for native platform only (--load only works for single platform)
# This verifies the build works, but maintainers should build multi-arch manually
docker buildx build \
--platform linux/amd64 \
--load \
-f containers/Containerfile \
"${BUILD_ARGS[@]}" \
"${LABEL_ARGS[@]}" \
--tag "${LOCAL_IMAGE_NAME}" \
.
echo "Successfully built: ${LOCAL_IMAGE_NAME}"
- name: Verify embedded config labels
env:
DISTRO_NAME: ${{ matrix.distro }}
IMAGE_TAG: ${{ needs.generate-matrix.outputs.version }}
run: |
LOCAL_IMAGE_NAME="${IMAGE_PREFIX}-${DISTRO_NAME}:${IMAGE_TAG}"
bash scripts/verify-config-labels.sh "${LOCAL_IMAGE_NAME}"