Skip to content

Commit de6cdd5

Browse files
add an automated CI workflow to sync ODH-notebooks with latest codeflare-sdk release
1 parent 90c45b8 commit de6cdd5

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
- name: Clone repository and Sync
34+
run: |
35+
git clone https://x-access-token:${GITHUB_TOKEN}@github.com/$REPO_OWNER/$REPO_NAME.git $REPO_NAME
36+
cd $REPO_NAME
37+
git remote add upstream https://github.com/$UPSTREAM_OWNER/$REPO_NAME.git
38+
git config --global user.email "[email protected]"
39+
git config --global user.name "codeflare-machine-account"
40+
git remote -v
41+
git pull upstream main && git push origin main
42+
43+
- name: Setup Python environment
44+
uses: actions/setup-python@v4
45+
with:
46+
python-version: |
47+
3.8
48+
3.9
49+
50+
- name: Install pipenv and pip-versions
51+
run: pip install pipenv pip-versions
52+
53+
- name: Update Pipfiles in accordance with Codeflare-SDK latest release
54+
run: |
55+
package_name=codeflare-sdk
56+
# Get the list of available versions for the package
57+
if ! versions=$(pipenv run pip-versions list $package_name);then
58+
echo "Failed to retrieve versions for $package_name"
59+
exit 1
60+
fi
61+
# Check if the desired version exists in the list
62+
if echo "$versions" | grep -q "${CODEFLARE_RELEASE_VERSION}"; then
63+
echo "Version ${CODEFLARE_RELEASE_VERSION} is available for $package_name"
64+
# list all Pipfile paths having Codeflare-SDK listed
65+
paths+=($(grep -rl "${package_name} = \"~=.*\""))
66+
# Extracting only directories from file paths, excluding a `.gitworkflow` directory
67+
directories=()
68+
exclude_directories=(
69+
".git/objects/pack"
70+
".github/workflows/",
71+
)
72+
for path in "${paths[@]}"; do
73+
current_dir=$(dirname "$path")
74+
#Check if current_dir is not in exclude_directories list
75+
if [[ ! "${exclude_directories[@]}" =~ "$current_dir" ]]; then
76+
#Check if Pipfile exists in current_dir
77+
if [ -f "$current_dir/Pipfile" ];then
78+
directories+=("$current_dir")
79+
fi
80+
fi
81+
done
82+
# Remove duplicates
83+
directories=($(echo "${directories[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
84+
# Print the directories for verification
85+
echo "Directories (Start updating Pipfile in these below directories in accordance with Codeflare-SDK latest release):"
86+
for dir in "${directories[@]}"; do
87+
echo "- $dir"
88+
done
89+
# iterate over the directories and update Pipfile
90+
counter=0
91+
total=${#directories[@]}
92+
for dir in "${directories[@]}"; do
93+
counter=$((counter+1))
94+
echo "--Processing directory $counter '$dir' of total $total"
95+
cd "$dir" && pipenv install ${package_name}~="${CODEFLARE_RELEASE_VERSION}" && pipenv --rm && cd -
96+
echo "$((total-counter)) directories remaining.."
97+
done
98+
else
99+
versions_list=$(echo "$versions" | tr '\n' ' ' | sed 's/, $//')
100+
versions="${versions_list%,}"
101+
echo "Version '${CODEFLARE_RELEASE_VERSION}' is not available for $package_name"
102+
echo "Available versions for $package_name: $versions"
103+
exit 1
104+
fi
105+
106+
- name: Push changes
107+
run: |
108+
cd $REPO_NAME
109+
git add . && git status && git checkout -b ${{ env.UPDATER_BRANCH }} && \
110+
git commit -am "Updated notebooks via ${{ env.UPDATER_BRANCH }} GitHub action" --signoff &&
111+
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$REPO_OWNER/$REPO_NAME.git
112+
git push origin ${{ env.UPDATER_BRANCH }}
113+
114+
- name: Create Pull Request
115+
run: |
116+
gh pr create --repo $UPSTREAM_OWNER/$REPO_NAME \
117+
--title "$pr_title" \
118+
--body "$pr_body" \
119+
--head $REPO_OWNER:$UPDATER_BRANCH \
120+
--base $BRANCH_NAME
121+
env:
122+
pr_title: "[Digest Updater Action] Update notebook's pipfile to sync with Codeflare-SDK release"
123+
pr_body: |
124+
:rocket: This is an automated Pull Request.
125+
126+
This PR updates the `Pipfile` to sync with latest Codeflare-SDK release.
127+
128+
: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)