Skip to content

Commit a19d8b2

Browse files
mtchoum1jiridanek
andauthored
[RHOAIENG-24973] [RHOAIENG-26615] Create workflows to automate notebook digest and buildconfig updates (opendatahub-io#1150)
* Created notebooks-digest-updater.yaml and update-buildconfigs.yaml to automate the release of notebooks with the github action call: Notebooks Release * Addressed Code Rabbit nitpicks and recommendations * fixup, correct YAML syntax by quoting `on` keys in workflows This commit updates `.github/workflows/notebooks-release.yaml` and `.github/workflows/update-buildconfigs.yaml` to ensure proper YAML syntax by quoting the `on` keys. * fixup, `notebooks-release.yaml` to use a relative path for `update-buildconfigs.yaml` action * fixup, `notebooks-release.yaml` to use a relative path for `notebooks-digest-updater.yaml` action * fixup, correct grammar in `description` field within `notebooks-digest-updater.yaml` workflow * fixup, grant `contents` and `pull-requests` write permissions for `notebooks-digest-updater.yaml` in `notebooks-release.yaml` workflow * fixup, grant `contents` and `pull-requests` write permissions for `update-buildconfigs.yaml` in `notebooks-release.yaml` workflow * fixup, use `${{ github.repository_owner }}` and `${{ github.event.repository.name }}` for dynamic organization and repository name in `notebooks-digest-updater.yaml` workflow env variables so that the action runs even on a fork * fixup, `notebooks-release.yaml` workflow dynamically use `${{ github.repository_owner }}` and `${{ github.event.repository.name }}` for `REPO_OWNER` and `REPO_NAME` env variables. * fixup, correct formatting for `VERSION` environment variable in `notebooks-release.yaml` workflow * Recreated notebooks-release.yaml and restored build-notebooks-push.yaml * Created create-release as a resuable workflow * Removed Trail and fix coderabbit true nitpicks --------- Co-authored-by: Jiri Daněk <[email protected]>
1 parent 859258d commit a19d8b2

File tree

6 files changed

+367
-5
lines changed

6 files changed

+367
-5
lines changed

.github/workflows/create-release.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
name: Create release
3+
permissions:
4+
contents: write
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
release_tag:
9+
description: "Release Tag:"
10+
required: true
11+
default: 'v1.32.0'
12+
type: string
13+
release_name:
14+
description: 'Name of the release'
15+
required: true
16+
default: '2025a'
17+
type: string
18+
branch:
19+
description: "Target Branch:"
20+
type: string
21+
default: "main"
22+
workflow_call:
23+
inputs:
24+
release_tag:
25+
description: "Release Tag:"
26+
required: true
27+
type: string
28+
release_name:
29+
description: "Release Name:"
30+
required: true
31+
type: string
32+
branch:
33+
description: "Target Branch:"
34+
type: string
35+
36+
env:
37+
RELEASE_TAG: ${{ inputs.release_tag }}
38+
RELEASE_NAME: ${{ inputs.release_name }}
39+
BRANCH: ${{ inputs.branch }}
40+
41+
jobs:
42+
release:
43+
name: Create opendatahub-io/notebooks release
44+
runs-on: ubuntu-latest
45+
steps:
46+
- name: Check out repository
47+
uses: actions/checkout@v4
48+
with:
49+
fetch-depth: 0
50+
- name: Generate notebooks release
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
working-directory: ${{env.GITHUB_WORKSPACE}}
54+
run: |
55+
gh release create "$RELEASE_TAG" --title="$RELEASE_NAME-$RELEASE_TAG" --generate-notes --target "$BRANCH"

.github/workflows/notebooks-digest-updater.yaml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,28 @@ on: # yamllint disable-line rule:truthy
88
branch:
99
required: false
1010
description: "Optional: Provide branch name"
11-
user-hash:
11+
type: string
12+
user_hash:
1213
required: false
13-
description: "Optional: Specify a Git hash (it should exists on the branch history)"
14+
description: "Optional: Specify a Git hash (it should exist in the branch history)"
15+
type: string
16+
workflow_call:
17+
inputs:
18+
branch:
19+
required: false
20+
description: "Optional: Provide branch name"
21+
type: string
22+
user_hash:
23+
required: false
24+
description: "Optional: Specify a Git hash (it should exist in the branch history)"
25+
type: string
1426

1527
env:
16-
USER_HASH: ${{ github.event.inputs.user-hash }}
28+
USER_HASH: ${{ inputs.user_hash }}
1729
REPO_ORG: ${{ github.repository_owner }}
18-
REPO_NAME: 'notebooks'
30+
REPO_NAME: ${{ github.event.repository.name }}
1931
TMP_BRANCH: tmp-digest-sync-${{ github.run_id }}
20-
BRANCH_NAME: ${{ github.event.inputs.branch || 'main' }}
32+
BRANCH_NAME: ${{ inputs.branch }}
2133

2234
jobs:
2335
update-images:
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
---
2+
name: Notebooks Release
3+
permissions:
4+
contents: write
5+
actions: read
6+
"on":
7+
workflow_dispatch:
8+
inputs:
9+
release_tag:
10+
description: 'Release tag for the notebooks release'
11+
required: true
12+
default: 'v1.32.0'
13+
type: string
14+
release_name:
15+
description: 'Name of the release'
16+
required: true
17+
default: '2025a'
18+
type: string
19+
buildconfigs_version:
20+
description: 'Version to update the BuildConfigs to (if applicable)'
21+
required: false
22+
type: string
23+
update_buildconfigs:
24+
description: 'Update BuildConfigs for CUDA RStudio and RStudio'
25+
required: true
26+
default: true
27+
type: boolean
28+
branch:
29+
description: "Optional: Provide branch name"
30+
required: false
31+
type: string
32+
default: "main"
33+
user_hash:
34+
description: "Optional: Specify a Git hash (it should exists on the branch history)"
35+
required: false
36+
type: string
37+
release_type:
38+
description: "Select the type of action to perform"
39+
required: true
40+
default: "Sync"
41+
type: choice
42+
options:
43+
- Sync
44+
- Release
45+
46+
env:
47+
RELEASE_TAG: ${{ github.event.inputs.release_tag }}
48+
RELEASE_NAME: ${{ github.event.inputs.release_name }}
49+
BRANCH: ${{ github.event.inputs.branch }}
50+
USER_HASH: ${{ github.event.inputs.user_hash }}
51+
REPO_OWNER: ${{ github.repository_owner }}
52+
REPO_NAME: ${{ github.event.repository.name }}
53+
VERSION: ${{ github.event.inputs.buildconfigs_version }}
54+
55+
jobs:
56+
# 1. Update the params-latest.env and commit-latest.env files with new SHAs
57+
Update_manifests:
58+
# grant the permissions that notebooks-digest-updater.yaml needs
59+
permissions:
60+
contents: write
61+
pull-requests: write
62+
uses: ./.github/workflows/notebooks-digest-updater.yaml
63+
with:
64+
branch: ${{ github.event.inputs.branch }}
65+
user_hash: ${{ github.event.inputs.user_hash }}
66+
67+
# 2. Check if the Manifest PR is merged
68+
Manifests_merged:
69+
needs: Update_manifests
70+
runs-on: ubuntu-latest
71+
outputs:
72+
pr_merged_m: ${{ steps.check_pr.outputs.pr_merged }}
73+
steps:
74+
- name: Check out repository
75+
uses: actions/checkout@v4
76+
with:
77+
fetch-depth: 0
78+
79+
- name: Check if PR is merged
80+
id: check_pr
81+
env:
82+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
working-directory: ${{env.GITHUB_WORKSPACE}}
84+
run: |
85+
bash "${GITHUB_WORKSPACE}/ci/check-pr-merged.sh" "[Updater Action] Update Notebook and Runtime Images as well as the Commits With New SHAs" "${REPO_OWNER}" "${REPO_NAME}"
86+
87+
# 3. Update the BuildConfigs for CUDA RStudio and RStudio
88+
Update_buildConfigs:
89+
if: ${{ inputs.update_buildconfigs && github.event.inputs.release_type == 'Release' }}
90+
# grant the permissions that update-buildconfigs.yaml needs
91+
permissions:
92+
contents: write
93+
pull-requests: write
94+
uses: ./.github/workflows/update-buildconfigs.yaml
95+
with:
96+
branch: ${{ github.event.inputs.branch }}
97+
version: ${{ github.event.inputs.buildconfigs_version }}
98+
99+
# 4. Check if the BuildConfigs PR is merged
100+
BuildConfigs_merged:
101+
needs: Update_buildConfigs
102+
if: ${{ inputs.update_buildconfigs && github.event.inputs.release_type == 'Release' }}
103+
runs-on: ubuntu-latest
104+
outputs:
105+
pr_merged_b: ${{ steps.check_pr.outputs.pr_merged }}
106+
steps:
107+
- name: Check out repository
108+
uses: actions/checkout@v4
109+
with:
110+
fetch-depth: 0
111+
112+
- name: Check if PR is merged
113+
id: check_pr
114+
env:
115+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116+
working-directory: ${{env.GITHUB_WORKSPACE}}
117+
run: |
118+
bash "${GITHUB_WORKSPACE}/ci/check-pr-merged.sh" "[Updater Action] Update BuildConfigs for CUDA RStudio and RStudio" "${REPO_OWNER}" "${REPO_NAME}"
119+
120+
# 5. Generate the release with BuildConfigs if needed
121+
Generate_release_with_buildconfigs:
122+
needs: [Update_manifests, Manifests_merged, Update_buildConfigs, BuildConfigs_merged]
123+
if: ${{ needs.Manifests_merged.outputs.pr_merged_m == 'true' && needs.BuildConfigs_merged.outputs.pr_merged_b == 'true' && inputs.update_buildconfigs && github.event.inputs.release_type == 'Release' }}
124+
permissions:
125+
contents: write
126+
uses: ./.github/workflows/create-release.yaml
127+
with:
128+
release_tag: ${{ github.event.inputs.release_tag }}
129+
release_name: ${{ github.event.inputs.release_name }}
130+
branch: ${{ github.event.inputs.branch }}
131+
132+
# 6. Generate the release without BuildConfigs
133+
Generate_release:
134+
needs: [Update_manifests, Manifests_merged]
135+
if: ${{ needs.Manifests_merged.outputs.pr_merged_m == 'true' && github.event.inputs.update_buildconfigs == 'false' && github.event.inputs.release_type == 'Release' }}
136+
permissions:
137+
contents: write
138+
uses: ./.github/workflows/create-release.yaml
139+
with:
140+
release_tag: ${{ github.event.inputs.release_tag }}
141+
release_name: ${{ github.event.inputs.release_name }}
142+
branch: ${{ github.event.inputs.branch }}
143+
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# The aim of this GitHub workflow is to update the cuda-rstudio-buildconfig.yaml and rstudio-buildconfig.yaml
2+
# If no version is provided, the workflow will update the BuildConfigs to the next version by incrementing the minor version number by 1.
3+
---
4+
name: Update BuildConfigs
5+
permissions:
6+
contents: write
7+
pull-requests: write
8+
"on":
9+
workflow_dispatch:
10+
inputs:
11+
branch:
12+
description: "Optional: Provide branch name"
13+
required: false
14+
type: string
15+
default: "main"
16+
version:
17+
description: "Optional: Provide version to update BuildConfigs to"
18+
required: false
19+
type: string
20+
workflow_call:
21+
inputs:
22+
branch:
23+
required: true
24+
type: string
25+
version:
26+
required: true
27+
type: string
28+
env:
29+
TMP_BRANCH: tmp-verify-${{ github.run_id }}
30+
BRANCH: ${{ inputs.branch }}
31+
VERSION: ${{ inputs.version }}
32+
33+
jobs:
34+
buildConfigs:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Check out repository
38+
uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 0
41+
42+
- name: Configure Git
43+
run: |
44+
git config user.name "GitHub Actions"
45+
git config user.email "github-actions[bot]@users.noreply.github.com"
46+
47+
- name: Create Target Branch
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
working-directory: ${{env.GITHUB_WORKSPACE}}
51+
run: |
52+
git checkout -b "$TMP_BRANCH"
53+
git push --set-upstream origin "$TMP_BRANCH"
54+
55+
- name: Update BuildConfig
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
working-directory: ${{env.GITHUB_WORKSPACE}}
59+
run: |
60+
for config in "cuda-rstudio-buildconfig.yaml" "rstudio-buildconfig.yaml"; do
61+
bash "${GITHUB_WORKSPACE}/ci/buildconfig-updater.sh" "${GITHUB_WORKSPACE}/manifests/base/$config" "$VERSION"
62+
done
63+
64+
- name: Add Files and Commit Changes
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
working-directory: ${{env.GITHUB_WORKSPACE}}
68+
run: |
69+
git add "${GITHUB_WORKSPACE}/manifests/base/"*.yaml
70+
git commit -m "Update BuildConfigs for CUDA RStudio and RStudio"
71+
git push origin "$TMP_BRANCH"
72+
73+
- name: Create Pull Request
74+
run: |
75+
gh pr create -B $BRANCH -H "$TMP_BRANCH" --title "$PR_TITLE" --body "$PR_BODY"
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
PR_TITLE: "[Updater Action] Update BuildConfigs for CUDA RStudio and RStudio"
79+
PR_BODY: |
80+
:rocket: This is an automated Pull Request.
81+
Created by `/.github/workflows/update-buildconfigs.yaml`
82+
- `manifests/base/cuda-rstudio-buildconfig.yaml` File that points to the latest CUDA RStudio version
83+
- `manifests/base/rstudio-buildconfig.yaml` File that points to the latest RStudio version

ci/buildconfig-updater.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
file_path=$1
4+
version=$2
5+
6+
tmpfile=$(mktemp)
7+
trap 'rm -f "$tmpfile"' EXIT
8+
9+
while IFS= read -r line; do
10+
if [[ "$line" == *"ref: rhoai-"* ]]; then
11+
if [[ -z "$version" ]]; then
12+
# Auto-increment minor version
13+
version_current="${line##*rhoai-}"
14+
IFS='.' read -r major minor <<< "$version_current"
15+
minor=$((minor + 1))
16+
echo " ref: rhoai-${major}.${minor}" >> "$tmpfile"
17+
else
18+
# Use provided version
19+
echo " ref: rhoai-${version}" >> "$tmpfile"
20+
fi
21+
else
22+
echo "$line" >> "$tmpfile"
23+
fi
24+
done < "$file_path"
25+
26+
# Replace original file atomically
27+
mv "$tmpfile" "$file_path"

ci/check-pr-merged.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
PR_TITLE=$1
5+
REPO_OWNER=$2
6+
REPO_NAME=$3
7+
8+
# PR to look for
9+
PR_TITLE_ESCAPED=$(echo "$PR_TITLE" | sed 's/"/\\"/g') # Escape double quotes for jq
10+
11+
#Fetch matching PRs
12+
PR_NUMBER=$(gh pr list --repo "$REPO_OWNER/$REPO_NAME" --state all --search "$PR_TITLE_ESCAPED" --json number,title | jq -r '.[0].number')
13+
echo "PR Numbers: $PR_NUMBER"
14+
15+
if [ -z "$PR_NUMBER" ] || [ "$PR_NUMBER" = "null" ]; then
16+
echo "No PR found with title: $PR_TITLE_ESCAPED"
17+
exit 1
18+
fi
19+
20+
# Polling loop to wait for the PR to be merged total timeout=5h
21+
MAX_ATTEMPTS=30
22+
SLEEP_DURATION=600
23+
24+
for (( i=1; i<=MAX_ATTEMPTS; i++ )); do
25+
echo "Checking if PR #$PR_NUMBER is merged (Attempt $i/$MAX_ATTEMPTS)..."
26+
PR_STATE=$(gh pr view --repo "$REPO_OWNER/$REPO_NAME" $PR_NUMBER --json mergedAt --jq '.mergedAt')
27+
28+
if [ "$PR_STATE" = "null" ] || [ -z "$PR_STATE" ]; then
29+
echo "PR #$PR_NUMBER is not merged yet. Waiting..."
30+
sleep $SLEEP_DURATION
31+
else
32+
echo "PR #$PR_NUMBER is merged!"
33+
echo "pr_merged=true" >> $GITHUB_ENV
34+
echo "pr_merged=true" >> $GITHUB_OUTPUT
35+
exit 0
36+
fi
37+
done
38+
39+
echo "Timed out waiting for PR #$PR_NUMBER to be merged."
40+
echo "pr_merged=false" >> $GITHUB_ENV
41+
echo "pr_merged=false" >> $GITHUB_OUTPUT
42+
exit 1

0 commit comments

Comments
 (0)