1- # Copyright 2025 Google LLC
1+ # Copyright 2023-2026 Google LLC
22
33# Licensed under the Apache License, Version 2.0 (the "License");
44# you may not use this file except in compliance with the License.
3434 maxtext_sha :
3535 required : true
3636 type : string
37- image_date :
38- required : false
39- type : string
4037 workflow :
4138 required : false
4239 type : string
4542 required : false
4643 type : string
4744 default : ' '
45+ include_test_assets :
46+ required : false
47+ type : boolean
48+ default : false
4849 secrets :
4950 HF_TOKEN :
5051 required : true
@@ -53,36 +54,42 @@ permissions:
5354 contents : read
5455
5556jobs :
56- build_and_push :
57- runs-on : linux-x86-n2-16-buildkit
58- container : google/cloud-sdk:524.0.0
59- if : >
60- github.event_name == 'release' ||
61- github.event_name == 'schedule' ||
62- github.event_name == 'pull_request' ||
63- github.event_name == 'workflow_dispatch' && (
64- github.event.inputs.target_device == 'all' ||
65- github.event.inputs.target_device == 'tpu' ||
66- github.event.inputs.target_device == 'gpu'
67- )
57+ pre_build_check :
58+ runs-on : ubuntu-latest
59+ outputs :
60+ should_run : ${{ steps.check.outputs.should_run }}
6861 steps :
6962 - name : Check if build should run
7063 id : check
7164 shell : bash
7265 run : |
73- if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${GITHUB_EVENT_INPUTS_TARGET_DEVICE}" != "all" && "${GITHUB_EVENT_INPUTS_TARGET_DEVICE}" != "${INPUTS_DEVICE}" ]]; then
74- echo "should_run=false" >> $GITHUB_OUTPUT
75- echo "Skipping ${INPUTS_IMAGE_NAME} build for device: ${INPUTS_DEVICE} in ${INPUTS_BUILD_MODE} mode."
76- else
66+ EVENT_NAME="${{ github.event_name }}"
67+ TARGET_DEVICE="${{ github.event.inputs.target_device }}"
68+ INPUT_DEVICE="${{ inputs.device }}"
69+
70+ SHOULD_RUN="false"
71+ if [[ "$EVENT_NAME" == "release" || "$EVENT_NAME" == "schedule" || "$EVENT_NAME" == "pull_request" ]]; then
72+ SHOULD_RUN="true"
73+ elif [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
74+ if [[ "$TARGET_DEVICE" == "all" || "$TARGET_DEVICE" == "$INPUT_DEVICE" ]]; then
75+ SHOULD_RUN="true"
76+ fi
77+ fi
78+
79+ if [[ "$SHOULD_RUN" == "true" ]]; then
7780 echo "should_run=true" >> $GITHUB_OUTPUT
78- echo "Building ${INPUTS_IMAGE_NAME} for device: ${INPUTS_DEVICE} in ${INPUTS_BUILD_MODE} mode."
81+ echo "Building ${{ inputs.image_name }} for device: ${{ inputs.device }} in ${{ inputs.build_mode }} mode."
82+ else
83+ echo "should_run=false" >> $GITHUB_OUTPUT
84+ echo "Skipping ${{ inputs.image_name }} build for device: ${{ inputs.device }} in ${{ inputs.build_mode }} mode."
7985 fi
80- env :
81- GITHUB_EVENT_INPUTS_TARGET_DEVICE : ${{ github.event.inputs.target_device }}
82- INPUTS_DEVICE : ${{ inputs.device }}
83- INPUTS_IMAGE_NAME : ${{ inputs.image_name }}
84- INPUTS_BUILD_MODE : ${{ inputs.build_mode }}
8586
87+ build_and_push :
88+ needs : pre_build_check
89+ runs-on : linux-x86-n2-16-buildkit
90+ container : google/cloud-sdk:524.0.0
91+ if : needs.pre_build_check.outputs.should_run == 'true'
92+ steps :
8693 - name : Matrix Debugger
8794 run : |
8895 echo "device: ${{ inputs.device }}"
@@ -93,50 +100,68 @@ jobs:
93100
94101 - name : Checkout MaxText
95102 uses : actions/checkout@v5
96- if : steps.check.outputs.should_run == 'true'
97103 with :
98- # This ensures that every job clones the exact same commit as "setup" job
99104 ref : ${{ inputs.maxtext_sha }}
100105
101106 - name : Mark git repositories as safe
102107 run : git config --global --add safe.directory ${GITHUB_WORKSPACE}
103- if : steps.check.outputs.should_run == 'true'
104108
105109 - name : Configure Docker
106110 run : gcloud auth configure-docker us-docker.pkg.dev,gcr.io -q
107- if : steps.check.outputs.should_run == 'true'
108111
109112 - name : Set up Docker BuildX
110113 uses : docker/setup-buildx-action@v3.11.1
111- if : steps.check.outputs.should_run == 'true'
112114 with :
113115 driver : remote
114116 endpoint : tcp://localhost:1234
115117
118+ - name : Download MaxText wheel
119+ uses : actions/download-artifact@v4
120+ with :
121+ name : maxtext-wheel
122+
123+ - name : Install uv and set Python version
124+ uses : astral-sh/setup-uv@v7
125+ with :
126+ python-version : ' 3.12'
127+ enable-cache : true
128+
129+ - name : Install MaxText wheel
130+ shell : bash
131+ run : |
132+ uv venv --seed
133+ source .venv/bin/activate
134+ maxtext_wheel=$(ls maxtext-*-py3-none-any.whl 2>/dev/null)
135+ uv pip install ${maxtext_wheel}[runner] --resolution=lowest
136+
137+ - name : Copy tests assets to package directory
138+ if : inputs.include_test_assets == true
139+ shell : bash
140+ run : |
141+ source .venv/bin/activate
142+ cp -r ${PWD}/tests .venv/lib/python3.12/site-packages/
143+ cp ${PWD}/pytest.ini .venv/lib/python3.12/site-packages/
144+
116145 - name : Build and push Docker image
117146 uses : docker/build-push-action@v6
118- if : steps.check.outputs.should_run == 'true'
119147 with :
120148 push : true
121149 context : .
122- file : ${{ inputs.dockerfile }}
123- tags : gcr.io/tpu-prod-env-multipod /${{ inputs.image_name }}:${{ github.run_id }}
150+ file : .venv/lib/python3.12/site-packages/dependencies/dockerfiles/ ${{ inputs.dockerfile }}
151+ tags : gcr.io/${{ vars.PROJECT_NAME }} /${{ inputs.image_name }}:${{ github.run_id }}
124152 cache-from : type=gha
125153 outputs : type=image,compression=zstd,force-compression=true
126154 build-args : |
127155 DEVICE=${{ inputs.device }}
128156 MODE=${{ inputs.build_mode }}
129157 WORKFLOW=${{ inputs.workflow }}
130- PACKAGE_DIR=./src
131- JAX_VERSION=NONE
132- LIBTPU_VERSION=NONE
133- INCLUDE_TEST_ASSETS=true
158+ PACKAGE_DIR=.venv/lib/python3.12/site-packages
159+ INCLUDE_TEST_ASSETS=${{ inputs.include_test_assets }}
134160
135161 - name : Add tags to Docker image
136- if : steps.check.outputs.should_run == 'true'
137162 shell : bash
138163 run : |
139- SOURCE_IMAGE="gcr.io/tpu-prod-env-multipod /${INPUTS_IMAGE_NAME}"
164+ SOURCE_IMAGE="gcr.io/${{ vars.PROJECT_NAME }} /${INPUTS_IMAGE_NAME}"
140165 TEMP_IMG="${SOURCE_IMAGE}:${{ github.run_id }}"
141166
142167 if [[ $INPUTS_VERSION_NAME ]]; then
@@ -146,16 +171,26 @@ jobs:
146171 echo "Tagging docker images corresponding to nightly release..."
147172
148173 # Add date tag
149- gcloud container images add-tag "${TEMP_IMG}" "$SOURCE_IMAGE:${INPUTS_IMAGE_DATE}" --quiet
174+ IMAGE_DATE="$(date +%Y-%m-%d)"
175+ gcloud container images add-tag "${TEMP_IMG}" "$SOURCE_IMAGE:$IMAGE_DATE" --quiet
150176
151177 # Convert date to YYYYMMDD format
152- clean_date=$(echo "${INPUTS_IMAGE_DATE} " | sed 's/[-:]//g' | cut -c1-8)
178+ clean_date=$(echo "$IMAGE_DATE " | sed 's/[-:]//g' | cut -c1-8)
153179
154180 # Add MaxText tag
181+ MAXTEXT_SHA=$(git rev-parse --short HEAD)
155182 gcloud container images add-tag "${TEMP_IMG}" "${SOURCE_IMAGE}:maxtext_${MAXTEXT_SHA}_${clean_date}" --quiet
156183 fi
157184 env :
158185 INPUTS_IMAGE_NAME : ${{ inputs.image_name }}
159- INPUTS_IMAGE_DATE : ${{ inputs.image_date }}
160186 INPUTS_VERSION_NAME : ${{ inputs.version_name }}
161- MAXTEXT_SHA : ${{ inputs.maxtext_sha }}
187+
188+ promote_image :
189+ needs : [pre_build_check, build_and_push]
190+ if : needs.pre_build_check.outputs.should_run == 'true' && inputs.include_test_assets == true
191+ uses : ./.github/workflows/promote_docker_image.yml
192+ with :
193+ image_name : ${{ inputs.image_name }}
194+ image_tag : ${{ github.run_id }}
195+ device : ${{ inputs.device }}
196+ workflow : ${{ inputs.workflow }}
0 commit comments