|
| 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 |
0 commit comments