Files
container/.github/workflows/build-test-images.yml
T
Satyam Singh 5240d36464 fix: quote inputs and improve shell conditionals for safety (#68)
This PR improves **safety and consistency** of the GitHub Actions
workflow (build-test-images.yml) file by:
  - Using **[[ ... ]]** **instea**d of **[ ... ]** for conditionals.
- Adding **double quotes** around inputs and refs to **avoid**
evaluation issues.

This helps prevent bugs in **shell parsing**, especially with **empty or
misinterpreted** input values.


@katiewasnothere @wlan0
2025-06-10 13:54:48 -07:00

69 lines
2.2 KiB
YAML

name: Build and publish containerization test images
on:
workflow_dispatch:
inputs:
publish:
type: boolean
description: "Publish the built image"
default: false
version:
type: string
description: "Version of the image to create"
default: "test"
image:
type: choice
description: Test image to build
options:
- dockermanifestimage
- emptyimage
default: 'dockermanifestimage'
useBuildx:
type: boolean
description: "Use docker buildx to build the image"
default: false
jobs:
image:
name: Build test images
timeout-minutes: 30
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check branch
run: |
if [[ "${{ github.ref }}" != "refs/heads/main" ]] && [[ "${{ github.ref }}" != refs/heads/release* ]] && [[ "${{ inputs.publish }}" == "true" ]]; then
echo "❌ Cannot publish an image if we are not on main or a release branch."
exit 1
fi
- name: Check inputs
run: |
if [[ "${{ inputs.image }}" == "dockermanifestimage" ]] && [[ "${{ inputs.useBuildx }}" == "true" ]]; then
echo "❌ dockermanifestimage cannot be built with buildx"
exit 1
fi
if [[ "${{ inputs.image }}" == "emptyimage" ]] && [[ "${{ inputs.useBuildx }}" != "true" ]]; then
echo "❌ emptyimage should be built with buildx"
exit 1
fi
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
if: ${{ inputs.useBuildx }}
uses: docker/setup-buildx-action@v3
- name: Build dockerfile and push image
uses: docker/build-push-action@v6
with:
push: ${{ inputs.publish }}
context: Tests/TestImages/${{ inputs.image }}
tags: ghcr.io/apple/containerization/${{ inputs.image }}:${{ inputs.version }}