Skip to content

Commit 934ab31

Browse files
authored
Merge pull request #21 from elezar/on-pr-images
Build images on PR
2 parents 9567477 + 3afc51f commit 934ab31

File tree

4 files changed

+120
-34
lines changed

4 files changed

+120
-34
lines changed

.github/workflows/basic-checks.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: "basic checks"
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
version:
7+
description: "The short SHA to use as a version string"
8+
value: ${{ jobs.variables.outputs.version }}
9+
golang_version:
10+
description: "The golang version for this project"
11+
value: ${{ jobs.variables.outputs.golang_version }}
12+
pull_request:
13+
types:
14+
- opened
15+
- synchronize
16+
branches:
17+
- main
18+
- release-*
19+
20+
jobs:
21+
variables:
22+
uses: ./.github/workflows/variables.yaml

.github/workflows/ci.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
name: CI Pipeline
16+
17+
on:
18+
push:
19+
branches:
20+
- "pull-request/[0-9]+"
21+
- main
22+
- release-*
23+
24+
jobs:
25+
basic:
26+
uses: ./.github/workflows/basic-checks.yaml
27+
28+
image:
29+
uses: ./.github/workflows/image.yaml
30+
needs:
31+
- basic
32+
secrets: inherit
33+
with:
34+
version: ${{ needs.basic.outputs.version }}
35+
build_multi_arch_images: ${{ github.ref_name == 'main' || startsWith(github.ref_name, 'release-') }}

.github/workflows/image.yaml

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,18 @@
1616
name: Image
1717

1818
on:
19-
pull_request:
20-
types:
21-
- opened
22-
- synchronize
23-
branches:
24-
- main
25-
- release-*
26-
push:
27-
branches:
28-
- main
29-
- release-*
19+
workflow_call:
20+
inputs:
21+
version:
22+
required: true
23+
type: string
24+
build_multi_arch_images:
25+
required: true
26+
type: string
3027

3128
jobs:
3229
build:
33-
runs-on: ubuntu-latest
30+
runs-on: linux-amd64-cpu4
3431
strategy:
3532
matrix:
3633
dist:
@@ -45,43 +42,31 @@ jobs:
4542
sample: deviceQuery
4643
- dist: ubi8
4744
sample: nbody
48-
4945
steps:
5046
- uses: actions/checkout@v4
5147
name: Check out code
52-
- name: Calculate build vars
53-
id: vars
54-
run: |
55-
echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
56-
echo "LOWERCASE_REPO_OWNER=$(echo "${GITHUB_REPOSITORY_OWNER}" | awk '{print tolower($0)}')" >> $GITHUB_ENV
57-
REPO_FULL_NAME="${{ github.event.pull_request.head.repo.full_name }}"
58-
echo "${REPO_FULL_NAME}"
59-
echo "LABEL_IMAGE_SOURCE=https://github.com/${REPO_FULL_NAME}" >> $GITHUB_ENV
6048

61-
GENERATE_ARTIFACTS="false"
62-
if [[ "${{ github.actor }}" == "dependabot[bot]" ]]; then
63-
GENERATE_ARTIFACTS="false"
64-
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]]; then
65-
GENERATE_ARTIFACTS="true"
66-
elif [[ "${{ github.event_name }}" == "push" ]]; then
67-
GENERATE_ARTIFACTS="true"
68-
fi
69-
echo "PUSH_ON_BUILD=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV
70-
echo "BUILD_MULTI_ARCH_IMAGES=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV
7149
- name: Set up QEMU
7250
uses: docker/setup-qemu-action@v3
51+
with:
52+
image: tonistiigi/binfmt:master
53+
7354
- name: Set up Docker Buildx
7455
uses: docker/setup-buildx-action@v3
56+
7557
- name: Login to GitHub Container Registry
7658
uses: docker/login-action@v3
7759
with:
7860
registry: ghcr.io
7961
username: ${{ github.actor }}
8062
password: ${{ secrets.GITHUB_TOKEN }}
63+
8164
- name: Build image
8265
env:
83-
IMAGE_NAME: ghcr.io/${LOWERCASE_REPO_OWNER}/k8s-samples
84-
VERSION: ${COMMIT_SHORT_SHA}
66+
IMAGE_NAME: ghcr.io/nvidia/k8s-samples
67+
VERSION: ${{ inputs.version }}
68+
PUSH_ON_BUILD: true
69+
BUILD_MULTI_ARCH_IMAGES: ${{ inputs.build_multi_arch_images }}
8570
run: |
86-
echo "${VERSION}"
71+
echo "Building ${{ matrix.sample }} on ${{ matrix.dist }}"
8772
SAMPLE=${{ matrix.sample }} make -f deployments/container/Makefile build-${{ matrix.dist }}

.github/workflows/variables.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
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+
version:
19+
description: "The short SHA to use as a version string"
20+
value: ${{ jobs.variables.outputs.version }}
21+
golang_version:
22+
description: "The golang version for this project"
23+
value: ${{ jobs.variables.outputs.golang_version }}
24+
25+
jobs:
26+
variables:
27+
runs-on: ubuntu-latest
28+
outputs:
29+
version: ${{ steps.version.outputs.version }}
30+
golang_version: ${{ steps.golang_version.outputs.golang_version }}
31+
steps:
32+
- name: Check out code
33+
uses: actions/checkout@v4
34+
35+
- name: Generate Commit Short SHA
36+
id: version
37+
run: echo "version=$(echo $GITHUB_SHA | cut -c1-8)" >> "$GITHUB_OUTPUT"
38+
39+
- name: Get Golang Version
40+
id: golang_version
41+
run: |
42+
GOLANG_VERSION=$(./hack/golang-version.sh || echo "NOT_SUPPORTED")
43+
echo "Detected $GOLANG_VERSION"
44+
echo "golang_version=${GOLANG_VERSION}" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)