Skip to content

Commit 48d4b3f

Browse files
Merge pull request #162 from stuggi/fr_branch_changes
Use PR for openstack-k8s-operators-ci workflow updates and Convert feature_branch_repos to YAML with configurable options
2 parents 689dd45 + d241a83 commit 48d4b3f

3 files changed

Lines changed: 129 additions & 48 deletions

File tree

.github/workflows/create-release-branch-v1.yml

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
# 'The name of the OpenStack K8s tag variable in the Makefile (for install_yamls).'
6262
OPENSTACK_K8S_TAG_VARIABLE: 'OPENSTACK_K8S_TAG'
6363
# 'The relative path to the file containing the list of repositories to process.'
64-
REPO_LIST_FILE: 'feature_branch_repos.txt'
64+
REPO_LIST_FILE: 'feature_branch_repos.yaml'
6565
# 'The branch to create the new branch from.'
6666
SOURCE_BRANCH: 'main'
6767
# 'Timeout for git operations (in seconds)'
@@ -315,8 +315,8 @@ jobs:
315315
exit 1
316316
fi
317317

318-
# Read repositories from file, filtering out empty lines and comments
319-
repos=$(grep -v '^#' "${REPO_LIST_FILE}" | grep -v '^[[:space:]]*$' | tr '\n' ' ')
318+
# Read repositories from YAML file
319+
repos=$(yq e '.repos[].name' "${REPO_LIST_FILE}" | tr '\n' ' ')
320320

321321
if [ -z "$repos" ]; then
322322
echo "No repositories found in '${REPO_LIST_FILE}'."
@@ -381,8 +381,11 @@ jobs:
381381
handle_repo_error "${repo_name}" "Failed to create new branch '${BRANCH_NAME}'" "$TEMP_DIR"
382382
fi
383383

384+
# Check if we should skip BRANCH variable changes for this repo
385+
skip_makefile_changes=$(yq e ".repos[] | select(.name == \"${repo_name}\") | .skip_makefile_changes // false" "${REPO_LIST_FILE}")
386+
384387
BRANCH_PUSHED=false
385-
if [ -f "Makefile" ]; then
388+
if [ -f "Makefile" ] && [ "$skip_makefile_changes" != "true" ]; then
386389
echo "Makefile found. Checking for variables to update on new branch..."
387390
if grep -qE "^${BRANCH_VARIABLE}\s*(\?=|=)" Makefile; then
388391
if ! sed -i -E "s/^(${BRANCH_VARIABLE}\s*(\?=|=)\s*).*/\1${BRANCH_NAME}/" Makefile; then
@@ -396,7 +399,7 @@ jobs:
396399
fi
397400
fi
398401
fi
399-
402+
400403
# Check if there are changes to commit and push
401404
if ! git diff --quiet -- Makefile; then
402405
# FAIL if commit and push fails
@@ -408,7 +411,11 @@ jobs:
408411
echo "No changes detected in Makefile."
409412
fi
410413
else
411-
echo "No Makefile found."
414+
if [ "$skip_makefile_changes" = "true" ]; then
415+
echo "Skipping Makefile changes for ${repo_name} (configured in ${REPO_LIST_FILE})."
416+
else
417+
echo "No Makefile found."
418+
fi
412419
fi
413420

