Skip to content

Trigger unit tests for docker images upload workflow #3

Trigger unit tests for docker images upload workflow

Trigger unit tests for docker images upload workflow #3

# Copyright 2025 Google LLC

Check failure on line 1 in .github/workflows/build_and_push_docker_image.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/build_and_push_docker_image.yml

Invalid workflow file

(Line: 149, Col: 9): Unexpected symbol: '='. Located at position 43 within expression: inputs.device == 'tpu' && inputs.workflow = 'post-training' && needs.build_and_push.result == 'success' && needs.build_and_push.outputs.should_run == 'true'
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This workflow will build and push MaxText Docker image to GCR.
name: Build and Push MaxText Docker Images
on:
workflow_call:
inputs:
image_name:
required: true
type: string
device:
required: true
type: string
build_mode:
required: true
type: string
dockerfile:
required: true
type: string
maxtext_sha:
required: true
type: string
image_date:
required: false
type: string
workflow:
required: false
type: string
default: 'pre-training'
version_name:
required: false
type: string
default: ''
permissions:
contents: read
jobs:
build_and_push:
runs-on: linux-x86-n2-16-buildkit
container: google/cloud-sdk:524.0.0
if: >
github.event_name == 'release' ||
github.event_name == 'schedule' ||
github.event_name == 'pull_request' ||
github.event_name == 'workflow_dispatch' && (
github.event.inputs.target_device == 'all' ||
github.event.inputs.target_device == 'tpu' ||
github.event.inputs.target_device == 'gpu'
)
outputs:
should_run: ${{ steps.check.outputs.should_run }} # Map the step output to the job level
steps:
- name: Check if build should run
id: check
shell: bash
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${GITHUB_EVENT_INPUTS_TARGET_DEVICE}" != "all" && "${GITHUB_EVENT_INPUTS_TARGET_DEVICE}" != "${INPUTS_DEVICE}" ]]; then
echo "should_run=false" >> $GITHUB_OUTPUT
echo "Skipping ${INPUTS_IMAGE_NAME} build for device: ${INPUTS_DEVICE} in ${INPUTS_BUILD_MODE} mode."
else
echo "should_run=true" >> $GITHUB_OUTPUT
echo "Building ${INPUTS_IMAGE_NAME} for device: ${INPUTS_DEVICE} in ${INPUTS_BUILD_MODE} mode."
fi
env:
GITHUB_EVENT_INPUTS_TARGET_DEVICE: ${{ github.event.inputs.target_device }}
INPUTS_DEVICE: ${{ inputs.device }}
INPUTS_IMAGE_NAME: ${{ inputs.image_name }}
INPUTS_BUILD_MODE: ${{ inputs.build_mode }}
- name: Checkout MaxText
uses: actions/checkout@v5
if: steps.check.outputs.should_run == 'true'
with:
# This ensures that every job clones the exact same commit as "setup" job
ref: ${{ inputs.maxtext_sha }}
- name: Mark git repositories as safe
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
if: steps.check.outputs.should_run == 'true'
- name: Configure Docker
run: gcloud auth configure-docker us-docker.pkg.dev,gcr.io -q
if: steps.check.outputs.should_run == 'true'
- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v3.11.1
if: steps.check.outputs.should_run == 'true'
with:
driver: remote
endpoint: tcp://localhost:1234
- name: Build and push Docker image
uses: docker/build-push-action@v6
if: steps.check.outputs.should_run == 'true'
with:
push: true
context: .
file: ${{ inputs.dockerfile }}
tags: gcr.io/tpu-prod-env-multipod/${{ inputs.image_name }}:${{ github.run_id }}
cache-from: type=gha
outputs: type=image,compression=zstd,force-compression=true
build-args: |
DEVICE=${{ inputs.device }}
MODE=${{ inputs.build_mode }}
WORKFLOW=${{ inputs.workflow }}
PACKAGE_DIR=./src
JAX_VERSION=NONE
LIBTPU_VERSION=NONE
INCLUDE_TEST_ASSETS=true
test:
needs: build_and_push
if: |
needs.build_and_push.result == 'success' &&
needs.build_and_push.outputs.should_run == 'true'
strategy:
fail-fast: false
matrix:
flavor: >-
${{ fromJSON('{
"gpu-pre-training": ["gpu-unit", "gpu-integration"],
"tpu-post-training": ["post-training-tpu-unit", "post-training-tpu-integration", "post-training-cpu-unit"],
"tpu-pre-training": ["tpu-unit", "tpu-integration", "cpu-unit"]
}')[format('{0}-{1}', inputs.device, inputs.workflow)] }}
uses: ./.github/workflows/run_tests_coordinator.yml
with:
flavor: ${{ matrix.flavor }}
base_image: ${{ inputs.image_name }}:${{ github.run_id }}
is_scheduled_run: true
maxtext_installed: true
notebook-test:
needs: build_and_push
if: |
inputs.device == 'tpu' &&
inputs.workflow = 'post-training' &&
needs.build_and_push.result == 'success' &&
needs.build_and_push.outputs.should_run == 'true'
uses: ./.github/workflows/run_jupyter_notebooks.yml
with:
device_type: tpu
device_name: v6e-4
base_image: ${{ inputs.image_name }}:${{ github.run_id }}
cloud_runner: linux-x86-ct6e-180-4tpu
maxtext_installed: true
secrets:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
tagging:
needs: [test, notebook-test]
if: |
always() &&
needs.test.result == 'success' &&
(needs.notebook-test.result == 'success' || needs.notebook-test.result == 'skipped')
runs-on: linux-x86-n2-16-buildkit
container: google/cloud-sdk:524.0.0
steps:
- name: Configure Docker
run: gcloud auth configure-docker us-docker.pkg.dev,gcr.io -q
- name: Add tags to Docker image
shell: bash
run: |
SOURCE_IMAGE="gcr.io/tpu-prod-env-multipod/${INPUTS_IMAGE_NAME}"
TEMP_IMG="${SOURCE_IMAGE}:${{ github.run_id }}"
if [[ $INPUTS_VERSION_NAME ]]; then
echo "Tagging docker images corresponding to PyPI release..."
gcloud container images add-tag "${TEMP_IMG}" "${SOURCE_IMAGE}:${INPUTS_VERSION_NAME}" --quiet
else
echo "Tagging docker images corresponding to nightly release..."
# Add date tag
gcloud container images add-tag "${TEMP_IMG}" "$SOURCE_IMAGE:${INPUTS_IMAGE_DATE}" --quiet
# Convert date to YYYYMMDD format
clean_date=$(echo "${INPUTS_IMAGE_DATE}" | sed 's/[-:]//g' | cut -c1-8)
# Add MaxText tag
maxtext_hash=$(git rev-parse --short HEAD)
gcloud container images add-tag "${TEMP_IMG}" "${SOURCE_IMAGE}:maxtext_${maxtext_hash}_${clean_date}" --quiet
# Latest Tag
gcloud container images add-tag "${TEMP_IMG}" "${SOURCE_IMAGE}:latest" --quiet
env:
INPUTS_IMAGE_NAME: ${{ inputs.image_name }}
INPUTS_IMAGE_DATE: ${{ inputs.image_date }}
INPUTS_VERSION_NAME: ${{ inputs.version_name }}