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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type commentScriptOptions struct {
Mutation string
BaseRef string
HeadRef string
HeadBranch string
IncludePRNumber bool
FailOnWarning bool
ExpectFailure bool
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -190,13 +206,16 @@ 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,
"GH_BODY_LOG="+bodyLogPath,
"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")
Expand Down
11 changes: 11 additions & 0 deletions cli/internal/automation/minimum_version_warning.go
Original file line number Diff line number Diff line change
Expand Up @@ -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--<target>".
releasePleaseBranchPrefix = "release-please--"
)

var minimumVersionWarningValuePattern = regexp.MustCompile(`MINIMUM_REQUIRED_CLI_VERSION\s*=\s*"([^"]+)"`)
Expand All @@ -35,6 +37,7 @@ type minimumVersionWarningConfig struct {
repository string
baseRef string
headRef string
headBranch string
failOnWarning bool
}

Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
27 changes: 27 additions & 0 deletions cli/internal/automation/minimum_version_warning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"cli": {
"component": "cli",
"release-as": "3.0.0-beta.31",
"release-type": "go",
"versioning": "prerelease",
"prerelease": true,
Expand Down
Loading