Skip to content

Commit 3edc728

Browse files
Bobbins228abhijeet-dhumal
authored andcommitted
add an automated CI workflow to sync ODH-notebooks with latest codeflare-sdk release
1 parent 90c45b8 commit 3edc728

File tree

2 files changed

+144
-0
lines changed

2 files changed

+144
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# The aim of this GitHub workflow is to update the pipfile to sync with Codeflare-SDK release.
2+
name: Sync ODH-notebooks with codeflare-sdk release
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
upstream-repository-organization:
7+
required: true
8+
description: "Owner of target upstream notebooks repository used to open a PR against"
9+
default: "opendatahub-io"
10+
11+
codeflare-repository-organization:
12+
required: true
13+
description: "Owner of origin notebooks repository used to open a PR"
14+
default: "project-codeflare"
15+
16+
codeflare_sdk_release_version:
17+
required: true
18+
description: "Provide version of the Codeflare-SDK release"
19+
20+
env:
21+
BRANCH_NAME: main
22+
CODEFLARE_RELEASE_VERSION: ${{ github.event.inputs.codeflare_sdk_release_version }}
23+
UPDATER_BRANCH: odh-sync-updater-${{ github.run_id }}
24+
UPSTREAM_OWNER: ${{ github.event.inputs.upstream-repository-organization }}
25+
REPO_OWNER: ${{ github.event.inputs.codeflare-repository-organization }}
26+
REPO_NAME: notebooks
27+
GITHUB_TOKEN: ${{ secrets.CODEFLARE_MACHINE_ACCOUNT_TOKEN }}
28+
29+
jobs:
30+
build:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v4
34+
with:
35+
ref: ${{ env.BRANCH_NAME }}
36+
37+
- name: Clone repository and Sync
38+
run: |
39+
git clone https://x-access-token:${GITHUB_TOKEN}@github.com/$REPO_OWNER/$REPO_NAME.git $REPO_NAME
40+
cd $REPO_NAME
41+
git remote add upstream https://github.com/$UPSTREAM_OWNER/$REPO_NAME.git
42+
git config --global user.email "[email protected]"
43+
git config --global user.name "codeflare-machine-account"
44+
git remote -v
45+
git pull upstream main && git push origin main
46+
47+
- name: Setup Python environment
48+
uses: actions/setup-python@v4
49+
with:
50+
python-version: |
51+
3.8
52+
3.9
53+
54+
- name: Install pipenv and pip-versions
55+
run: pip install pipenv pip-versions
56+
57+
- name: Update Pipfiles in accordance with Codeflare-SDK latest release
58+
run: |
59+
package_name=codeflare-sdk
60+
# Get the list of available versions for the package
61+
if ! versions=$(pipenv run pip-versions list $package_name);then
62+
echo "Failed to retrieve versions for $package_name"
63+
exit 1
64+
fi
65+
# Check if the desired version exists in the list
66+
if echo "$versions" | grep -q "${CODEFLARE_RELEASE_VERSION}"; then
67+
echo "Version ${CODEFLARE_RELEASE_VERSION} is available for $package_name"
68+
# list all Pipfile paths having Codeflare-SDK listed
69+
paths+=($(grep -rl "${package_name} = \"~=.*\""))
70+
# Extracting only directories from file paths, excluding a `.gitworkflow` directory
71+
directories=()
72+
exclude_directories=(
73+
".git/objects/pack"
74+
".github/workflows/",
75+
)
76+
for path in "${paths[@]}"; do
77+
current_dir=$(dirname "$path")
78+
#Check if current_dir is not in exclude_directories list
79+
if [[ ! "${exclude_directories[@]}" =~ "$current_dir" ]]; then
80+
#Check if Pipfile exists in current_dir
81+
if [ -f "$current_dir/Pipfile" ];then
82+
directories+=("$current_dir")
83+
fi
84+
fi
85+
done
86+
# Remove duplicates
87+
directories=($(echo "${directories[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
88+
# Print the directories for verification
89+
echo "Directories (Start updating Pipfile in these below directories in accordance with Codeflare-SDK latest release):"
90+
for dir in "${directories[@]}"; do
91+
echo "- $dir"
92+
done
93+
# iterate over the directories and update Pipfile
94+
counter=0
95+
total=${#directories[@]}
96+
for dir in "${directories[@]}"; do
97+
counter=$((counter+1))
98+
echo "--Processing directory $counter '$dir' of total $total"
99+
cd "$dir" && pipenv install ${package_name}~="${CODEFLARE_RELEASE_VERSION}" && pipenv --rm && cd -
100+
echo "$((total-counter)) directories remaining.."
101+
done
102+
else
103+
versions_list=$(echo "$versions" | tr '\n' ' ' | sed 's/, $//')
104+
versions="${versions_list%,}"
105+
echo "Version '${CODEFLARE_RELEASE_VERSION}' is not available for $package_name"
106+
echo "Available versions for $package_name: $versions"
107+
exit 1
108+
fi
109+
110+
- name: Push changes
111+
run: |
112+
cd $REPO_NAME
113+
git add . && git status && git checkout -b ${{ env.UPDATER_BRANCH }} && \
114+
git commit -am "Updated notebooks via ${{ env.UPDATER_BRANCH }} GitHub action" --signoff &&
115+
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$REPO_OWNER/$REPO_NAME.git
116+
git push origin ${{ env.UPDATER_BRANCH }}
117+
118+
- name: Create Pull Request
119+
run: |
120+
gh pr create --repo $UPSTREAM_OWNER/$REPO_NAME \
121+
--title "$pr_title" \
122+
--body "$pr_body" \
123+
--head $REPO_OWNER:$UPDATER_BRANCH \
124+
--base $BRANCH_NAME
125+
env:
126+
pr_title: "[Digest Updater Action] Update notebook's pipfile to sync with Codeflare-SDK release"
127+
pr_body: |
128+
:rocket: This is an automated Pull Request.
129+
130+
This PR updates the `Pipfile` to sync with latest Codeflare-SDK release.
131+
132+
:exclamation: **IMPORTANT NOTE**: Remember to delete the ` ${{ env.UPDATER_BRANCH }}` branch after merging the changes

.github/workflows/release.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,15 @@ jobs:
100100
env:
101101
GITHUB_TOKEN: ${{ secrets.CODEFLARE_MACHINE_ACCOUNT_TOKEN }}
102102
shell: bash
103+
104+
- name: Sync ODH Notebooks
105+
run: |
106+
gh workflow run odh-notebooks-sync.yml \
107+
--repo ${{ github.event.inputs.codeflare-repository-organization }}/codeflare-sdk \
108+
--ref ${{ github.ref }} \
109+
--field upstream-repository-organization=opendatahub-io
110+
--field codeflare-repository-organization=${{ github.event.inputs.codeflare-repository-organization }} \
111+
--field codeflare_sdk_release_version=${{ github.event.inputs.release-version }}
112+
env:
113+
GITHUB_TOKEN: ${{ secrets.CODEFLARE_MACHINE_ACCOUNT_TOKEN }}
114+
shell: bash

0 commit comments

Comments
 (0)