-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathgenerate-acknowledge-critical-fixes-repo-list.sh
executable file
·53 lines (42 loc) · 2.26 KB
/
generate-acknowledge-critical-fixes-repo-list.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# Script to extract GitHub org/repo from the specified payload or latest
# release if no payload is provided. Used for locking down repos that
# come from the release payload.
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/art-tools"
# Function to display usage
usage() {
echo "Usage: $0 [PAYLOAD] [OUTPUT_FILE]"
echo "PAYLOAD: Optional. The payload to process."
echo "OUTPUT_FILE: Optional. File to write the results to. Default is 'acknowledge-critical-fix-repos.txt'."
}
# Function to fetch the latest release payload
fetch_latest_payload() {
local releases_json=$(curl -s "https://sippy.dptools.openshift.org/api/releases")
local latest_release=$(echo "$releases_json" | jq -r '.releases[0]')
local latest_release_info=$(curl -s "https://amd64.ocp.releases.ci.openshift.org/api/v1/releasestream/$latest_release.0-0.nightly/latest")
local pull_spec=$(echo "$latest_release_info" | jq -r '.pullSpec')
echo "$pull_spec"
}
PAYLOAD=${1:-$(fetch_latest_payload)}
OUTPUT_FILE=${2:-$(dirname "${BASH_SOURCE[0]}")/acknowledge-critical-fix-repos.txt} # Default output file
# Check if the payload fetching failed
if [ -z "$PAYLOAD" ]; then
echo "Error: Failed to fetch the latest release payload."
exit 1
fi
# Extract and process the information
EXTRACTED_INFO=$(oc adm release info "$PAYLOAD" -o json | jq -r '.references.spec.tags[] | select(.annotations."io.openshift.build.source-location" != "") | .annotations."io.openshift.build.source-location" | capture("https://github.com/(?<org>[^/]+)/(?<repo>[^/]+)") | "\(.org)/\(.repo)"' | sort -u)
# Combine manually added repos with extracted ones and remove duplicates
COMBINED_INFO=$(echo -e "$(echo -e "$MANUALLY_ADDED_REPOS" | sed 's/[[:space:]]\+/\n/g')\n$EXTRACTED_INFO" | sort -u | sed '/^$/d')
# Check if the extraction was successful
if [ -z "$COMBINED_INFO" ]; then
echo "Error: Failed to extract or combine information."
exit 2
fi
# Output the results
echo "# This was generated by ${BASH_SOURCE[0]} on $(date)" > $OUTPUT_FILE
echo "$COMBINED_INFO" >> "$OUTPUT_FILE"
echo "Extracted and manually added GitHub org/repo written to $OUTPUT_FILE"