Skip to content

Commit

Permalink
Merge pull request #21 from elezar/on-pr-images
Browse files Browse the repository at this point in the history
Build images on PR
  • Loading branch information
elezar authored Feb 20, 2025
2 parents 9567477 + 3afc51f commit 934ab31
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 34 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/basic-checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "basic checks"

on:
workflow_call:
outputs:
version:
description: "The short SHA to use as a version string"
value: ${{ jobs.variables.outputs.version }}
golang_version:
description: "The golang version for this project"
value: ${{ jobs.variables.outputs.golang_version }}
pull_request:
types:
- opened
- synchronize
branches:
- main
- release-*

jobs:
variables:
uses: ./.github/workflows/variables.yaml
35 changes: 35 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2025 NVIDIA CORPORATION
#
# 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
#
# http://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.

name: CI Pipeline

on:
push:
branches:
- "pull-request/[0-9]+"
- main
- release-*

jobs:
basic:
uses: ./.github/workflows/basic-checks.yaml

image:
uses: ./.github/workflows/image.yaml
needs:
- basic
secrets: inherit
with:
version: ${{ needs.basic.outputs.version }}
build_multi_arch_images: ${{ github.ref_name == 'main' || startsWith(github.ref_name, 'release-') }}
53 changes: 19 additions & 34 deletions .github/workflows/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,18 @@
name: Image

on:
pull_request:
types:
- opened
- synchronize
branches:
- main
- release-*
push:
branches:
- main
- release-*
workflow_call:
inputs:
version:
required: true
type: string
build_multi_arch_images:
required: true
type: string

jobs:
build:
runs-on: ubuntu-latest
runs-on: linux-amd64-cpu4
strategy:
matrix:
dist:
Expand All @@ -45,43 +42,31 @@ jobs:
sample: deviceQuery
- dist: ubi8
sample: nbody

steps:
- uses: actions/checkout@v4
name: Check out code
- name: Calculate build vars
id: vars
run: |
echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
echo "LOWERCASE_REPO_OWNER=$(echo "${GITHUB_REPOSITORY_OWNER}" | awk '{print tolower($0)}')" >> $GITHUB_ENV
REPO_FULL_NAME="${{ github.event.pull_request.head.repo.full_name }}"
echo "${REPO_FULL_NAME}"
echo "LABEL_IMAGE_SOURCE=https://github.com/${REPO_FULL_NAME}" >> $GITHUB_ENV

GENERATE_ARTIFACTS="false"
if [[ "${{ github.actor }}" == "dependabot[bot]" ]]; then
GENERATE_ARTIFACTS="false"
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]]; then
GENERATE_ARTIFACTS="true"
elif [[ "${{ github.event_name }}" == "push" ]]; then
GENERATE_ARTIFACTS="true"
fi
echo "PUSH_ON_BUILD=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV
echo "BUILD_MULTI_ARCH_IMAGES=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:master

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build image
env:
IMAGE_NAME: ghcr.io/${LOWERCASE_REPO_OWNER}/k8s-samples
VERSION: ${COMMIT_SHORT_SHA}
IMAGE_NAME: ghcr.io/nvidia/k8s-samples
VERSION: ${{ inputs.version }}
PUSH_ON_BUILD: true
BUILD_MULTI_ARCH_IMAGES: ${{ inputs.build_multi_arch_images }}
run: |
echo "${VERSION}"
echo "Building ${{ matrix.sample }} on ${{ matrix.dist }}"
SAMPLE=${{ matrix.sample }} make -f deployments/container/Makefile build-${{ matrix.dist }}
44 changes: 44 additions & 0 deletions .github/workflows/variables.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
#
# 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
#
# http://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.

on:
workflow_call:
outputs:
version:
description: "The short SHA to use as a version string"
value: ${{ jobs.variables.outputs.version }}
golang_version:
description: "The golang version for this project"
value: ${{ jobs.variables.outputs.golang_version }}

jobs:
variables:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
golang_version: ${{ steps.golang_version.outputs.golang_version }}
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Generate Commit Short SHA
id: version
run: echo "version=$(echo $GITHUB_SHA | cut -c1-8)" >> "$GITHUB_OUTPUT"

- name: Get Golang Version
id: golang_version
run: |
GOLANG_VERSION=$(./hack/golang-version.sh || echo "NOT_SUPPORTED")
echo "Detected $GOLANG_VERSION"
echo "golang_version=${GOLANG_VERSION}" >> $GITHUB_OUTPUT

0 comments on commit 934ab31

Please sign in to comment.