Skip to content

Commit

Permalink
TRT-1573: a29y special handling for ocp-build-data (#53627)
Browse files Browse the repository at this point in the history
a29y gets applied to all branches for ocp-build-data because the tide
branching manager is a little naive. This affects zstreams which ART has
asked us not to do, and to only apply a29y to the release we're
interested in.

This adds a hacky python script to manpiulate the YAML.  You'll now need
to invoke a29y with a `RELEASE=4.17` option,

e.g.:

    make acknowledge-critical-fixes-only RELEASE=4.17

Same when unreverting.

Co-authored-by: Luke Meyer <sosiouxme@gmail.com>
  • Loading branch information
stbenjam and sosiouxme committed Jul 5, 2024
1 parent bc4e19a commit f219299
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,25 @@ prow-config: message
$(CONTAINER_ENGINE) run $(CONTAINER_ENGINE_OPTS) $(CONTAINER_USER) --rm -v "$(CURDIR)/core-services/prow/02_config:/config$(VOLUME_MOUNT_FLAGS)" quay-proxy.ci.openshift.org/openshift/ci:ci_determinize-prow-config_latest --prow-config-dir /config --sharded-prow-config-base-dir /config --sharded-plugin-config-base-dir /config

acknowledge-critical-fixes-only: message
@if [ -z "$(RELEASE)" ]; then \
echo "RELEASE is not specified. Please specify RELEASE=x.y"; \
exit 1; \
fi
./hack/generate-acknowledge-critical-fixes-repo-list.sh
# ocp-build-data is special
./hack/acknowledge_critical_fix_repos_single_repo.py openshift-eng/ocp-build-data openshift-$(RELEASE) --apply
$(eval REPOS ?= ./hack/acknowledge-critical-fix-repos.txt)
$(SKIP_PULL) || $(CONTAINER_ENGINE) pull $(CONTAINER_ENGINE_OPTS) quay-proxy.ci.openshift.org/openshift/ci:ci_tide-config-manager_latest
$(CONTAINER_ENGINE) run $(CONTAINER_ENGINE_OPTS) $(CONTAINER_USER) --rm -v "$(CURDIR)/core-services/prow/02_config:/config$(VOLUME_MOUNT_FLAGS)" -v "$(REPOS):/repos" quay-proxy.ci.openshift.org/openshift/ci:ci_tide-config-manager_latest --prow-config-dir /config --sharded-prow-config-base-dir /config --lifecycle-phase acknowledge-critical-fixes-only --repos-guarded-by-ack-critical-fixes /repos
$(MAKE) prow-config

revert-acknowledge-critical-fixes-only: message
@if [ -z "$(RELEASE)" ]; then \
echo "RELEASE is not specified. Please specify RELEASE=x.y"; \
exit 1; \
fi
# ocp-build-data is special
./hack/acknowledge_critical_fix_repos_single_repo.py openshift-eng/ocp-build-data openshift-$(RELEASE) --revert
$(SKIP_PULL) || $(CONTAINER_ENGINE) pull $(CONTAINER_ENGINE_OPTS) quay-proxy.ci.openshift.org/openshift/ci:ci_tide-config-manager_latest
$(CONTAINER_ENGINE) run $(CONTAINER_ENGINE_OPTS) $(CONTAINER_USER) --rm -v "$(CURDIR)/core-services/prow/02_config:/config$(VOLUME_MOUNT_FLAGS)" quay-proxy.ci.openshift.org/openshift/ci:ci_tide-config-manager_latest --prow-config-dir /config --sharded-prow-config-base-dir /config --lifecycle-phase revert-critical-fixes-only
$(MAKE) prow-config
Expand Down
68 changes: 68 additions & 0 deletions hack/acknowledge_critical_fix_repos_single_repo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python3
"""This script handles turning on acknowledge-critical-fixes-only for a
single branch on a single repository."""
import copy
import sys
import os
import yaml

def split_out_branch(repo, branch_to_split, revert=False):
"""Splits out branch from a prow config"""
script_dir = os.path.dirname(os.path.realpath(__file__))
yaml_file = os.path.join(script_dir,
"../core-services/prow/02_config", repo, "_prowconfig.yaml")

# Check if the file exists
if not os.path.isfile(yaml_file):
print(f"YAML file not found: {yaml_file}")
sys.exit(1)

with open(yaml_file, 'r', encoding='utf-8') as file:
config = yaml.safe_load(file)

if revert:
new_queries = []
for query in config['tide']['queries']:
if 'includedBranches' in query and branch_to_split in query['includedBranches']:
if len(query['includedBranches']) == 1:
continue # Remove this query as it's the split-out branch
query['includedBranches'].remove(branch_to_split)
new_queries.append(query)

# Add the branch back to the original query
new_queries[0]['includedBranches'].append(branch_to_split)
config['tide']['queries'] = new_queries
else:
queries = config['tide']['queries'][0] # Don't assume it's the only one
new_query = copy.deepcopy(queries)

if branch_to_split in queries['includedBranches']:
queries['includedBranches'].remove(branch_to_split)
new_query['includedBranches'] = [branch_to_split]
new_query['labels'].append('acknowledge-critical-fixes-only')
config['tide']['queries'].append(new_query)
else:
print(f"Branch '{branch_to_split}' not found in the includedBranches.")
return

with open(yaml_file, 'w', encoding='utf-8') as file:
yaml.safe_dump(config, file, default_flow_style=False, sort_keys=False)

print(f"Updated YAML written to {yaml_file}")

if __name__ == "__main__":
if len(sys.argv) != 4:
print("Usage: python script.py <repo> <branch_to_split> <--apply|--revert>")
sys.exit(1)

arg_repo = sys.argv[1]
arg_branch_to_split = sys.argv[2]
arg_action = sys.argv[3]

if arg_action == "--apply":
split_out_branch(arg_repo, arg_branch_to_split)
elif arg_action == "--revert":
split_out_branch(arg_repo, arg_branch_to_split, revert=True)
else:
print("Invalid action. Use --apply to apply changes or --revert to revert changes.")
sys.exit(1)
2 changes: 1 addition & 1 deletion hack/generate-acknowledge-critical-fixes-repo-list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -eo pipefail
echo "Generating updated list of repos for acknowledge-critical-fixes-only..."

# Manually added repos (space-separated list)
MANUALLY_ADDED_REPOS="openshift/os openshift-eng/ocp-build-data openshift-eng/art-tools"
MANUALLY_ADDED_REPOS="openshift/os openshift-eng/art-tools"

# Function to display usage
usage() {
Expand Down

0 comments on commit f219299

Please sign in to comment.