Skip to content

Commit 24021ca

Browse files
add an automated CI workflow to sync ODH-notebooks with Codeflare-SDK release
1 parent d85339b commit 24021ca

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# The aim of this GitHub workflow is to update the pipfile to sync with Codeflare-SDK release.
2+
name: Sync with codeflare-sdk release
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
upstream-repository-organization:
7+
required: false
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: false
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
55+
run: pip install pipenv
56+
57+
- name: Update Pipfiles in accordance with Codeflare-SDK latest release
58+
run: |
59+
# list all Pipfile paths having Codeflare-SDK listed
60+
paths+=($(grep -rl 'codeflare-sdk = "~=.*"'))
61+
# Extracting only directories from file paths, excluding a `.gitworkflow` directory
62+
directories=()
63+
exclude_directories=(
64+
".git/objects/pack"
65+
".github/workflows/",
66+
)
67+
for path in "${paths[@]}"; do
68+
current_dir=$(dirname "$path")
69+
#Check if current_dir is not in exclude_directories list
70+
if [[ ! "${exclude_directories[@]}" =~ "$current_dir" ]]; then
71+
#Check if Pipfile exists in current_dir
72+
if [ -f "$current_dir/Pipfile" ];then
73+
directories+=("$current_dir")
74+
fi
75+
fi
76+
done
77+
# Remove duplicates
78+
directories=($(echo "${directories[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
79+
# Print the directories for verification
80+
echo "Directories (Start updating Pipfile in these below directories in accordance with Codeflare-SDK latest release):"
81+
for dir in "${directories[@]}"; do
82+
echo "- $dir"
83+
done
84+
# iterate over the directories and update Pipfile
85+
counter=0
86+
total=${#directories[@]}
87+
for dir in "${directories[@]}"; do
88+
counter=$((counter+1))
89+
echo "--Processing directory $counter '$dir' of total $total"
90+
cd "$dir" && pipenv install codeflare-sdk~="${CODEFLARE_RELEASE_VERSION}" && pipenv --rm && cd -
91+
echo "$((total-counter)) directories remaining.."
92+
done
93+
94+
- name: Push changes
95+
run: |
96+
cd $REPO_NAME
97+
git add . && git status && git checkout -b ${{ env.UPDATER_BRANCH }} && \
98+
git commit -am "Updated notebooks via ${{ env.UPDATER_BRANCH }} GitHub action" --signoff &&
99+
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$REPO_OWNER/$REPO_NAME.git
100+
git push origin ${{ env.UPDATER_BRANCH }}
101+
102+
- name: Create Pull Request
103+
run: |
104+
gh pr create --repo $UPSTREAM_OWNER/$REPO_NAME \
105+
--title "$pr_title" \
106+
--body "$pr_body" \
107+
--head $REPO_OWNER:$UPDATER_BRANCH \
108+
--base $BRANCH_NAME
109+
env:
110+
pr_title: "[Digest Updater Action] Update notebook's pipfile to sync with Codeflare-SDK release"
111+
pr_body: |
112+
:rocket: This is an automated Pull Request.
113+
114+
This PR updates the `Pipfile` to sync with latest Codeflare-SDK release.
115+
116+
:exclamation: **IMPORTANT NOTE**: Remember to delete the ` ${{ env.UPDATER_BRANCH }}` branch after merging the changes

.github/workflows/project-codeflare-release.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ on:
3838
description: 'Owner of target community-operators-prod repository used to open a PR against'
3939
required: true
4040
default: 'redhat-openshift-ecosystem'
41+
upstream-repository-organization:
42+
description: 'Owner of target upstream notebooks repository used to open a PR against'
43+
required: false
44+
default: 'opendatahub-io'
4145

4246
jobs:
4347
release-parameters:
@@ -152,6 +156,19 @@ jobs:
152156
shell: bash
153157
if: ${{ env.SDK_RELEASE_STATUS_CODE != '200' }}
154158

159+
- name: Sync ODH Notebooks
160+
run: |
161+
gh workflow run odh-notebooks-sync.yml \
162+
--repo ${{ github.event.inputs.codeflare-repository-organization }}/codeflare-operator \
163+
--ref ${{ github.ref }} \
164+
--field upstream-repository-organization=${{ github.event.inputs.upstream-repository-organization }}
165+
--field codeflare-repository-organization=${{ github.event.inputs.codeflare-repository-organization }} \
166+
--field codeflare_sdk_release_version=${{ github.event.inputs.codeflare-sdk-version }}
167+
env:
168+
GITHUB_TOKEN: ${{ secrets.CODEFLARE_MACHINE_ACCOUNT_TOKEN }}
169+
shell: bash
170+
if: ${{ env.SDK_RELEASE_STATUS_CODE == '200' }}
171+
155172
release-codeflare-operator:
156173
needs: [release-mcad, release-instascale, release-codeflare-sdk]
157174
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)