Skip to content

Commit 8d883cb

Browse files
authored
Go and kpt setup moved into a reusable composite action (kptdev#479)
Signed-off-by: aravind.est <aravindhan.a@est.tech>
1 parent dfc9b83 commit 8d883cb

7 files changed

Lines changed: 80 additions & 51 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 2026 The Nephio Authors
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: "Setup Go and kpt"
16+
description: "Sets up Go from go.mod and installs kpt version matching go.mod"
17+
18+
inputs:
19+
install-kpt:
20+
description: "Whether to install kpt"
21+
required: false
22+
default: "true"
23+
kpt-fallback-version:
24+
description: "Fallback kpt version if extraction from go.mod fails"
25+
required: false
26+
default: "v1.0.0-beta.61.1"
27+
go-cache:
28+
description: "Enable Go module caching"
29+
required: false
30+
default: "true"
31+
32+
outputs:
33+
kpt-version:
34+
description: "The kpt version installed"
35+
value: ${{ steps.kpt-version.outputs.version }}
36+
37+
runs:
38+
using: "composite"
39+
steps:
40+
- name: Set up Go
41+
uses: actions/setup-go@v5
42+
with:
43+
go-version-file: go.mod
44+
cache: ${{ inputs.go-cache == 'true' }}
45+
46+
- name: Get kpt version from go.mod
47+
if: inputs.install-kpt == 'true'
48+
id: kpt-version
49+
shell: bash
50+
run: |
51+
KPT_VERSION=$(go list -m -f '{{.Version}}' github.com/kptdev/kpt 2>/dev/null)
52+
if [ -z "$KPT_VERSION" ]; then
53+
echo "Warning: Could not resolve kpt version from go.mod, using fallback"
54+
KPT_VERSION="${{ inputs.kpt-fallback-version }}"
55+
fi
56+
echo "version=${KPT_VERSION}" >> "$GITHUB_OUTPUT"
57+
58+
- name: Install kpt
59+
if: inputs.install-kpt == 'true'
60+
uses: jaxxstorm/action-install-gh-release@v2.1.0
61+
with:
62+
repo: kptdev/kpt
63+
tag: ${{ steps.kpt-version.outputs.version }}
64+
chmod: 0755

.github/workflows/golangci-lint.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ jobs:
4545
- name: Checkout Porch
4646
uses: actions/checkout@v4
4747
- name: Set up Go
48-
uses: actions/setup-go@v5
48+
uses: ./.github/actions/setup-go-kpt
4949
with:
50-
go-version-file: go.mod
50+
install-kpt: "false"
5151
- name: Run Linter
5252
run: make lint
5353

.github/workflows/gosec-scan.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ jobs:
4747
- name: Checkout Porch
4848
uses: actions/checkout@v4
4949
- name: Set up Go
50-
uses: actions/setup-go@v5
50+
uses: ./.github/actions/setup-go-kpt
5151
with:
52-
go-version-file: go.mod
52+
install-kpt: "false"
5353

5454
- name: Run Gosec Security Scanner
5555
run: make gosec-sarif

.github/workflows/porch-e2e-ci-jobs.yaml

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ jobs:
5858
- name: Checkout Porch
5959
uses: actions/checkout@v4
6060
- name: Set up Go
61-
uses: actions/setup-go@v5
61+
uses: ./.github/actions/setup-go-kpt
6262
with:
63-
go-version-file: go.mod
64-
cache: true
63+
install-kpt: "false"
64+
go-cache: "true"
6565
- name: Set variables
6666
id: vars
6767
run: |
@@ -144,26 +144,10 @@ jobs:
144144
steps:
145145
- name: Checkout Porch
146146
uses: actions/checkout@v4
147-
- name: Set up Go
148-
uses: actions/setup-go@v5
149-
with:
150-
go-version-file: go.mod
151-
cache: true
152-
- name: Get kpt version from go.mod
153-
id: kpt-version
154-
run: |
155-
KPT_VERSION=$(grep 'github.com/kptdev/kpt' go.mod | awk '{print $2}')
156-
if [ -z "$KPT_VERSION" ]; then
157-
echo "Warning: Could not extract kpt version from go.mod, using fallback"
158-
KPT_VERSION="v1.0.0-beta.59.2"
159-
fi
160-
echo "version=${KPT_VERSION}" >> $GITHUB_OUTPUT
161-
- name: Install kpt
162-
uses: jaxxstorm/action-install-gh-release@v2.1.0
147+
- name: Set up Go and kpt
148+
uses: ./.github/actions/setup-go-kpt
163149
with:
164-
repo: kptdev/kpt
165-
tag: ${{ steps.kpt-version.outputs.version }}
166-
chmod: 0755
150+
go-cache: "true"
167151
- name: Install Kind
168152
uses: helm/kind-action@v1
169153
with:

.github/workflows/porchctl-dev-release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ jobs:
3535
with:
3636
fetch-depth: 0
3737
- name: Set up Go
38-
uses: actions/setup-go@v5
38+
uses: ./.github/actions/setup-go-kpt
3939
with:
40-
go-version-file: go.mod
40+
install-kpt: "false"
4141
- name: Build
4242
run: make porchctl
4343
- name: Pack binary

.github/workflows/release.yaml

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,8 @@ jobs:
3535
with:
3636
fetch-depth: 0
3737

38-
- name: Set up Go
39-
uses: actions/setup-go@v5
40-
with:
41-
go-version-file: go.mod
42-
43-
- name: Get kpt version from go.mod
44-
id: kpt-version
45-
run: |
46-
KPT_VERSION=$(grep 'github.com/kptdev/kpt' go.mod | awk '{print $2}')
47-
if [ -z "$KPT_VERSION" ]; then
48-
echo "Warning: Could not extract kpt version from go.mod, using fallback"
49-
KPT_VERSION="v1.0.0-beta.61.1"
50-
fi
51-
echo "version=${KPT_VERSION}" >> "$GITHUB_OUTPUT"
52-
53-
- name: Install kpt
54-
uses: jaxxstorm/action-install-gh-release@v2.1.0
55-
with:
56-
repo: kptdev/kpt
57-
tag: ${{ steps.kpt-version.outputs.version }}
58-
chmod: 0755
38+
- name: Set up Go and kpt
39+
uses: ./.github/actions/setup-go-kpt
5940

6041
- name: Build porch blueprint
6142
run: PATH=./bin:$PATH IMAGE_REPO=docker.io/nephio IMAGE_TAG=${{ github.ref_name }} PORCH_CACHE_TYPE=CR make deployment-config

.github/workflows/sonar-ci-artifacts.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ jobs:
3333
fetch-depth: 0
3434

3535
- name: Set up Go
36-
uses: actions/setup-go@v5
36+
uses: ./.github/actions/setup-go-kpt
3737
with:
38-
go-version-file: go.mod
38+
install-kpt: "false"
3939

4040
- name: Run unit tests to generate coverage report
4141
id: test

0 commit comments

Comments
 (0)