-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into addcognitotopep
- Loading branch information
Showing
7 changed files
with
525 additions
and
7 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
.github/actions/determine-or-use-target-branch-and-get-last-released-image/action.yaml
This file contains 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,88 @@ | ||
name: "Determine or Use Target Branch and Get Latest Docker Image" | ||
description: | | ||
Determine the branch to fetch the latest docker image tag from, or use a target branch directly. | ||
- If base-branch is set, determine the target branch to fetch the latest docker image tag from | ||
- Determine the IMAGE_TAG based on the latest release R and check for images built on branch R - 1: | ||
- For commits on the aptos-release-v1.19 branch, the IMAGE_TAG should be the latest commit built on aptos-release-v1.18 | ||
- For commits on the main branch, the IMAGE_TAG should be the latest commit on the max release aptos-release-v<X.X> branch | ||
- For commits on other branches, the IMAGE_TAG should be the latest commit on the branch's last release aptos-release-v<X.X> branch | ||
- If branch is set, use it directly | ||
inputs: | ||
base-branch: | ||
description: "The base branch to determine the target from, or use a target branch directly" | ||
required: false | ||
branch: | ||
description: "Use this branch directly if set" | ||
required: false | ||
variants: | ||
description: "The variants to check, as a space-separated string, e.g. 'performance failpoints'" | ||
required: false | ||
|
||
outputs: | ||
TARGET_BRANCH: | ||
description: "The determined or target target branch" | ||
value: ${{ steps.set-target-branch.outputs.TARGET_BRANCH }} | ||
IMAGE_TAG: | ||
description: "The latest docker image tag for the given branch and variants" | ||
value: ${{ steps.determine-test-image-tag.outputs.IMAGE_TAG }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
# Checkout repository based on base branch or target branch | ||
- name: Checkout branch | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ inputs.base-branch || inputs.branch }} | ||
path: checkout_branch | ||
fetch-depth: 0 | ||
|
||
- name: Setup Python environment | ||
uses: ./checkout_branch/.github/actions/python-setup | ||
with: | ||
pyproject_directory: checkout_branch/testsuite | ||
|
||
# Determine the target branch if base-branch is used | ||
- name: Set target branch | ||
id: set-target-branch | ||
run: | | ||
if [[ -n "${{ inputs.base-branch }}" ]]; then | ||
base_branch="${{ inputs.base-branch }}" | ||
echo "Determining target branch from base branch: $base_branch" | ||
./testrun determine_target_branch_to_fetch_last_released_image.py "$base_branch" | ||
else | ||
echo "Using target branch: ${{ inputs.branch }}" | ||
echo "TARGET_BRANCH=${{ inputs.branch }}" >> $GITHUB_OUTPUT | ||
fi | ||
shell: bash | ||
working-directory: checkout_branch/testsuite | ||
|
||
# Checkout the determined or target branch | ||
- name: Checkout target branch | ||
if: ${{ steps.set-target-branch.outputs.TARGET_BRANCH != inputs.branch }} | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ steps.set-target-branch.outputs.TARGET_BRANCH }} | ||
path: checkout_branch | ||
fetch-depth: 0 | ||
|
||
# Setup Python environment again after second checkout, as branches are different | ||
- name: Setup Python environment again | ||
if: ${{ steps.set-target-branch.outputs.TARGET_BRANCH != inputs.branch }} | ||
uses: ./checkout_branch/.github/actions/python-setup | ||
with: | ||
pyproject_directory: checkout_branch/testsuite | ||
|
||
# Determine image tag using the target branch | ||
- name: Determine image tag | ||
id: determine-test-image-tag | ||
run: | | ||
variants=(${{ inputs.variants }}) # split the variants string into an array | ||
variants_args=() | ||
for variant in "${variants[@]}"; do | ||
variants_args+=("--variant" "$variant") | ||
done | ||
./testrun find_latest_image.py "${variants_args[@]}" | ||
shell: bash | ||
working-directory: checkout_branch/testsuite |
This file contains 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 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
107 changes: 107 additions & 0 deletions
107
testsuite/determine_target_branch_to_fetch_last_released_image.py
This file contains 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,107 @@ | ||
import sys | ||
import re | ||
|
||
from test_framework.logging import init_logging, log | ||
from test_framework.git import Git | ||
from test_framework.shell import LocalShell | ||
|
||
# GitHub output logic from determinator | ||
from determinator import GithubOutput, write_github_output | ||
|
||
# Initialize logging and the shell/git instances | ||
shell = LocalShell() | ||
git = Git(shell) | ||
|
||
GH_OUTPUT_KEY = "TARGET_BRANCH" | ||
|
||
|
||
def get_all_release_branches(): | ||
"""Get all aptos-release-vX.Y branches""" | ||
pattern = "aptos-release-v*" | ||
regex = r"refs/heads/(aptos-release-v\d+\.\d+)$" | ||
branches = git.get_remote_branches_matching_pattern("origin", pattern, regex) | ||
return sorted(branches, key=lambda x: [int(n) for n in x.split("v")[1].split(".")]) | ||
|
||
|
||
def get_all_release_branches_with_times(): | ||
"""Get all aptos-release-vX.Y branches with their creation times""" | ||
branches = get_all_release_branches() | ||
return [(branch, git.get_branch_creation_time(branch)) for branch in branches] | ||
|
||
|
||
def get_latest_branch_for_previous_major(major): | ||
"""Get the latest aptos-release-v(previous_major).Y branch""" | ||
prev_major = int(major) - 1 | ||
pattern = f"aptos-release-v{prev_major}.*" | ||
regex = rf"refs/heads/(aptos-release-v{prev_major}\.\d+)$" | ||
|
||
branches = git.get_remote_branches_matching_pattern("origin", pattern, regex) | ||
|
||
if branches: | ||
return max(branches, key=lambda x: int(x.split(".")[-1])) | ||
return None | ||
|
||
|
||
def determine_target_branch(base_branch): | ||
"""Determine the appropriate target branch based on the base branch""" | ||
all_release_branches = get_all_release_branches_with_times() | ||
if not all_release_branches: | ||
raise ValueError("No release branches found") | ||
|
||
if base_branch == "main": | ||
# Sort by version numbers for 'main' branch | ||
sorted_branches = sorted( | ||
all_release_branches, | ||
key=lambda x: [int(n) for n in x[0].split("v")[1].split(".")], | ||
reverse=True, | ||
) | ||
return sorted_branches[0][0] | ||
|
||
all_release_branches.sort( | ||
key=lambda x: x[1], reverse=True | ||
) # Sort by creation time, newest first | ||
|
||
# If the base branch is a release branch, find the previous release branch | ||
match = re.match(r"^aptos-release-v(\d+)\.(\d+)", base_branch) | ||
if match: | ||
major, minor = match.groups() | ||
if int(minor) == 0: | ||
return get_latest_branch_for_previous_major(major) | ||
else: | ||
return f"aptos-release-v{major}.{int(minor) - 1}" | ||
|
||
# For other personal branches, find the latest release branch earlier than the current branch | ||
base_branch_time = git.get_branch_creation_time(base_branch) | ||
for branch, time in all_release_branches: | ||
if time < base_branch_time: | ||
return branch | ||
|
||
# If no suitable branch found, return the earliest release branch | ||
return all_release_branches[-1][0] | ||
|
||
|
||
def main() -> None: | ||
if len(sys.argv) != 2: | ||
log.error("Usage: python determine_target_branch.py <base_branch>") | ||
sys.exit(1) | ||
|
||
base_branch = sys.argv[1] | ||
try: | ||
# Determine the target branch | ||
target_branch = determine_target_branch(base_branch) | ||
if target_branch is not None: | ||
# Write the target branch to GitHub output | ||
write_github_output(GithubOutput(GH_OUTPUT_KEY, str(target_branch))) | ||
log.info( | ||
f"Successfully wrote target branch to GitHub output: {target_branch}" | ||
) | ||
except Exception as e: | ||
log.error( | ||
f"Error determining target branch and writing to GitHub output: {e}\n" | ||
"This may be an indication that you're running locally or the environment is not configured correctly." | ||
) | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.