Skip to content

feat(RELEASE-1142): support for merge queues #1169

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 1 commit into from
Jul 3, 2025
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
25 changes: 22 additions & 3 deletions integration-tests/pipelines/e2e-tests-staging-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.labels['pac.test.appstudio.openshift.io/pull-request']
- name: BRANCH_NAME
valueFrom:
fieldRef:
fieldPath: metadata.labels['pac.test.appstudio.openshift.io/branch']
script: |
#!/usr/bin/env bash

Expand Down Expand Up @@ -171,7 +175,17 @@ spec:

echo "PR_GIT_URL: $(params.PR_GIT_URL)"
echo "PR_GIT_REVISION: $(params.PR_GIT_REVISION)"
echo "PR_NUMBER: ${PR_NUMBER:?}"
if [ -n "${PR_NUMBER}" ]; then
echo "PR_NUMBER: ${PR_NUMBER}"
else
if [ -n "${BRANCH_NAME}" ]; then
echo "This is not a PR, but a merge queue branch"
echo "BRANCH_NAME: ${BRANCH_NAME}"
else
echo "No PR_NUMBER or BRANCH_NAME environment variables found"
exit 1
fi
fi

VAULT_PASSWORD_FILE=$(mktemp)
export VAULT_PASSWORD_FILE
Expand All @@ -190,8 +204,13 @@ spec:
export RELEASE_CATALOG_GIT_URL
export RELEASE_CATALOG_GIT_REVISION

AFFECTED_PIPELINES=$("/home/e2e/tests/scripts/find_release_pipelines_from_pr.sh" \
"konflux-ci/release-service-catalog" "${PR_NUMBER:?}")
if [ -n "${PR_NUMBER}" ]; then
AFFECTED_PIPELINES=$("/home/e2e/tests/scripts/find_release_pipelines_from_pr.sh" \
--repo "konflux-ci/release-service-catalog" --pull_request_number "${PR_NUMBER}")
else
AFFECTED_PIPELINES=$("/home/e2e/tests/scripts/find_release_pipelines_from_branch.sh" \
--repo "konflux-ci/release-service-catalog" --branch "${BRANCH_NAME}")
fi

# if PIPELINE_USED is set, use it, otherwise use PIPELINE_TEST_SUITE
PIPELINE=""
Expand Down
129 changes: 128 additions & 1 deletion integration-tests/scripts/find_release_pipelines_from_pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ find_release_pipelines_from_pr() {
setup_workspace
clone_and_checkout_pr "$REPO" "$PR_NUM" || return 1

_find_and_process_pipelines
}

find_release_pipelines_from_branch() {
local REPO=$1
local BRANCH=$2

if [ -z "$REPO" ] || [ -z "$BRANCH" ]; then
echo "please provide repo and branch name, for example: find_release_pipelines_from_branch konflux-ci/release-service-catalog development"
return 1
fi

setup_workspace
clone_and_checkout_branch "$REPO" "$BRANCH" || return 1

_find_and_process_pipelines
}

_find_and_process_pipelines() {
# Declare global variables
declare -a FOUND_PIPELINENAMES
declare -a FOUND_INTERNAL_PIPELINENAMES
Expand Down Expand Up @@ -223,6 +242,21 @@ clone_and_checkout_pr() {
fi
}

clone_and_checkout_branch() {
local repo=$1
local branch=$2

git clone --quiet "https://github.com/$repo.git" release-service-catalog
cd release-service-catalog || exit 1

if ! git checkout "$branch" > /dev/null 2>&1; then
echo "Failed to checkout branch '$branch'"
cd ../.. || exit 1
rm -rf ".tmp_pr_check"
return 1
fi
}

find_changed_tekton_tasks_pipelines() {
local FILES
FILES=$(git diff --name-only origin/development...HEAD)
Expand Down Expand Up @@ -329,4 +363,97 @@ cleanup_workspace() {
rm -rf ".tmp_pr_check"
}

find_release_pipelines_from_pr "$1" "$2"
# Usage function
usage() {
echo "Usage: $0 --repo <repo> [--pull_request_number <number> | --branch <branch>]"
echo ""
echo "Options:"
echo " --repo <repo> Repository in 'owner/repo' format (e.g., 'konflux-ci/release-service-catalog')"
echo " --pull_request_number <number> Pull request number"
echo " --branch <branch> Branch name to checkout"
echo " -h, --help Show this help message"
echo ""
echo "Note: Either --pull_request_number or --branch must be provided, but not both."
echo ""
echo "Examples:"
echo " $0 --repo konflux-ci/release-service-catalog --pull_request_number 949"
echo " $0 --repo konflux-ci/release-service-catalog --branch development"
exit 1
}

# Main execution with command line switch parsing
main() {
local repo=""
local pull_number=""
local branch=""

# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--repo)
repo="$2"
shift 2
;;
--pull_request_number)
pull_number="$2"
shift 2
;;
--branch)
branch="$2"
shift 2
;;
-h|--help)
usage
;;
*)
echo "Error: Unknown option '$1'" >&2
echo "" >&2
usage
;;
esac
done

# Validate required parameters
if [ -z "$repo" ]; then
echo "Error: --repo parameter is required." >&2
echo "" >&2
usage
fi

# Validate that either pull_request_number or branch is provided, but not both
if [ -n "$pull_number" ] && [ -n "$branch" ]; then
echo "Error: Cannot specify both --pull_request_number and --branch. Choose one." >&2
echo "" >&2
usage
fi

if [ -z "$pull_number" ] && [ -z "$branch" ]; then
echo "Error: Either --pull_request_number or --branch parameter is required." >&2
echo "" >&2
usage
fi

# Validate repo format (should contain owner/repo)
if [[ ! "$repo" =~ ^[^/]+/[^/]+$ ]]; then
echo "Error: Repository must be in 'owner/repo' format (e.g., 'konflux-ci/release-service-catalog')" >&2
echo "" >&2
usage
fi

# Validate pull_number is numeric if provided
if [ -n "$pull_number" ] && ! [[ "$pull_number" =~ ^[0-9]+$ ]]; then
echo "Error: Pull request number must be a positive integer" >&2
echo "" >&2
usage
fi

# Call the main function with appropriate parameters
if [ -n "$pull_number" ]; then
find_release_pipelines_from_pr "$repo" "$pull_number"
else
find_release_pipelines_from_branch "$repo" "$branch"
fi
}

# Execute main function with all arguments
main "$@"