Skip to content
Draft
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
30 changes: 29 additions & 1 deletion .github/actions/check-go-mod-replace/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,31 @@
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.
directives that are not in the allowed list, or requires one of the given
modules at a pseudo-version (commit date and hash instead of a tag).

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: "[]"

tagged-only-modules:
description: >
JSON array of module paths that must be required at tagged versions, not
pseudo-versions. Submodules (path/...) are included. Pseudo-versions of
other modules are allowed.
Example: '["github.com/kptdev/kpt"]'
required: false
default: "[]"

runs:
using: composite
steps:
Expand All @@ -45,3 +56,20 @@ runs:
echo "$UNEXPECTED" | jq .
exit 1
fi

- name: Check for pseudo-versions
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
TAGGED_ONLY='${{ inputs.tagged-only-modules }}'
# Pseudo-versions end in a 14 digit UTC timestamp and a 12 character commit hash.
PSEUDO=$(go mod edit -json | jq --argjson modules "$TAGGED_ONLY" \
'[(.Require // [])[]
| select(.Path as $p | $modules | any(. as $m | $p == $m or ($p | startswith($m + "/"))))
| select(.Version | test("[-.][0-9]{14}-[0-9a-f]{12}$"))]')
COUNT=$(echo "$PSEUDO" | jq 'length')
if [ "$COUNT" -gt 0 ]; then
echo "::error::$(pwd)/go.mod requires modules at pseudo-versions. Use tagged versions before releasing."
echo "$PSEUDO" | jq .
exit 1
fi
2 changes: 2 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ jobs:
run: make fix vet fmt lint
- name: Test with Coverage
run: make test-coverage
- name: Script Tests
run: make test-scripts
- name: Docker Runtime Tests
run: make test-docker
env:
Expand Down
43 changes: 0 additions & 43 deletions .github/workflows/release-api.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,57 @@
# See the License for the specific language governing permissions and
# limitations under the License.

name: kpt CLI release
# Generates SLSA provenance for the assets of the release created by release.yml.
# The recorded revision is the commit of the cli/vX.Y.Z tag. Release events are
# only delivered for releases created with an App or PAT token, which release.yml uses.

name: kpt release provenance
on:
push:
tags:
- "cli/v[0-9]+.[0-9]+.[0-9]+*"
release:
types: [published]

permissions:
contents: read

