|
| 1 | +# Copyright 2025 NVIDIA CORPORATION |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +on: |
| 16 | + workflow_call: |
| 17 | + outputs: |
| 18 | + commit_short_sha: |
| 19 | + description: "The short SHA to use as a version string" |
| 20 | + value: ${{ jobs.variables.outputs.commit_short_sha }} |
| 21 | + repo_full_name: |
| 22 | + description: "The full repository name" |
| 23 | + value: ${{ jobs.variables.outputs.repo_full_name }} |
| 24 | + label_image_source: |
| 25 | + description: "The image source label URL" |
| 26 | + value: ${{ jobs.variables.outputs.label_image_source }} |
| 27 | + push_on_build: |
| 28 | + description: "Whether to push images on build" |
| 29 | + value: ${{ jobs.variables.outputs.push_on_build }} |
| 30 | + operator_image_base: |
| 31 | + description: "The base operator image name" |
| 32 | + value: ${{ jobs.variables.outputs.operator_image_base }} |
| 33 | + operator_version: |
| 34 | + description: "The operator version" |
| 35 | + value: ${{ jobs.variables.outputs.operator_version }} |
| 36 | + |
| 37 | +jobs: |
| 38 | + variables: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + outputs: |
| 41 | + commit_short_sha: ${{ steps.vars.outputs.commit_short_sha }} |
| 42 | + repo_full_name: ${{ steps.vars.outputs.repo_full_name }} |
| 43 | + label_image_source: ${{ steps.vars.outputs.label_image_source }} |
| 44 | + push_on_build: ${{ steps.vars.outputs.push_on_build }} |
| 45 | + operator_image_base: ${{ steps.vars.outputs.operator_image_base }} |
| 46 | + operator_version: ${{ steps.vars.outputs.operator_version }} |
| 47 | + steps: |
| 48 | + - name: Checkout code |
| 49 | + uses: actions/checkout@v5 |
| 50 | + |
| 51 | + - name: Calculate all variables |
| 52 | + id: vars |
| 53 | + run: | |
| 54 | + # Basic computed values |
| 55 | + COMMIT_SHORT_SHA="${GITHUB_SHA:0:8}" |
| 56 | + |
| 57 | + # Repository information |
| 58 | + REPO_FULL_NAME="${{ github.event.pull_request.head.repo.full_name }}" |
| 59 | + if [[ -z "${REPO_FULL_NAME}" ]]; then |
| 60 | + REPO_FULL_NAME="${{ github.repository }}" |
| 61 | + fi |
| 62 | + LABEL_IMAGE_SOURCE="https://github.com/${REPO_FULL_NAME}" |
| 63 | + |
| 64 | + # Determine if we should push images |
| 65 | + PUSH_ON_BUILD="false" |
| 66 | + if [[ "${{ github.actor }}" != "dependabot[bot]" ]]; then |
| 67 | + if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]]; then |
| 68 | + PUSH_ON_BUILD="true" |
| 69 | + elif [[ "${{ github.event_name }}" == "push" ]]; then |
| 70 | + PUSH_ON_BUILD="true" |
| 71 | + elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then |
| 72 | + PUSH_ON_BUILD="true" |
| 73 | + fi |
| 74 | + fi |
| 75 | + |
| 76 | + # Image and version information |
| 77 | + OPERATOR_IMAGE_BASE="ghcr.io/nvidia/gpu-operator" |
| 78 | + OPERATOR_VERSION="${COMMIT_SHORT_SHA}" |
| 79 | + |
| 80 | + # Output all variables |
| 81 | + echo "commit_short_sha=${COMMIT_SHORT_SHA}" >> $GITHUB_OUTPUT |
| 82 | + echo "repo_full_name=${REPO_FULL_NAME}" >> $GITHUB_OUTPUT |
| 83 | + echo "label_image_source=${LABEL_IMAGE_SOURCE}" >> $GITHUB_OUTPUT |
| 84 | + echo "push_on_build=${PUSH_ON_BUILD}" >> $GITHUB_OUTPUT |
| 85 | + echo "operator_image_base=${OPERATOR_IMAGE_BASE}" >> $GITHUB_OUTPUT |
| 86 | + echo "operator_version=${OPERATOR_VERSION}" >> $GITHUB_OUTPUT |
| 87 | + |
| 88 | + # Display for debugging |
| 89 | + echo "::notice::Commit SHA: ${COMMIT_SHORT_SHA}" |
| 90 | + echo "::notice::Push on build: ${PUSH_ON_BUILD}" |
| 91 | + echo "::notice::Operator image: ${OPERATOR_IMAGE_BASE}:${OPERATOR_VERSION}" |
| 92 | +
|
0 commit comments