@@ -44,6 +44,28 @@ atexit_handler() {
4444 fi
4545}
4646
47+ github_app_token () {
48+ local -r jwt=" $1 "
49+ local -r repo=" $2 "
50+
51+ local install_id
52+ install_id=" $( curl -s \
53+ -H " Authorization: Bearer ${jwt} " \
54+ -H " Accept: application/vnd.github+json" \
55+ " https://api.github.com/repos/${repo} /installation" \
56+ | jq -r ' .id' ) "
57+ if [ -z " ${install_id} " ] || [ " ${install_id} " = " null" ]; then
58+ echo " ERROR: Failed to get installation ID for ${repo} " >&2
59+ return 1
60+ fi
61+
62+ curl -s -X POST \
63+ -H " Authorization: Bearer ${jwt} " \
64+ -H " Accept: application/vnd.github+json" \
65+ " https://api.github.com/app/installations/${install_id} /access_tokens" \
66+ | jq -r ' .token'
67+ }
68+
4769load_secrets () {
4870 # Disable command tracing to prevent leaking credentials in logs
4971 # and restore it after the secrets are loaded
@@ -56,24 +78,39 @@ load_secrets() {
5678 local -r app_sha=" 867d9ebf7dd18e67e2599f0f890f3f41b8673e88c4394a32a05476024c41ea0f"
5779 local -r app_exe=" /tmp/gh-token-${app_ver} "
5880
59- # Install a GitHub CLI extension to generate tokens for GitHub Apps
60- curl -sSL https://github.com/Link-/gh-token/releases/download/v${app_ver} /linux-amd64 -o " ${app_exe} "
81+ curl -sSL \
82+ " https://github.com/Link-/gh-token/releases/download/v${app_ver} /linux-amd64" \
83+ -o " ${app_exe} "
6184 if ! echo " ${app_sha} ${app_exe} " | sha256sum -c -; then
6285 echo " ERROR: Failed to verify GitHub CLI extension checksum"
63- exit 1
86+ return 1
6487 fi
6588 chmod +x " ${app_exe} "
6689
67- # Generate a GitHub token for the GitHub App
68- GITHUB_TOKEN=" $( " ${app_exe} " generate --app-id " $( < " ${GITHUB_APP_ID_PATH} " ) " --key " ${GITHUB_KEY_PATH} " | jq -r ' .token' ) "
69- if [ -z " ${GITHUB_TOKEN} " ] || [ " ${GITHUB_TOKEN} " = " null" ]; then
70- echo " ERROR: Failed to generate GitHub token"
71- exit 1
90+ GITHUB_APP_JWT=" $( " ${app_exe} " generate \
91+ --app-id " $( < " ${GITHUB_APP_ID_PATH} " ) " \
92+ --key " ${GITHUB_KEY_PATH} " \
93+ --jwt \
94+ --token-only) "
95+ if [ -z " ${GITHUB_APP_JWT} " ]; then
96+ echo " ERROR: Failed to generate GitHub App JWT"
97+ return 1
7298 fi
7399 rm -f " ${app_exe} "
74100
75- export GITHUB_TOKEN
76- echo " GitHub token generated."
101+ GITHUB_TOKEN_USHIFT=" $( github_app_token " ${GITHUB_APP_JWT} " openshift/microshift) "
102+ if [ -z " ${GITHUB_TOKEN_USHIFT} " ] || [ " ${GITHUB_TOKEN_USHIFT} " = " null" ]; then
103+ echo " ERROR: Failed to generate installation access token for openshift/microshift"
104+ return 1
105+ fi
106+
107+ GITHUB_TOKEN_EDGE=" $( github_app_token " ${GITHUB_APP_JWT} " openshift-eng/edge-tooling) "
108+ if [ -z " ${GITHUB_TOKEN_EDGE} " ] || [ " ${GITHUB_TOKEN_EDGE} " = " null" ]; then
109+ echo " ERROR: Failed to generate installation access token for openshift-eng/edge-tooling"
110+ return 1
111+ fi
112+
113+ echo " GitHub tokens generated."
77114 else
78115 echo " WARNING: GitHub App credentials not found at ${GITHUB_APP_ID_PATH} and ${GITHUB_KEY_PATH} . GitHub operations will not be available."
79116 fi
@@ -96,12 +133,20 @@ load_secrets() {
96133}
97134
98135install_prerequisites () {
99- echo " Installing gcloud CLI..."
136+ # Export the PATH to include the local bin directory
137+ export PATH=" ${HOME} /.local/bin:${PATH} "
100138
139+ echo " Installing gcloud CLI..."
101140 curl -sSL https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-linux-x86_64.tar.gz | tar -xz -C /tmp
102141 /tmp/google-cloud-sdk/install.sh --quiet --path-update true
103142 export PATH=" /tmp/google-cloud-sdk/bin:${PATH} "
104143 echo " gcloud CLI installed."
144+
145+ echo " Installing Python package dependencies..."
146+ pip install --user \
147+ ' uv==0.11.6' \
148+ ' matplotlib==3.9.4'
149+ echo " Python package dependencies installed."
105150}
106151
107152wait_for_mcp_status () {
167212 # Configure JIRA MCP
168213 if [[ -n " ${JIRA_API_TOKEN:- } " ]] && [[ -n " ${JIRA_USERNAME:- } " ]]; then
169214 echo " Configuring JIRA MCP..."
170-
171- # Install uv to manage MCP dependencies
172- pip install uv --user --upgrade
173- export PATH=" ${HOME} /.local/bin:${PATH} "
174-
175215 claude mcp add \
176216 -e JIRA_URL=" ${JIRA_URL} " \
177217 -e JIRA_API_TOKEN=" ${JIRA_API_TOKEN} " \
@@ -210,9 +250,13 @@ configure_claude
210250# microshift-ci skills and run analysis on all releases and open pull requests
211251SRC_DIR=" /tmp/edge-tooling"
212252EXE_DIR=" ${SRC_DIR} /plugins/microshift-ci/scripts"
253+ { set +x; export GITHUB_TOKEN=" ${GITHUB_TOKEN_EDGE} " ; set -x; }
213254gh repo clone openshift-eng/edge-tooling " ${SRC_DIR} " -- --branch main
214255cd " ${SRC_DIR} "
215256
257+ # The rest of the script runs with the MicroShift GitHub token
258+ { set +x; export GITHUB_TOKEN=" ${GITHUB_TOKEN_USHIFT} " ; set -x; }
259+
216260# Run analysis on all releases and open rebase PRs.
217261# Time-box analysis and limit turns to avoid uncontrolled billable minutes.
218262echo " Running Claude to analyze MicroShift CI jobs and pull requests..."
0 commit comments