Skip to content

Allow a release without engine cherrypicks (adds fallback logic) #172184

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

Merged
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
45 changes: 44 additions & 1 deletion bin/internal/last_engine_commit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,48 @@ $ErrorActionPreference = "Stop"

$progName = Split-Path -parent $MyInvocation.MyCommand.Definition
$flutterRoot = (Get-Item $progName).parent.parent.FullName
$gitToplevel = (git rev-parse --show-toplevel).Trim()
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking: This assumes this will only ever be run inside the flutter/**/ path. If someone runs ~/fluter/bin/internal/... from another git repo.. spicy.

# 1. Determine when we diverged from master.
$MERGE_BASE_COMMIT = ""
try {
$MERGE_BASE_COMMIT = (git merge-base HEAD master).Trim()
}
catch {
# If git merge-base fails (e.g., master not found, no common history),
# $MERGE_BASE_COMMIT will remain empty.
}

cmd /c "git log -1 --pretty=format:%H -- ""$(git rev-parse --show-toplevel)/DEPS"" ""$(git rev-parse --show-toplevel)/engine"""
# If we did not find a merge-base, fail
if ([string]::IsNullOrEmpty($MERGE_BASE_COMMIT)) {
Write-Error "Error: Could not determine a suitable engine commit." -ErrorAction Stop
Write-Error "Current branch: $(git rev-parse --abbrev-ref HEAD).Trim()" -ErrorAction Stop
Write-Error "Expected a different branch, from 'master', or a 'master' branch that exists and has history." -ErrorAction Stop
exit 1
}

# 2. Define and search history range to search within (unique to changes on this branch).
$HISTORY_RANGE = "$MERGE_BASE_COMMIT..HEAD"
Copy link
Member

Choose a reason for hiding this comment

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

on a release branch, the content hash will also use the release version file in internal. Not sure if you need that here or not. I guess that would be handled in the fallback on line 54.

$DEPS_PATH = Join-Path $gitToplevel "DEPS"
$ENGINE_PATH = Join-Path $gitToplevel "engine"

$ENGINE_COMMIT = (git log -1 --pretty=format:%H --ancestry-path $HISTORY_RANGE -- "$DEPS_PATH" "$ENGINE_PATH")

# 3. If no engine-related commit was found within the current branch's history, fallback to the first commit on this branch.
if ([string]::IsNullOrEmpty($ENGINE_COMMIT)) {
# Find the oldest commit on HEAD that is *not* reachable from MERGE_BASE_COMMIT.
# This is the first commit *on this branch* after it diverged from 'master'.
$ENGINE_COMMIT = (git log --pretty=format:%H --reverse --ancestry-path "$MERGE_BASE_COMMIT..HEAD" | Select-Object -First 1).Trim()

# Final check: If even this fallback fails (which would be highly unusual if MERGE_BASE_COMMIT was found),
# then something is truly wrong.
if ([string]::IsNullOrEmpty($ENGINE_COMMIT)) {
Write-Error "Error: Unexpected state. MERGE_BASE_COMMIT was found ($MERGE_BASE_COMMIT), but no commits found on current branch after it." -ErrorAction Stop
Write-Error "Current branch: $((git rev-parse --abbrev-ref HEAD).Trim())" -ErrorAction Stop
Write-Error "History range searched for fallback: $HISTORY_RANGE" -ErrorAction Stop
Write-Error "All commits on current branch (for debug):" -ErrorAction Stop
(git log --pretty=format:%H) | Write-Error -ErrorAction Stop
exit 1
}
}

Write-Output $ENGINE_COMMIT
35 changes: 34 additions & 1 deletion bin/internal/last_engine_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,37 @@ set -e

FLUTTER_ROOT="$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")")"

git log -1 --pretty=format:%H -- "$(git rev-parse --show-toplevel)/DEPS" "$(git rev-parse --show-toplevel)/engine"
# 1. Determine when we diverged from master, and prevent set -e from exiting.
MERGE_BASE_COMMIT="$(git merge-base HEAD master || echo "")"

# If we did not find a merge-base, fail
if [[ -z "$MERGE_BASE_COMMIT" ]]; then
echo >&2 "Error: Could not determine a suitable engine commit."
echo >&2 "Current branch: $(git rev-parse --abbrev-ref HEAD)"
echo >&2 "Expected a different branch, from master"
exit 1
fi

# 2. Define and search history range to searhc within (unique to changes on this branch).
HISTORY_RANGE="$MERGE_BASE_COMMIT..HEAD"
ENGINE_COMMIT="$(git log -1 --pretty=format:%H --ancestry-path "$HISTORY_RANGE" -- "$(git rev-parse --show-toplevel)/DEPS" "$(git rev-parse --show-toplevel)/engine")"

# 3. If no engine-related commit was found within the current branch's history, fallback to the first commit on this branch.
if [[ -z "$ENGINE_COMMIT" ]]; then
# Find the oldest commit on HEAD that is *not* reachable from MERGE_BASE_COMMIT.
# This is the first commit *on this branch* after it diverged from 'master'.
ENGINE_COMMIT="$(git log --pretty=format:%H --reverse --ancestry-path "$MERGE_BASE_COMMIT"..HEAD | head -n 1)"
Copy link
Member

