Skip to content

Commit f0b4886

Browse files
committed
Change extension handling
1 parent 55c4dee commit f0b4886

File tree

1 file changed

+45
-72
lines changed

1 file changed

+45
-72
lines changed

.github/workflows/build_extensions.yaml

Lines changed: 45 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -51,105 +51,78 @@ jobs:
5151
wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
5252
chmod +x /usr/local/bin/yq
5353
54-
- name: Find extensions
55-
id: find_extensions
54+
- name: Process and build extensions
5655
run: |
56+
# Get branch name
57+
branch="${GITHUB_REF##*/}"
58+
59+
# Convert repository owner to lowercase for Docker compatibility
60+
REPO_OWNER="${{ github.repository_owner }}"
61+
REPO_OWNER_LOWER=$(echo "$REPO_OWNER" | tr '[:upper:]' '[:lower:]')
62+
63+
# Find extensions based on input or search all
5764
if [[ -n "${{ github.event.inputs.specific_extension }}" ]]; then
58-
# Check if the specified extension exists
59-
if [[ -d "extensions/${{ github.event.inputs.specific_extension }}" ]]; then
60-
echo "extensions=$(find extensions/${{ github.event.inputs.specific_extension }} -name 'bioc-extension.yaml')" >> $GITHUB_OUTPUT
61-
echo "Building specific extension: ${{ github.event.inputs.specific_extension }}"
62-
else
65+
if [[ ! -d "extensions/${{ github.event.inputs.specific_extension }}" ]]; then
6366
echo "::error::Extension directory not found: extensions/${{ github.event.inputs.specific_extension }}"
6467
exit 1
6568
fi
69+
extension_files=$(find extensions/${{ github.event.inputs.specific_extension }} -name 'bioc-extension.yaml')
70+
echo "Building specific extension: ${{ github.event.inputs.specific_extension }}"
6671
else
67-
# Find all extensions
68-
echo "extensions=$(find extensions -name 'bioc-extension.yaml' | sort)" >> $GITHUB_OUTPUT
72+
extension_files=$(find extensions -name 'bioc-extension.yaml' | sort)
6973
echo "Building all available extensions"
7074
fi
71-
72-
- name: Extract extension data to files
73-
run: |
74-
branch="${GITHUB_REF##*/}"
75-
76-
# Create empty files
77-
> /tmp/basenames.txt
78-
> /tmp/basetags.txt
79-
> /tmp/outnames.txt
80-
> /tmp/dirs.txt
8175
82-
for ext_file in $(echo "${{ steps.find_extensions.outputs.extensions }}"); do
76+
# Process each extension file directly
77+
for ext_file in $extension_files; do
8378
ext_dir=$(dirname "$ext_file")
8479
ext_name=$(basename "$ext_dir")
8580
8681
echo "Processing extension: $ext_name from $ext_file"
8782
88-
# Parse YAML directly using yq - convert outname to lowercase
89-
outname=$(yq '.container.outname' "$ext_file" | tr '[:upper:]' '[:lower:]')
90-
base_image=$(yq '.container.base.image' "$ext_file" | tr '[:upper:]' '[:lower:]')
91-
9283
# Check if Dockerfile exists
9384
if [[ ! -f "$ext_dir/Dockerfile" ]]; then
9485
echo "::warning::No Dockerfile found for extension $ext_name, skipping"
9586
continue
9687
fi
9788
89+
# Parse YAML directly using yq
90+
outname=$(yq '.container.outname' "$ext_file" | tr '[:upper:]' '[:lower:]')
91+
base_image=$(yq '.container.base.image' "$ext_file" | tr '[:upper:]' '[:lower:]')
92+
9893
# Handle tags
9994
tags_count=$(yq '.container.base.tag | length' "$ext_file")
10095
101-
# If no tags defined, use branch name as default tag
96+
# Build for each tag (or branch name if no tags specified)
10297
if [[ $tags_count -eq 0 ]]; then
103-
echo "$outname" >> /tmp/outnames.txt
104-
echo "$base_image" >> /tmp/basenames.txt
105-
echo "$branch" >> /tmp/basetags.txt
106-
echo "$ext_dir" >> /tmp/dirs.txt
98+
tags=("$branch")
10799
else
108-
# For each tag, create a line in each file
100+
# Get all tags as an array
101+
tags=()
109102
for (( i=0; i<$tags_count; i++ )); do
110-
tag=$(yq ".container.base.tag[$i]" "$ext_file")
111-
echo "$outname" >> /tmp/outnames.txt
112-
echo "$base_image" >> /tmp/basenames.txt
113-
echo "$tag" >> /tmp/basetags.txt
114-
echo "$ext_dir" >> /tmp/dirs.txt
103+
tags+=("$(yq ".container.base.tag[$i]" "$ext_file")")
115104
done
116105
fi
117-
done
118-
119-
echo "Files created with build data:"
120-
echo "===== Outnames ====="
121-
cat /tmp/outnames.txt
122-
echo "===== Base Images ====="
123-
cat /tmp/basenames.txt
124-
echo "===== Tags ====="
125-
cat /tmp/basetags.txt
126-
echo "===== Directories ====="
127-
cat /tmp/dirs.txt
128-
129-
- name: Build extensions
130-
run: |
131-
# Check if we have any extensions to build
132-
if [[ ! -s /tmp/outnames.txt ]]; then
133-
echo "No extensions to build"
134-
exit 0
135-
fi
136-
137-
# Convert repository owner to lowercase for Docker compatibility
138-
REPO_OWNER="${{ github.repository_owner }}"
139-
REPO_OWNER_LOWER=$(echo "$REPO_OWNER" | tr '[:upper:]' '[:lower:]')
140-
141-
# Process line by line with paste command
142-
paste /tmp/outnames.txt /tmp/basenames.txt /tmp/basetags.txt /tmp/dirs.txt | while read outname base_image tag ext_dir; do
143-
echo "Building $outname:$tag from $base_image:$tag using Dockerfile in $ext_dir"
144-
145-
# Build and push with lowercase names
146-
docker buildx build --platform linux/amd64 \
147-
-t "ghcr.io/$REPO_OWNER_LOWER/$outname:$tag" \
148-
-t "docker.io/$REPO_OWNER_LOWER/$outname:$tag" \
149-
--build-arg BASE_IMAGE=$base_image \
150-
--build-arg TAG=$tag \
151-
--push \
152-
"$ext_dir"
153106
154-
echo "Successfully built and pushed $outname:$tag"
107+
# Build for each tag
108+
for tag in "${tags[@]}"; do
109+
echo "Building $outname:$tag from $base_image:$tag using Dockerfile in $ext_dir"
110+
111+
# Build and push with lowercase names
112+
docker buildx build --platform linux/amd64 \
113+
-t "ghcr.io/$REPO_OWNER_LOWER/$outname:$tag" \
114+
-t "docker.io/$REPO_OWNER_LOWER/$outname:$tag" \
115+
--build-arg BASE_IMAGE=$base_image \
116+
--build-arg TAG=$tag \
117+
--push \
118+
"$ext_dir"
119+
120+
build_result=$?
121+
if [ $build_result -ne 0 ]; then
122+
echo "::error::Failed to build $outname:$tag"
123+
exit $build_result
124+
fi
125+
126+
echo "Successfully built and pushed $outname:$tag"
127+
done
155128
done

0 commit comments

Comments
 (0)