Skip to content

Commit

Permalink
improve shell scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
AjayJagan committed May 3, 2024
1 parent 1a20447 commit ec0484a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/actions/update-manifest-branches/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ runs:
script({github, core})
- name: Update versions
shell: bash
run: ./.github/scripts/update-manifests-tags.sh ${{ env.CODEFLARE }} ${{ env.KUBERAY }} ${{ env.KUEUE }} ${{ env.DSP }} ${{ env.DASHBOARD }} ${{ env.NOTEBOOK-CONTROLLER }} ${{ env.NOTEBOOK-CONTROLLER }} ${{ env.NOTEBOOKS }} ${{ env.TRUSTYAI }} ${{ env.MODELMESH }} ${{ env.ODH-MODEL-CONTROLLER }} ${{ env.KSERVE }} ${{ env.MODEL-REGISTRY }}
run: ./.github/scripts/update-manifests-tags.sh
6 changes: 1 addition & 5 deletions .github/scripts/get-component-release-notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = ({ github, core }) => {
'Accept': 'application/vnd.github.text+json'
}
}).then((result) => {
const allowedComponents = ["dashboard", "notebooks", "notebook-controller", "trustyai", "kserve", "modelmesh-serving", "model-registry", "kueue", "codeflare", "kuberay", "dsp"]
let outputStr = "## Component Release Notes\n"
result.data.forEach((issue) => {
issueCommentBody = issue.body_text
Expand All @@ -24,9 +23,7 @@ module.exports = ({ github, core }) => {
components = components.splice(2, components.length - 1)
components.forEach(component => {
[componentName, branchUrl, tagUrl] = component.split("|")
if (allowedComponents.includes(componentName)) {
outputStr += `- **${componentName.charAt(0).toUpperCase() + componentName.slice(1)}**: ${tagUrl}\n`
}
})
}
})
Expand All @@ -35,5 +32,4 @@ module.exports = ({ github, core }) => {
}).catch(e => {
core.setFailed(`Action failed with error ${e}`);
})
}

}
10 changes: 7 additions & 3 deletions .github/scripts/get-release-branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ module.exports = ({ github, core }) => {
const splitArr = branchUrl.split("/")
const idx = splitArr.indexOf("tree")
const branchName = splitArr.slice(idx + 1).join("/")
core.exportVariable(componentName.toUpperCase(), branchName);
if(componentName === "notebook-controller"){
core.exportVariable("component_spec_odh-notebook-controller".toLowerCase(), branchName);
core.exportVariable("component_spec_kf-notebook-controller".toLowerCase(), branchName);
}else{
core.exportVariable("component_spec_"+componentName.toLowerCase(), branchName);
}
})
}
})
console.log("Read release/tag from tracker issue successfully...")
}).catch(e => {
core.setFailed(`Action failed with error ${e}`);
})
}

}
37 changes: 8 additions & 29 deletions .github/scripts/update-manifests-tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,15 @@
set -euo pipefail

update_tags(){
MANIFEST_STR=$(cat get_all_manifests.sh | grep $1 | sed 's/ //g')
readarray -d ":" -t STR_ARR <<< "$MANIFEST_STR"
RES=""
for i in "${!STR_ARR[@]}"; do
if [ $i == 2 ]; then
RES+=$2":"
else
RES+=${STR_ARR[$i]}":"
fi
done
echo "${RES::-2}"
sed -i -r "s|.*$1.*| ${RES::-2}|" get_all_manifests.sh
sed -i -r "/\"$1\"/s|([^:]*):([^:]*):[^:]*:(.*)|\1:\2:$2:\3|" get_all_manifests.sh
}

declare -A COMPONENT_VERSION_MAP=(
["\"codeflare\""]=$1
["\"ray\""]=$2
["\"kueue\""]=$3
["\"data-science-pipelines-operator\""]=$4
["\"odh-dashboard\""]=$5
["\"kf-notebook-controller\""]=$6
["\"odh-notebook-controller\""]=$7
["\"notebooks\""]=$8
["\"trustyai\""]=$9
["\"model-mesh\""]=$10
["\"odh-model-controller\""]=$11
["\"kserve\""]=$12
["\"modelregistry\""]=$13
)
prefix=component_spec_

