Skip to content

Commit 62ea11d

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

File tree

2 files changed

+126
-0
lines changed

2 files changed

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

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ jobs:
152152
shell: bash
153153
if: ${{ env.SDK_RELEASE_STATUS_CODE != '200' }}
154154

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

0 commit comments

Comments
 (0)