414421
# Special handling for openstack-operator: update default_images.yaml
@@ -698,19 +705,85 @@ jobs:
698705
echo "::error::Failed to checkout main branch in openstack-k8s-operators-ci"
699706
exit 1
700707
fi
701-
708+
702709
if ! git pull origin main; then
703710
echo "::error::Failed to pull latest changes from main branch in openstack-k8s-operators-ci"
704711
exit 1
705712
fi
706713
707-
update_yaml_value ".github/workflows/force-bump-branches.yaml" ".jobs.trigger-jobs.strategy.matrix.branch" "${FORCE_BUMP_BRANCHES}"
714+
# Create a new branch for the PR
715+
PR_BRANCH="update-force-bump-branches-${BRANCH_NAME}-$(date +%s)"
716+
echo "Creating branch ${PR_BRANCH} for pull request..."
717+
if ! git checkout -b "${PR_BRANCH}"; then
718+
echo "::error::Failed to create branch ${PR_BRANCH}"
719+
exit 1
720+
fi
721+
722+
# Track if any changes were made
723+
CHANGES_MADE=false
724+
FILES_TO_COMMIT=""
725+
726+
# Update force-bump-branches.yaml
727+
WORKFLOW_FILE=".github/workflows/force-bump-branches.yaml"
728+
if [ -f "${WORKFLOW_FILE}" ]; then
729+
update_yaml_value "${WORKFLOW_FILE}" ".jobs.trigger-jobs.strategy.matrix.branch" "${FORCE_BUMP_BRANCHES}"
730+
if ! git diff --quiet -- "${WORKFLOW_FILE}"; then
731+
echo "Updated ${WORKFLOW_FILE}"
732+
FILES_TO_COMMIT="${WORKFLOW_FILE}"
733+
CHANGES_MADE=true
734+
fi
735+
else
736+
echo "No ${WORKFLOW_FILE} found."
737+
fi
738+
739+
# If changes were made, commit and create PR
740+
if [ "$CHANGES_MADE" = "true" ]; then
741+
echo "Changes detected. Preparing to commit and create pull request..."
742+
743+
# Show the changes
744+
echo "Showing all changes:"
745+
git diff
746+
747+
if [ "$DRY_RUN" = "true" ]; then
748+
echo "DRY RUN: Would have committed and created PR for openstack-k8s-operators-ci with changes to: ${FILES_TO_COMMIT}"
749+
else
750+
# Configure git
751+
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
752+
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
753+
754+
# Commit all changes
755+
git add ${FILES_TO_COMMIT}
756+
git commit -m "ci: Update force-bump-branches for ${BRANCH_NAME}"
757+
758+
# Push the branch
759+
echo "Pushing branch ${PR_BRANCH}..."
760+
if ! retry_command 3 5 "Pushing branch ${PR_BRANCH}" git push origin "${PR_BRANCH}"; then
761+
echo "::error::Failed to push branch ${PR_BRANCH}"
762+
exit 1
763+
fi
708764
709-
# Commit and push changes if any were made
710-
commit_and_push "ci: Update force-bump-branches for ${BRANCH_NAME}" ".github/workflows/force-bump-branches.yaml" "${SOURCE_BRANCH}"
765+
# Create pull request using GitHub CLI
766+
echo "Creating pull request..."
767+
PR_BODY="This PR updates the force-bump-branches workflow to include the ${BRANCH_NAME} branch."$'\n\n'"Changes included:"$'\n'"- Update force-bump-branches.yaml matrix to: ${FORCE_BUMP_BRANCHES}"$'\n\n'"Generated automatically by the create-release-branch workflow."
768+
PR_URL=$(gh pr create \
769+
--title "ci: Update force-bump-branches for ${BRANCH_NAME}" \
770+
--body "${PR_BODY}" \
771+
--base main \
772+
--head "${PR_BRANCH}" \
773+
--repo "${ORG_NAME}/openstack-k8s-operators-ci")
774+
775+
if [ $? -ne 0 ]; then
776+
echo "::error::Failed to create pull request"
777+
exit 1
778+
fi
779+
780+
echo "✅ Pull request created successfully: ${PR_URL}"
781+
fi
782+
else
783+
echo "No changes detected in openstack-k8s-operators-ci. Skipping pull request creation."
784+
fi
711785
712786
cd .. && rm -rf "$TEMP_DIR"
713-
echo "Workflow finished."
714787
715788
retag-and-push-rabbitmq-cluster-operator-index:
716789
# Only run if not a dry run, parameter is enabled, and create-branches job succeeded

feature_branch_repos.txt

Lines changed: 0 additions & 37 deletions
This file was deleted.

feature_branch_repos.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Configuration for repositories to create feature branches in
2+
# Each repository can have the following options:
3+
# - name: (required) The repository name
4+
# - skip_makefile_changes: (optional) If true, skip updating BRANCH variable in Makefile
5+
#
6+
# Example:
7+
# - name: my-repo
8+
# skip_makefile_changes: true
9+
10+
repos:
11+
- name: architecture
12+
- name: barbican-operator
13+
- name: ci-framework
14+
- name: cinder-operator
15+
- name: data-plane-adoption
16+
- name: designate-operator
17+
- name: edpm-ansible
18+
- name: glance-operator
19+
- name: heat-operator
20+
- name: horizon-operator
21+
- name: infra-operator
22+
- name: install_yamls
23+
- name: ironic-operator
24+
- name: keystone-operator
25+
- name: lib-common
26+
- name: manila-operator
27+
- name: mariadb-operator
28+
- name: mysqld_exporter
29+
- name: neutron-operator
30+
- name: nova-operator
31+
- name: octavia-operator
32+
- name: openstack-baremetal-operator
33+
- name: openstack-must-gather
34+
- name: openstack-network-exporter
35+
- name: openstack-operator
36+
- name: ovn-operator
37+
- name: placement-operator
38+
- name: prometheus-podman-exporter
39+
skip_makefile_changes: true
40+
- name: sg-core
41+
skip_makefile_changes: true
42+
- name: swift-operator
43+
- name: telemetry-operator
44+
- name: test-operator
45+
- name: watcher-operator

0 commit comments

Comments
 (0)