Skip to content

Commit 965ca2d

Browse files
[no-relnotes] Use reusable workflows for CI
This commit introduces the following changes to the CI structure. A more agressive split of the CI steps to reusable workflows. We now have the following high-level workflows: - A set of basic checks that are run on PR and can be invoked from a workflow - A full ci pipeline that is run on push to main and release-* branches (as well as PR copy bot branches) - A standalone definition for CodeQL Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent 8945a29 commit 965ca2d

File tree

7 files changed

+219
-65
lines changed

7 files changed

+219
-65
lines changed

.github/workflows/basic-checks.yaml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
name: "basic checks"
15+
16+
on:
17+
workflow_call:
18+
outputs:
19+
version:
20+
description: "The short SHA to use as a version string"
21+
value: ${{ jobs.variables.outputs.version }}
22+
golang_version:
23+
description: "The golang version for this project"
24+
value: ${{ jobs.variables.outputs.golang_version }}
25+
pull_request:
26+
types:
27+
- opened
28+
- synchronize
29+
branches:
30+
- main
31+
- release-*
32+
33+
jobs:
34+
variables:
35+
uses: ./.github/workflows/variables.yaml
36+
37+
golang:
38+
needs:
39+
- variables
40+
uses: ./.github/workflows/golang.yaml
41+
with:
42+
golang_version: ${{ needs.variables.outputs.golang_version }}
43+
44+
code-scanning:
45+
needs:
46+
- variables
47+
uses: ./.github/workflows/code_scanning.yaml
48+
with:
49+
golang_version: ${{ needs.variables.outputs.golang_version }}

.github/workflows/ci.yaml

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

.github/workflows/code_scanning.yaml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
name: "CodeQL"
15+
16+
on:
17+
workflow_call:
18+
inputs:
19+
golang_version:
20+
required: true
21+
type: string
22+
23+
jobs:
24+
analyze:
25+
name: Analyze Go code with CodeQL
26+
runs-on: ubuntu-latest
27+
timeout-minutes: 360
28+
permissions:
29+
security-events: write
30+
packages: read
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
35+
- name: Install Go
36+
uses: actions/setup-go@v5
37+
with:
38+
go-version: ${{ inputs.golang_version }}
39+
40+
- name: Initialize CodeQL
41+
uses: github/codeql-action/init@v3
42+
with:
43+
languages: go
44+
build-mode: manual
45+
46+
- shell: bash
47+
run: |
48+
make build
49+
50+
- name: Perform CodeQL Analysis
51+
uses: github/codeql-action/analyze@v3
52+
with:
53+
category: "/language:go"

.github/workflows/golang.yaml

+25-41
Original file line numberDiff line numberDiff line change
@@ -15,72 +15,56 @@
1515
name: Golang
1616

1717
on:
18-
pull_request:
19-
types:
20-
- opened
21-
- synchronize
22-
branches:
23-
- main
24-
- release-*
25-
push:
26-
branches:
27-
- main
28-
- release-*
18+
workflow_call:
19+
inputs:
20+
golang_version:
21+
required: true
22+
type: string
2923