jobs:
build:
hash:
# Only the CLI releases have assets.
if: startsWith(github.event.release.tag_name, 'cli/v')
runs-on: ubuntu-latest
name: kpt-cli-release
name: hash-release-assets
outputs:
hashes: ${{ steps.hash.outputs.hashes }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: cli/go.mod
- name: Check for replace directives in cli/go.mod
uses: ./.github/actions/check-go-mod-replace
with:
working-directory: cli
- name: Build, Test, Lint
- name: Check that the release tag is on main
run: |
git config --global user.email you@example.com
git config --global user.name Your Name
make all
make test-docker
- name: Run GoReleaser
id: run-goreleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: release --skip=validate --verbose -f release/tag/goreleaser.yaml
git merge-base --is-ancestor "$GITHUB_SHA" origin/main
- name: Download release assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.event.release.tag_name }}
run: |
gh release download "$TAG" --dir release-assets
# Provenance from an earlier run is not an asset to attest.
rm -f release-assets/*.intoto.jsonl
- name: Generate SLSA subjects for provenance
id: hash
run: |
set -euo pipefail

checksum_file=$(cat dist/artifacts.json | jq -r '.[] | select (.type=="Checksum") | .path')

echo "hashes=$(cat $checksum_file | base64 -w0)" >> "$GITHUB_OUTPUT"
hashes=$(cd release-assets && sha256sum -- * | base64 -w0)
echo "hashes=${hashes}" >> "$GITHUB_OUTPUT"

provenance:
needs: [build]
needs: [hash]
permissions:
actions: read # To read the workflow path.
id-token: write # To sign the provenance.
contents: write # To add assets to a release.
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.0.0
with:
base64-subjects: "${{ needs.build.outputs.hashes }}"
upload-assets: true # upload to a new release
base64-subjects: "${{ needs.hash.outputs.hashes }}"
upload-assets: true # upload to the release that triggered this run
165 changes: 155 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,174 @@
# See the License for the specific language governing permissions and
# limitations under the License.

name: kpt library release
# Releases the api, root and cli modules with one locked version.
# See release/README.md and scripts/multimodule-release/release.sh.
#
# TODO: The provenance (release-provenance.yml) only attests the published assets,
# not the run that built them. A stricter option: this workflow only validates,
# tests, tags and pushes (keeping the dry run), and a workflow triggered by the
# pushed cli/v* tag builds, releases and attests in one run. That needs the app
# token for the push, protected cli/* tags, and would also allow resuming a
# half-done release by re-running it.
#
# Pushing uses a token of the kptdev-ci-bot GitHub App, created right before it is
# needed because installation tokens expire after an hour. The app secrets should
# also be defined in the "release" environment, which takes precedence over the
# organization secrets and limits who can read them.

name: kpt multimodule release
on:
push:
tags:
- "v[1-9].*.*"
workflow_dispatch:
inputs:
version:
required: true
description: 'The new version to be released, e.g. v1.2.3 or v1.2.3-pre.1'
type: string
dry_run:
required: false
default: false
description: 'Build everything locally, but do not push or publish anything'
type: boolean

concurrency:
group: kpt-multimodule-release
cancel-in-progress: false

permissions:
contents: read

jobs:
build:
# Releases are only made from main.
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
name: kpt-library-release
name: kpt-multimodule-release
environment: release
permissions:
contents: write
env:
BRANCH: main
DRY_RUN: ${{ inputs.dry_run }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: main
fetch-depth: 0
# Push credentials are configured later, with a fresh app token.
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Check for replace directives in go.mod
cache: false
- name: Configure git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Validate version and branch
id: validate
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
version=$(./scripts/multimodule-release/release.sh validate "$INPUT_VERSION" "$BRANCH")
echo "version=${version}" >> "$GITHUB_OUTPUT"
- name: Check for replace directives and kpt pseudo-versions (root module)
uses: ./.github/actions/check-go-mod-replace
with:
working-directory: .
tagged-only-modules: '["github.com/kptdev/kpt"]'
Comment on lines +87 to +91

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not quite correct, but it highlighted a severe logical issue in the workflow. I'll put this back in draft for now...

- name: Check for replace directives and kpt pseudo-versions (api module)
uses: ./.github/actions/check-go-mod-replace
with:
working-directory: api
tagged-only-modules: '["github.com/kptdev/kpt"]'
- name: Check for replace directives and kpt pseudo-versions (cli module)
uses: ./.github/actions/check-go-mod-replace
with:
working-directory: cli
tagged-only-modules: '["github.com/kptdev/kpt"]'
- name: Build, Test, Lint
run: |
make all
make test-docker
- name: Create commits and tags
env:
VERSION: ${{ steps.validate.outputs.version }}
run: ./scripts/multimodule-release/release.sh tag "$VERSION"
- name: Check release commits for replace directives and kpt pseudo-versions (root module)
uses: ./.github/actions/check-go-mod-replace
with:
working-directory: .
tagged-only-modules: '["github.com/kptdev/kpt"]'
- name: Check release commits for replace directives and kpt pseudo-versions (api module)
uses: ./.github/actions/check-go-mod-replace
with:
working-directory: api
tagged-only-modules: '["github.com/kptdev/kpt"]'
- name: Check release commits for replace directives and kpt pseudo-versions (cli module)
uses: ./.github/actions/check-go-mod-replace
- name: Build, test, lint (root module)
with:
working-directory: cli
tagged-only-modules: '["github.com/kptdev/kpt"]'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
# Only builds: the open-source GoReleaser cannot name the release differently from its tag.
args: release --skip=validate,publish --clean --verbose -f release/tag/goreleaser.yaml
env:
# The root tag, so that .Version (used in the package versions) is X.Y.Z.
GORELEASER_CURRENT_TAG: ${{ steps.validate.outputs.version }}
- name: Create GitHub App token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.CI_BOT_APP_ID }}
private-key: ${{ secrets.CI_BOT_PRIVATE_KEY }}
Comment thread
mozesl-nokia marked this conversation as resolved.
Resolved
- name: Configure push credentials
env:
APP_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
git remote set-url --push origin "https://x-access-token:${APP_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
# Before the push, so a failure here leaves no tags behind. Runs in dry runs too.
- name: Prepare release notes and assets
env:
VERSION: ${{ steps.validate.outputs.version }}
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
./scripts/multimodule-release/release.sh notes "$VERSION" "$BRANCH" release-notes.md
./scripts/multimodule-release/release.sh assets dist release-assets

{
echo "## Release ${VERSION} (dry run: ${DRY_RUN})"
echo
echo "### Assets"
echo
(cd release-assets && printf -- '- %s\n' *)
echo
echo "### Release notes"
echo
cat release-notes.md
} | tee -a "$GITHUB_STEP_SUMMARY"
- name: Push branch and tags
env:
VERSION: ${{ steps.validate.outputs.version }}
run: ./scripts/multimodule-release/release.sh push "$VERSION" "$BRANCH"
- name: Create GitHub release
if: ${{ !inputs.dry_run }}
env:
VERSION: ${{ steps.validate.outputs.version }}
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
git config --global user.email you@example.com
git config --global user.name Your Name
make lib
prerelease=()
if [[ "$VERSION" == *-* ]]; then
prerelease=(--prerelease)
fi
# The release is named vX.Y.Z but points at the cli/vX.Y.Z tag.
gh release create "cli/${VERSION}" release-assets/* \
--verify-tag \
--title "$VERSION" \
--notes-file release-notes.md \
"${prerelease[@]}"
6 changes: 3 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ git config --global user.name "Your Name"
* **.github/workflows/live-e2e.yml**: Live apply e2e tests
* Tests with pinned Kubernetes image SHAs
* Runs `make test-live-apply` with `K8S_VERSION` environment variable
* **.github/workflows/release-api.yml**: Release the kpt API module
* Builds, tests and lints the kpt API module
* Runs `make api`
* **.github/workflows/release.yml**: Multimodule release (manual `workflow_dispatch`)
* Tags the api, root and cli modules with one locked version, builds with GoReleaser and publishes the GitHub release
* Implemented by `scripts/multimodule-release/`; see `release/README.md`

### Documentation & Tests

Expand Down
Loading
Loading