diff --git a/cli/internal/architecture/comment_cli_minimum_version_warning_test.go b/cli/internal/architecture/comment_cli_minimum_version_warning_test.go index 77367cb70c..2c9ff0399e 100644 --- a/cli/internal/architecture/comment_cli_minimum_version_warning_test.go +++ b/cli/internal/architecture/comment_cli_minimum_version_warning_test.go @@ -26,6 +26,7 @@ type commentScriptOptions struct { Mutation string BaseRef string HeadRef string + HeadBranch string IncludePRNumber bool FailOnWarning bool ExpectFailure bool @@ -134,6 +135,21 @@ func TestCommentCliMinimumVersionWarningIgnoresUnrelatedChanges(t *testing.T) { assertNotContains(t, result.GitHubLog, "PATCH") } +// Verifies that release-please release PRs skip check mode even with Go CLI changes. +func TestCommentCliMinimumVersionWarningSkipsReleasePleaseBranch(t *testing.T) { + result := runCommentScriptCase(t, commentScriptOptions{ + Mutation: "go-cli", + BaseRef: "HEAD^", + HeadBranch: "release-please--branches--v3-beta", + IncludePRNumber: true, + FailOnWarning: true, + }) + + assertContains(t, result.Output, "release-please release PR") + assertNotContains(t, result.GitHubLog, "POST") + assertNotContains(t, result.GitHubLog, "PATCH") +} + // Verifies that non-PR runs stop before calling GitHub issue APIs. func TestCommentCliMinimumVersionWarningSkipsNonPullRequestRuns(t *testing.T) { result := runCommentScriptCase(t, commentScriptOptions{ @@ -190,6 +206,8 @@ func runCommentScript( command := exec.Command(filepath.Join(repositoryRoot(t), commentScriptPath)) command.Dir = repositoryPath + // GITHUB_HEAD_REF is always set explicitly because CI inherits the real PR head + // branch into the test process, which would trigger the release-please skip path. command.Env = append(os.Environ(), "PATH="+mockBinPath+string(os.PathListSeparator)+os.Getenv("PATH"), "GH_LOG="+gitHubLogPath, @@ -197,6 +215,7 @@ func runCommentScript( "GH_EXISTING_COMMENT_ID="+options.ExistingCommentID, "ULOOP_REPOSITORY_ROOT="+repositoryPath, "GITHUB_REPOSITORY=hatayama/unity-cli-loop", + "GITHUB_HEAD_REF="+options.HeadBranch, ) if options.IncludePRNumber { command.Env = append(command.Env, "PR_NUMBER=123") diff --git a/cli/internal/automation/minimum_version_warning.go b/cli/internal/automation/minimum_version_warning.go index c45860dfd9..459bd353b2 100644 --- a/cli/internal/automation/minimum_version_warning.go +++ b/cli/internal/automation/minimum_version_warning.go @@ -25,6 +25,8 @@ Please confirm whether the Unity package can still accept older CLI versions. If Resolved: this PR no longer has Go CLI changes without a ` + "`MINIMUM_REQUIRED_CLI_VERSION`" + ` update. ` goCliPackageRoot = "cli/" + // release-please names its release branches "release-please--branches--". + releasePleaseBranchPrefix = "release-please--" ) var minimumVersionWarningValuePattern = regexp.MustCompile(`MINIMUM_REQUIRED_CLI_VERSION\s*=\s*"([^"]+)"`) @@ -35,6 +37,7 @@ type minimumVersionWarningConfig struct { repository string baseRef string headRef string + headBranch string failOnWarning bool } @@ -49,6 +52,13 @@ func RunMinimumVersionWarning(ctx context.Context, stdout io.Writer, stderr io.W return 0 } + // Release PRs only contain release-please version stamps (cli/contract.json and + // internal/tools/default-tools.json); the reminder targets human-authored CLI changes. + if strings.HasPrefix(config.headBranch, releasePleaseBranchPrefix) { + writeMinimumVersionWarningLine(stdout, "Skipping CLI minimum version check because this is a release-please release PR.") + return 0 + } + if config.baseRef == "" { writeMinimumVersionWarningLine(stdout, "Skipping CLI minimum version comment because no base ref was provided.") return 0 @@ -127,6 +137,7 @@ func minimumVersionWarningConfigFromEnvironment() (minimumVersionWarningConfig, repository: os.Getenv("GITHUB_REPOSITORY"), baseRef: baseRef, headRef: headRef, + headBranch: os.Getenv("GITHUB_HEAD_REF"), failOnWarning: os.Getenv("CLI_MINIMUM_VERSION_FAIL_ON_WARNING") == "true", }, nil } diff --git a/cli/internal/automation/minimum_version_warning_test.go b/cli/internal/automation/minimum_version_warning_test.go index 72348e9a6d..e0198a637b 100644 --- a/cli/internal/automation/minimum_version_warning_test.go +++ b/cli/internal/automation/minimum_version_warning_test.go @@ -64,6 +64,33 @@ func TestMinimumVersionWarningSkipsMissingBaseRefBeforeRepositoryResolution(t *t } } +// Verifies that release-please release PRs skip the check before any git diff runs. +func TestMinimumVersionWarningSkipsReleasePleaseHeadBranch(t *testing.T) { + t.Setenv("ULOOP_REPOSITORY_ROOT", t.TempDir()) + t.Setenv("PR_NUMBER", "123") + t.Setenv("GITHUB_REPOSITORY", "owner/repository") + t.Setenv("GITHUB_BASE_REF", "v3-beta") + t.Setenv("GITHUB_HEAD_REF", "release-please--branches--v3-beta") + t.Setenv("CLI_MINIMUM_VERSION_BASE_REF", "") + t.Setenv("CLI_MINIMUM_VERSION_HEAD_REF", "") + t.Setenv("CLI_MINIMUM_VERSION_FAIL_ON_WARNING", "true") + t.Setenv("PATH", t.TempDir()) + + stdout := bytes.Buffer{} + stderr := bytes.Buffer{} + exitCode := RunMinimumVersionWarning(context.Background(), &stdout, &stderr) + + if exitCode != 0 { + t.Fatalf("expected release-please head branch to skip with exit code 0, got %d\n%s", exitCode, stderr.String()) + } + if stdout.String() != "Skipping CLI minimum version check because this is a release-please release PR.\n" { + t.Fatalf("expected release-please skip message, got %q", stdout.String()) + } + if stderr.String() != "" { + t.Fatalf("expected no stderr on release-please skip, got %q", stderr.String()) + } +} + // Verifies that Go CLI source changes require a minimum-version warning. func TestMinimumVersionWarningRequiresCommentForGoCliSourceChanges(t *testing.T) { testCases := []struct { diff --git a/release-please-config.json b/release-please-config.json index 842bb28744..fdb02b5ed7 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -21,6 +21,7 @@ }, "cli": { "component": "cli", + "release-as": "3.0.0-beta.31", "release-type": "go", "versioning": "prerelease", "prerelease": true,