3024
jobs:
3125
check:
3226
runs-on: ubuntu-latest
3327
steps:
3428
- uses: actions/checkout@v4
3529
name: Checkout code
36-
- name: Get Golang version
37-
id: vars
38-
run: |
39-
GOLANG_VERSION=$(./hack/golang-version.sh)
40-
echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION := }" >> $GITHUB_ENV
30+
4131
- name: Install Go
4232
uses: actions/setup-go@v5
4333
with:
44-
go-version: ${{ env.GOLANG_VERSION }}
34+
go-version: ${{ inputs.golang_versions }}
35+
4536
- name: Lint
4637
uses: golangci/golangci-lint-action@v6
4738
with:
4839
version: latest
4940
args: -v --timeout 5m
5041
skip-cache: true
42+
5143
- name: Check golang modules
5244
run: |
5345
make check-modules
5446
make -C deployments/devel check-modules
47+
5548
test:
5649
name: Unit test
5750
runs-on: ubuntu-latest
5851
steps:
59-
- name: Checkout code
60-
uses: actions/checkout@v4
61-
- name: Get Golang version
62-
id: vars
63-
run: |
64-
GOLANG_VERSION=$(./hack/golang-version.sh)
65-
echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION ?= }" >> $GITHUB_ENV
66-
- name: Install Go
67-
uses: actions/setup-go@v5
68-
with:
69-
go-version: ${{ env.GOLANG_VERSION }}
70-
- run: make test
52+
- name: Checkout code
53+
uses: actions/checkout@v4
54+
- name: Install Go
55+
uses: actions/setup-go@v5
56+
with:
57+
go-version: ${{ inputs.golang_version }}
58+
- run: make test
59+
7160
build:
7261
name: Build
7362
runs-on: ubuntu-latest
7463
steps:
75-
- name: Checkout code
76-
uses: actions/checkout@v4
77-
- name: Get Golang version
78-
id: vars
79-
run: |
80-
GOLANG_VERSION=$(./hack/golang-version.sh)
81-
echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION ?= }" >> $GITHUB_ENV
82-
- name: Install Go
83-
uses: actions/setup-go@v5
84-
with:
85-
go-version: ${{ env.GOLANG_VERSION }}
86-
- run: make build
64+
- name: Checkout code
65+
uses: actions/checkout@v4
66+
- name: Install Go
67+
uses: actions/setup-go@v5
68+
with:
69+
go-version: ${{ inputs.golang_version }}
70+
- run: make build

.github/workflows/image.yaml

+14-23
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,25 @@
1616
name: Image
1717

1818
on:
19-
push:
20-
branches:
21-
- "pull-request/[0-9]+"
22-
- main
23-
- 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
2427

2528
jobs:
2629
build:
2730
runs-on: linux-amd64-cpu4
2831
steps:
2932
- uses: actions/checkout@v4
3033
name: Check out code
31-
- name: Calculate build vars
32-
id: vars
33-
run: |
34-
echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
35-
echo "LOWERCASE_REPO_OWNER=$(echo "${GITHUB_REPOSITORY_OWNER}" | awk '{print tolower($0)}')" >> $GITHUB_ENV
36-
37-
GENERATE_ARTIFACTS="false"
38-
if [[ "${{ github.actor }}" == "dependabot[bot]" ]]; then
39-
GENERATE_ARTIFACTS="false"
40-
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]]; then
41-
GENERATE_ARTIFACTS="true"
42-
elif [[ "${{ github.event_name }}" == "push" ]]; then
43-
GENERATE_ARTIFACTS="true"
44-
fi
45-
echo "PUSH_ON_BUILD=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV
46-
echo "BUILD_MULTI_ARCH_IMAGES=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV
4734
- name: Set up QEMU
4835
uses: docker/setup-qemu-action@v3
36+
with:
37+
image: tonistiigi/binfmt:master
4938
- name: Set up Docker Buildx
5039
uses: docker/setup-buildx-action@v3
5140
- name: Login to GitHub Container Registry
@@ -56,8 +45,10 @@ jobs:
5645
password: ${{ secrets.GITHUB_TOKEN }}
5746
- name: Build image
5847
env:
59-
IMAGE_NAME: ghcr.io/${LOWERCASE_REPO_OWNER}/k8s-dra-driver
60-
VERSION: ${COMMIT_SHORT_SHA}
48+
IMAGE_NAME: ghcr.io/nvidia/k8s-dra-driver
49+
VERSION: ${{ inputs.version }}
50+
PUSH_ON_BUILD: true
51+
BUILD_MULTI_ARCH_IMAGES: ${{ inputs.build_multi_arch_images }}
6152
run: |
6253
echo "${VERSION}"
6354
make -f deployments/container/Makefile build

.github/workflows/variables.yaml

+44
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)
43+
echo "Detected $GOLANG_VERSION"
44+
echo "golang_version=${GOLANG_VERSION}" >> $GITHUB_OUTPUT

deployments/devel/Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ RUN make install-tools
2424
# We need to set the /work directory as a safe directory.
2525
# This allows git commands to run in the container.
2626
RUN git config --file=/.gitconfig --add safe.directory /work
27-

0 commit comments

Comments
 (0)