for key in ${!COMPONENT_VERSION_MAP[@]}; do
update_tags ${key} ${COMPONENT_VERSION_MAP[${key}]}
echo
env | while IFS="=" read varname value; do
[[ $varname =~ "${prefix}" ]] || continue
component=${varname#${prefix}}
component=${component/_/-}
update_tags $component $value
done
28 changes: 14 additions & 14 deletions .github/scripts/wait-for-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
#
# @param $1 - PR number or URL
# wait for a bit until pr is created, otherwise it throws an error "no checks reported on the 'odh-release/e2e-test' branch"
set -euo pipefail
set -euo

sleep 10

while [ $(gh pr checks "$1" | grep -v 'tide' | grep 'pending' | wc -m) -gt 0 ]; do
printf "PR checks still pending, retrying in 10 seconds...\n"
sleep 30 # replace with 60000
done
pr_has_status() {
local pr=$1
local status=$2
local skip=${3:-tide}

if [ $(gh pr checks "$1" | grep 'fail' | wc -m) -gt 0 ]; then
printf "!!PR checks failed!!\n"
exit 1
fi
gh pr checks $pr | awk -v FS=$'\t' -v status=$status "\$1 ~ /$skip/{next} \$2 == status {found=1} END {if (!found) exit 1}"
}

if [ $(gh pr checks "$1" | grep 'pass' | wc -m) -gt 0 ]; then
printf "!!PR checks passed!!\n"
exit 0
fi
while pr_has_status $1 pending; do
echo "PR checks still pending, retrying in 10 seconds..."
sleep 60000
done

printf "!!An unknown error occurred!!\n"
pr_has_status $1 fail && { echo "!!PR checks failed!!"; exit 1; }
pr_has_status $1 pass && { echo "!!PR checks passed!!"; exit 0; }
echo "!!An unknown error occurred!!"
exit 1
20 changes: 10 additions & 10 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
body-includes: "#Release#"
- name: Set version/tracker-url in env
run: |
echo "VERSION=$(echo "${{ steps.fc.outputs.comment-body }}" | grep version | cut -d "=" -f2)" >> $GITHUB_ENV
echo "TRACKER_URL=$(echo "${{ steps.fc.outputs.comment-body }}" | grep tracker-url | cut -d "=" -f2)" >> $GITHUB_ENV
echo "VERSION=$(echo "${{ steps.fc.outputs.comment-body }}" | awk -F= '$1 ~ /version$/{print $2}')" >> $GITHUB_ENV
echo "TRACKER_URL=$(echo "${{ steps.fc.outputs.comment-body }}" | awk -F= '$1 ~ /tracker-url$/{print $2}')" >> $GITHUB_ENV
- uses: fregante/setup-git-user@v2
- name: Create and push version tags
run: |
Expand All @@ -50,15 +50,15 @@ jobs:
name: Create community operators prod pr # https://github.com/redhat-openshift-ecosystem/community-operators-prod
runs-on: ubuntu-latest
steps:
- uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Set env variables
uses: opendatahub-io/opendatahub-operator/.github/actions/set-shared-env@incubation
- name: Get release data from pr
uses: peter-evans/find-comment@v3
id: fc
with:
pat-token: ${{ steps.generate-token.outputs.token }}
issue-number: ${{ github.event.pull_request.number }}
body-includes: "#Release#"
- name: Set version/tracker-url in env
run: |
echo "VERSION=$(echo "${{ steps.fc.outputs.comment-body }}" | awk -F= '$1 ~ /version$/{print $2}')" >> $GITHUB_ENV
- name: Checkout opendatahub-operator
uses: actions/checkout@v4
with:
Expand Down

0 comments on commit ec0484a

Please sign in to comment.