Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/actions/check-go-mod-replace/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2026 The kpt Authors
#
# 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: Check go.mod replace directives
description: >
Fails if the go.mod in the specified directory contains active replace
directives that are not in the allowed list.

inputs:
working-directory:
description: Directory containing the go.mod to check.
required: false
default: "."
allowed-replacements:
description: >
JSON array of module paths that are allowed to have replace directives.
Example: '["k8s.io/apiserver", "sigs.k8s.io/kustomize/kyaml"]'
required: false
default: "[]"

runs:
using: composite
steps:
- name: Check for replace directives
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
ALLOWED='${{ inputs.allowed-replacements }}'
UNEXPECTED=$(go mod edit -json | jq --argjson allowed "$ALLOWED" \
'[(.Replace // [])[] | select(.Old.Path as $p | $allowed | index($p) | not)]')
COUNT=$(echo "$UNEXPECTED" | jq 'length')
if [ "$COUNT" -gt 0 ]; then
echo "::error::$(pwd)/go.mod contains unexpected replace directives. Remove them before releasing."
echo "$UNEXPECTED" | jq .
exit 1
fi
4 changes: 4 additions & 0 deletions .github/workflows/release-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jobs:
with:
go-version-file: api/go.mod
cache-dependency-path: api/go.sum
- name: Check for replace directives in api/go.mod
uses: ./.github/actions/check-go-mod-replace
with:
working-directory: api
- name: Build, test, lint (api module)
run: |
git config --global user.email you@example.com
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Check for replace directives in go.mod
uses: ./.github/actions/check-go-mod-replace
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
Expand Down