Update Notebook Controllers' Image Tags #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# This workflow automatically updates the notebook controllers' image tags | |
name: Update Notebook Controllers' Image Tags | |
on: | |
workflow_dispatch: | |
inputs: | |
branch-name: | |
description: "Provide name of the branch, used to commit changes" | |
required: true | |
default: "main" | |
organization: | |
required: true | |
description: "Owner of origin kubeflow repository" | |
default: "opendatahub-io" | |
generate-pr: | |
description: "Create PR?" | |
required: true | |
default: "true" | |
workflow_call: | |
inputs: | |
branch-name: | |
description: "Provide name of the branch, used to commit changes" | |
required: true | |
type: string | |
organization: | |
description: "Owner of origin kubeflow repository" | |
required: true | |
type: string | |
generate-pr: | |
description: "Create PR?" | |
required: true | |
type: string | |
env: | |
REPO_OWNER: ${{ inputs.organization }} | |
TEMP_UPDATER_BRANCH: temp-${{ inputs.branch-name }}-${{ github.run_id }} | |
BRANCH_NAME: ${{ inputs.branch-name }} | |
GENERATE_PR: ${{ inputs.generate-pr }} | |
REPO_NAME: kubeflow | |
jobs: | |
update-notebook-controller-images: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Configure Git | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "GitHub Actions" | |
- name: Checkout branch | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ env.BRANCH_NAME }} | |
- name: Checkout new branch | |
run: | | |
echo ${{ env.TEMP_UPDATER_BRANCH }} | |
git fetch origin | |
git checkout -b ${{ env.TEMP_UPDATER_BRANCH }} origin/${{ env.BRANCH_NAME }} | |
git push --set-upstream origin ${{ env.TEMP_UPDATER_BRANCH }} | |
- name: Retrieve latest commit | |
id: commit-id | |
shell: bash | |
run: | | |
PAYLOAD=$(curl --silent -H 'Accept: application/vnd.github.v4.raw' https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/commits?sha=$BRANCH_NAME&per_page=1) | |
echo "GIT_HASH=$(echo $PAYLOAD | jq -r '.[0].sha[0:7]')" >> ${GITHUB_OUTPUT} | |
- name: Extract version from branch-name | |
id: version | |
run: | | |
if [[ "${{ env.BRANCH_NAME }}" == "main" ]]; then | |
VERSION="main" | |
else | |
VERSION=$(echo "${{ env.BRANCH_NAME }}" | sed -E 's/^v([0-9]+\.[0-9]+)-.*/\1/') | |
# Check if VERSION is empty, then assign the full branch name | |
if [[ -z "$VERSION" ]]; then | |
VERSION="${{ env.BRANCH_NAME }}" | |
fi | |
fi | |
echo "VERSION=$VERSION" >> ${GITHUB_OUTPUT} | |
echo "Extracted VERSION is: $VERSION" | |
- name: Update related files | |
id: apply-changes | |
run: | | |
GIT_HASH=${{ steps.commit-id.outputs.GIT_HASH }} | |
VERSION=${{ steps.version.outputs.VERSION }} | |
echo "Updating files in VERSION=${VERSION} with GIT_HASH=${GIT_HASH}" | |
sed -E "s/(odh-kf-notebook-controller-image=quay\.io\/opendatahub\/kubeflow-notebook-controller:)[^: -]+(-)[^ ]+/\1$VERSION\2$GIT_HASH/" -i components/notebook-controller/config/overlays/openshift/params.env | |
sed -E "s/(odh-notebook-controller-image=quay\.io\/opendatahub\/odh-notebook-controller:)[^: -]+(-)[^ ]+/\1$VERSION\2$GIT_HASH/" -i components/odh-notebook-controller/config/base/params.env | |
sed -E "s/(KF_TAG \?= )[^\-]+(-)[^ ]+/\1$VERSION\2$GIT_HASH/" -i components/odh-notebook-controller/makefile-vars.mk | |
git status | |
if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then | |
echo "Changes detected, committing and pushing..." | |
git fetch origin ${{ env.TEMP_UPDATER_BRANCH }} | |
git pull origin ${{ env.TEMP_UPDATER_BRANCH }} | |
git add components/notebook-controller/config/overlays/openshift/params.env | |
git add components/odh-notebook-controller/config/base/params.env | |
git add components/odh-notebook-controller/makefile-vars.mk | |
git commit -m "Update odh and notebook-controller with image ${VERSION}-${GIT_HASH}" | |
git push origin ${{ env.TEMP_UPDATER_BRANCH }} | |
else | |
echo "There were no changes detected on ${{ env.BRANCH_NAME }}" | |
fi | |
- name: PR Cretation | |
if: ${{ env.GENERATE_PR == 'true' }} | |
run: | | |
gh pr create --repo https://github.com/$REPO_OWNER/$REPO_NAME.git \ | |
--title "$pr_title" \ | |
--body "$pr_body" \ | |
--head $REPO_OWNER:${{ env.TEMP_UPDATER_BRANCH }} \ | |
--base ${{ env.BRANCH_NAME }} | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
pr_title: "[GHA-${{ github.run_id }}] Update odh and notebook-controller with image ${{ steps.version.outputs.VERSION }}-${{ steps.commit-id.outputs.GIT_HASH }}" | |
pr_body: | | |
:robot: This is an automated Pull Request created by `/.github/workflows/notebook-controller-images-updater.yaml`. | |
Have been updated the following related files: | |
- components/notebook-controller/config/overlays/openshift/params.env | |
- components/odh-notebook-controller/config/base/params.env | |
- components/odh-notebook-controller/makefile-vars.mk | |
- name: Auto Merge Changes to Target Branch | |
if: ${{ env.GENERATE_PR != 'true' }} | |
run: | | |
git fetch origin | |
git checkout ${{ env.BRANCH_NAME }} | |
git merge --no-ff ${{ env.TEMP_UPDATER_BRANCH }} -m ":robot: Update odh and notebook-controller with image ${VERSION}-${GIT_HASH} auto-merged changes from ${{ env.TEMP_UPDATER_BRANCH }}" | |
git push origin ${{ env.BRANCH_NAME }} |