-
Notifications
You must be signed in to change notification settings - Fork 4
fix(branching): cross-repo PR builds fail #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
tbcrawford
wants to merge
3
commits into
FigureTechnologies:main
Choose a base branch
from
tbcrawford:fix/builds-fail-cross-repo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
src/functionalTest/kotlin/com/figure/gradle/semver/specs/CrossRepositoryPullRequestSpec.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| /* | ||
| * Copyright (C) 2024 Figure Technologies | ||
| * | ||
| * 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 | ||
| * | ||
| * https://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. | ||
| */ | ||
| package com.figure.gradle.semver.specs | ||
|
|
||
| import com.figure.gradle.semver.internal.environment.Env | ||
| import com.figure.gradle.semver.kotest.GradleProjectsExtension | ||
| import com.figure.gradle.semver.kotest.shouldOnlyHave | ||
| import com.figure.gradle.semver.projects.RegularProject | ||
| import com.figure.gradle.semver.projects.SettingsProject | ||
| import com.figure.gradle.semver.projects.SubprojectProject | ||
| import io.kotest.core.extensions.install | ||
| import io.kotest.core.spec.style.FunSpec | ||
| import io.kotest.extensions.system.OverrideMode | ||
| import io.kotest.extensions.system.withEnvironment | ||
| import org.gradle.util.GradleVersion | ||
|
|
||
| class CrossRepositoryPullRequestSpec : FunSpec({ | ||
| val projects = install( | ||
| GradleProjectsExtension( | ||
| RegularProject(projectName = "regular-project"), | ||
| SettingsProject(projectName = "settings-project"), | ||
| SubprojectProject(projectName = "subproject-project"), | ||
| ), | ||
| ) | ||
|
|
||
| val mainBranch = "main" | ||
| val developmentBranch = "develop" | ||
| val forkedFeatureBranch = "fix/builds-fail-cross-repo" | ||
|
|
||
| test("should calculate next version for cross-repository/forked pull request") { | ||
| withEnvironment( | ||
| environment = mapOf( | ||
| Env.CI to "true", | ||
| Env.GITHUB_HEAD_REF to forkedFeatureBranch, | ||
| ), | ||
| mode = OverrideMode.SetOrOverride, | ||
| ) { | ||
| // Given: Simulate a cross-repo PR scenario where the feature branch doesn't exist locally | ||
| // This mimics what happens when GitHub Actions checks out a forked pull request | ||
| projects.git { | ||
| initialBranch = mainBranch | ||
| actions = actions { | ||
| commit(message = "1 commit on $mainBranch", tag = "1.0.0") | ||
|
|
||
| checkout(developmentBranch) | ||
| commit(message = "1 commit on $developmentBranch") | ||
|
|
||
| // Simulate being on main branch (as in cross-repo PRs) but with GITHUB_HEAD_REF set | ||
| // to the forked branch name that doesn't exist locally | ||
| checkout(mainBranch) | ||
| } | ||
| } | ||
|
|
||
| // When: Building should not fail even though the branch name from GITHUB_HEAD_REF doesn't exist locally | ||
| projects.build(GradleVersion.current()) | ||
|
|
||
| // Then: Should generate a version using the forked branch name from GITHUB_HEAD_REF | ||
| projects.versions shouldOnlyHave "1.0.1-fix-builds-fail-cross-repo.0" | ||
| } | ||
| } | ||
|
|
||
| test("should handle cross-repo PR with both GITHUB_HEAD_REF and GITHUB_REF_NAME set") { | ||
| withEnvironment( | ||
| environment = mapOf( | ||
| Env.CI to "true", | ||
| Env.GITHUB_HEAD_REF to forkedFeatureBranch, | ||
| Env.GITHUB_REF_NAME to "123/merge", // Typical PR merge ref | ||
| ), | ||
| mode = OverrideMode.SetOrOverride, | ||
| ) { | ||
| // Given: Similar setup but with both environment variables set | ||
| projects.git { | ||
| initialBranch = mainBranch | ||
| actions = actions { | ||
| commit(message = "1 commit on $mainBranch", tag = "1.0.0") | ||
| checkout(mainBranch) // Stay on main to simulate cross-repo PR checkout | ||
| } | ||
| } | ||
|
|
||
| // When: Building should prioritize GITHUB_HEAD_REF over GITHUB_REF_NAME | ||
| projects.build(GradleVersion.current()) | ||
|
|
||
| // Then: Should use the forked branch name, not the merge ref | ||
| projects.versions shouldOnlyHave "1.0.1-fix-builds-fail-cross-repo.0" | ||
| } | ||
| } | ||
|
|
||
| test("should fallback to GITHUB_REF_NAME when GITHUB_HEAD_REF is empty") { | ||
| withEnvironment( | ||
| environment = mapOf( | ||
| Env.CI to "true", | ||
| Env.GITHUB_HEAD_REF to "", // Empty but present | ||
| Env.GITHUB_REF_NAME to "feature-branch-fallback", | ||
| ), | ||
| mode = OverrideMode.SetOrOverride, | ||
| ) { | ||
| // Given: GITHUB_HEAD_REF is empty (not a PR) but GITHUB_REF_NAME is set | ||
| projects.git { | ||
| initialBranch = mainBranch | ||
| actions = actions { | ||
| commit(message = "1 commit on $mainBranch", tag = "1.0.0") | ||
| checkout("feature-branch-fallback") | ||
| commit(message = "1 commit on feature branch") | ||
| } | ||
| } | ||
|
|
||
| // When: Building should use GITHUB_REF_NAME since GITHUB_HEAD_REF is empty | ||
| projects.build(GradleVersion.current()) | ||
|
|
||
| // Then: Should use the ref name from GITHUB_REF_NAME with correct commit count | ||
| projects.versions shouldOnlyHave "1.0.1-feature-branch-fallback.1" | ||
| } | ||
| } | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SyntheticRef.getTarget()violates JGit Ref interface contractMedium Severity
SyntheticRef.getTarget()returnsnull, but the JGitRefinterface contract specifies that whenisSymbolic()isfalse,getTarget()must returnthis. All standard JGit non-symbolic ref implementations (e.g.,ObjectIdRef) follow this contract. Returningnullhere could cause aNullPointerExceptionif the ref is ever passed to JGit APIs or other code that relies on the documented non-null guarantee for non-symbolic refs.