|
| 1 | +# Copyright 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 | +name: Publish Helm OCI Chart |
| 16 | + |
| 17 | +on: |
| 18 | + workflow_call: |
| 19 | + inputs: |
| 20 | + operator_image: |
| 21 | + required: true |
| 22 | + type: string |
| 23 | + operator_version: |
| 24 | + required: true |
| 25 | + type: string |
| 26 | + |
| 27 | +permissions: |
| 28 | + contents: read |
| 29 | + packages: write |
| 30 | + |
| 31 | +concurrency: |
| 32 | + group: publish-helm-oci-chart-${{ inputs.operator_version }} |
| 33 | + cancel-in-progress: false |
| 34 | + |
| 35 | +jobs: |
| 36 | + publish-helm-chart: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + timeout-minutes: 10 |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v6 |
| 41 | + name: Check out code |
| 42 | + |
| 43 | + - name: Set up Helm |
| 44 | + uses: azure/setup-helm@v5.0.0 |
| 45 | + |
| 46 | + - name: Set chart image repository |
| 47 | + env: |
| 48 | + OPERATOR_IMAGE: ${{ inputs.operator_image }} |
| 49 | + run: echo "OPERATOR_REPOSITORY=${OPERATOR_IMAGE%/*}" >> "${GITHUB_ENV}" |
| 50 | + |
| 51 | + - name: Update chart image repository |
| 52 | + uses: mikefarah/yq@v4 |
| 53 | + with: |
| 54 | + cmd: yq -i '.operator.repository = env(OPERATOR_REPOSITORY) | .validator.repository = env(OPERATOR_REPOSITORY)' deployments/gpu-operator/values.yaml |
| 55 | + |
| 56 | + - name: Login to GitHub Container Registry |
| 57 | + env: |
| 58 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + run: echo "${GH_TOKEN}" | helm registry login ghcr.io -u "${GITHUB_ACTOR}" --password-stdin |
| 60 | + |
| 61 | + - name: Package Helm chart |
| 62 | + id: package |
| 63 | + env: |
| 64 | + OPERATOR_VERSION: ${{ inputs.operator_version }} |
| 65 | + run: | |
| 66 | + set -euo pipefail |
| 67 | +
|
| 68 | + # Helm chart versions must be SemVer. Prefix the image version so a |
| 69 | + # numeric short SHA with a leading zero remains a valid prerelease. |
| 70 | + CHART_VERSION="0.0.0-git-${OPERATOR_VERSION}" |
| 71 | +
|
| 72 | + mkdir -p dist |
| 73 | + helm lint deployments/gpu-operator |
| 74 | + helm package \ |
| 75 | + --version "${CHART_VERSION}" \ |
| 76 | + --app-version "${OPERATOR_VERSION}" \ |
| 77 | + --destination dist \ |
| 78 | + deployments/gpu-operator |
| 79 | +
|
| 80 | + CHART_PACKAGE="$(find dist -maxdepth 1 -type f -name 'gpu-operator-*.tgz' | head -n 1)" |
| 81 | + if [[ -z "${CHART_PACKAGE}" ]]; then |
| 82 | + echo "::error::Helm chart package was not created" |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | +
|
| 86 | + echo "chart_package=${CHART_PACKAGE}" >> "${GITHUB_OUTPUT}" |
| 87 | + echo "chart_version=${CHART_VERSION}" >> "${GITHUB_OUTPUT}" |
| 88 | +
|
| 89 | + - name: Publish Helm OCI chart |
| 90 | + env: |
| 91 | + GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} |
| 92 | + CHART_PACKAGE: ${{ steps.package.outputs.chart_package }} |
| 93 | + CHART_VERSION: ${{ steps.package.outputs.chart_version }} |
| 94 | + run: | |
| 95 | + set -euo pipefail |
| 96 | +
|
| 97 | + LOWERCASE_REPO_OWNER=$(echo "${GITHUB_REPOSITORY_OWNER}" | awk '{print tolower($0)}') |
| 98 | + CHART_REPOSITORY="oci://ghcr.io/${LOWERCASE_REPO_OWNER}/gpu-operator/charts" |
| 99 | +
|
| 100 | + helm push "${CHART_PACKAGE}" "${CHART_REPOSITORY}" |
| 101 | + echo "::notice::Published Helm chart to ${CHART_REPOSITORY}/gpu-operator:${CHART_VERSION}" |
0 commit comments