Choose a reason for hiding this comment

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

non-blocking; you can use "git log -1" instead of "| head -n 1" or Select-Object -First 1


# Final check: If even this fallback fails (which would be highly unusual if MERGE_BASE_COMMIT was found),
# then something is truly wrong.
if [[ -z "$ENGINE_COMMIT" ]]; then
echo >&2 "Error: Unexpected state. MERGE_BASE_COMMIT was found ($MERGE_BASE_COMMIT), but no commits found on current branch after it."
echo >&2 "Current branch: $(git rev-parse --abbrev-ref HEAD)"
echo >&2 "History range searched for fallback: $HISTORY_RANGE"
echo >&2 "All commits on current branch (for debug):"
git log --pretty=format:%H
exit 1
fi
fi

echo "$ENGINE_COMMIT"
54 changes: 50 additions & 4 deletions dev/tools/test/last_engine_commit_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ void main() {
}

io.ProcessResult run(String executable, List<String> args) {
print('Running "$executable ${args.join(" ")}');
final io.ProcessResult result = io.Process.runSync(
executable,
args,
Expand All @@ -76,7 +75,9 @@ void main() {
setUpAll(() async {
if (usePowershellOnPosix) {
final io.ProcessResult result = io.Process.runSync('pwsh', <String>['--version']);
print('Using Powershell (${result.stdout}) on POSIX for local debugging and testing');
print(
'Using Powershell (${(result.stdout as String).trim()}) on POSIX for local debugging and testing',
);
}
});

Expand Down Expand Up @@ -104,7 +105,7 @@ void main() {

if (const LocalPlatform().isWindows || usePowershellOnPosix) {
// Copy a minimal set of environment variables needed to run the update_engine_version script in PowerShell.
const List<String> powerShellVariables = <String>['SystemRoot', 'Path', 'PATHEXT'];
const List<String> powerShellVariables = <String>['SYSTEMROOT', 'PATH', 'PATHEXT'];
for (final String key in powerShellVariables) {
final String? value = io.Platform.environment[key];
if (value != null) {
Expand Down Expand Up @@ -143,7 +144,12 @@ void main() {
executable = testRoot.binInternalLastEngineCommit.path;
args = <String>[];
}
return run(executable, args).stdout as String;
return (run(executable, args).stdout as String).trim();
}

/// Gets the latest commit on the current branch.
String getLastCommit() {
return (run('git', <String>['rev-parse', 'HEAD']).stdout as String).trim();
}

void writeCommit(Iterable<String> files) {
Expand All @@ -157,7 +163,12 @@ void main() {
run('git', <String>['commit', '-m', 'Wrote ${files.length} files']);
}

void changeBranch({required String newBranchName}) {
run('git', <String>['checkout', '-b', newBranchName]);
}

test('returns the last engine commit', () {
changeBranch(newBranchName: 'flutter-1.2.3-candidate.0');
writeCommit(<String>['DEPS', 'engine/README.md']);

final String lastEngine = getLastEngineCommit();
Expand All @@ -168,6 +179,7 @@ void main() {
});

test('considers DEPS an engine change', () {
changeBranch(newBranchName: 'flutter-1.2.3-candidate.0');
writeCommit(<String>['DEPS', 'engine/README.md']);

final String lastEngineA = getLastEngineCommit();
Expand All @@ -177,6 +189,40 @@ void main() {
final String lastEngineB = getLastEngineCommit();
expect(lastEngineB, allOf(isNotEmpty, isNot(equals(lastEngineA))));
});

test('if there have been no engine changes, uses the first commit since the branch point', () {
final String initialStartingCommit = getLastCommit();

// Make an engine change *before* the branch.
writeCommit(<String>['engine/README.md']);
final String engineCommitPreBranch = getLastCommit();
changeBranch(newBranchName: 'flutter-1.2.3-candidate.0');

// Make a non-engine change, but no engine changes, after branching.
writeCommit(<String>['bin/internal/release-candidate-branch.version']);
final String initialBranchCommit = getLastCommit();

// Write another commit to make sure we don't always use the latest.
writeCommit(<String>['CHANGELOG.md']);
final String latestCommitIgnore = getLastCommit();

// Get the engine commit, which should fallback to HEAD~2 (in this case).
final String lastCommitToEngine = getLastEngineCommit();
expect(
lastCommitToEngine,
initialBranchCommit,
reason:
'The git history for this simulation looks like this:\n'
'master (intial commit) | $initialStartingCommit\n'
'master (touches engine) | $engineCommitPreBranch\n'
'flutter-1.2.3-candidate.0 | $initialBranchCommit\n'
'flutter-1.2.3-candidate.0 | $latestCommitIgnore\n'
'\n'
'We expected our script to select HEAD~2, $initialBranchCommit, but '
'instead it selected $lastCommitToEngine, which is incorrect. See '
'the table above to help debug.',
);
});
}

extension on File {
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy