|
| 1 | +--- |
| 2 | +# The aim of this GitHub workflow is to update the params.env file with the latest digest. |
| 3 | +name: Update notebook image build commit hashes |
| 4 | +on: # yamllint disable-line rule:truthy |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + branch: |
| 8 | + required: true |
| 9 | + description: "Provide the name of the branch you want to update ex main, vYYYYx etc: " |
| 10 | + # Put the scheduler on comment until automate the full release procedure |
| 11 | + # schedule: |
| 12 | + # - cron: "0 0 * * 5" #Scheduled every Friday |
| 13 | +env: |
| 14 | + DIGEST_UPDATER_BRANCH: digest-updater-${{ github.run_id }} |
| 15 | + BRANCH_NAME: ${{ github.event.inputs.branch || 'main' }} |
| 16 | + RELEASE_VERSION_N: 2024b |
| 17 | + RELEASE_VERSION_N_1: 2024a |
| 18 | +jobs: |
| 19 | + initialize: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + contents: write |
| 23 | + steps: |
| 24 | + - name: Install Skopeo CLI |
| 25 | + shell: bash |
| 26 | + run: | |
| 27 | + sudo apt-get -y update |
| 28 | + sudo apt-get -y install skopeo |
| 29 | +
|
| 30 | + # Checkout the branch |
| 31 | + - name: Checkout branch |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + ref: ${{ env.BRANCH_NAME }} |
| 35 | + |
| 36 | + # Create a new branch |
| 37 | + - name: Create a new branch |
| 38 | + run: | |
| 39 | + echo ${{ env.DIGEST_UPDATER_BRANCH }} |
| 40 | + git checkout -b ${{ env.DIGEST_UPDATER_BRANCH }} |
| 41 | + git push --set-upstream origin ${{ env.DIGEST_UPDATER_BRANCH }} |
| 42 | +
|
| 43 | + update-n-version: |
| 44 | + needs: [initialize] |
| 45 | + runs-on: ubuntu-latest |
| 46 | + permissions: |
| 47 | + contents: write |
| 48 | + steps: |
| 49 | + - name: Configure Git |
| 50 | + run: | |
| 51 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 52 | + git config --global user.name "GitHub Actions" |
| 53 | +
|
| 54 | + # Get latest build commit from the https://github.com/opendatahub-io/notebooks/${release_branch} using this as identifier for the latest tag name |
| 55 | + - name: Retrive latest commit hash from the release branch |
| 56 | + id: hash-n |
| 57 | + shell: bash |
| 58 | + run: | |
| 59 | + PAYLOAD=$(curl --silent -H 'Accept: application/vnd.github.v4.raw' https://api.github.com/repos/opendatahub-io/notebooks/commits?sha=$RELEASE_VERSION_N&per_page=1) |
| 60 | + echo "HASH_N=$(echo $PAYLOAD | jq -r '.[0].sha[0:7]')" >> ${GITHUB_OUTPUT} |
| 61 | +
|
| 62 | + # Checkout the release branch to apply the updates |
| 63 | + - name: Checkout release branch |
| 64 | + uses: actions/checkout@v4 |
| 65 | + with: |
| 66 | + ref: ${{ env.DIGEST_UPDATER_BRANCH }} |
| 67 | + |
| 68 | + - name: Update the params.env file |
| 69 | + run: | |
| 70 | + PARAMS_ENV_PATH="manifests/base/params.env" |
| 71 | +
|
| 72 | + echo Latest commit is: ${{ steps.hash-n.outputs.HASH_N }} on ${{ env.RELEASE_VERSION_N }} |
| 73 | +
|
| 74 | + # Get the complete list of images N-version to update |
| 75 | + IMAGES=$(grep "\-n=" "${PARAMS_ENV_PATH}" | cut -d "=" -f 1) |
| 76 | +
|
| 77 | + for image in ${IMAGES}; do |
| 78 | + echo "CHECKING: '${image}'" |
| 79 | + img=$(grep -E "${image}=" "${PARAMS_ENV_PATH}" | cut -d '=' -f2) |
| 80 | + registry=$(echo "${img}" | cut -d '@' -f1) |
| 81 | +
|
| 82 | + skopeo_metadata=$(skopeo inspect --retry-times 3 "docker://${img}") |
| 83 | +
|
| 84 | + src_tag=$(echo "${skopeo_metadata}" | jq '.Env[] | select(startswith("OPENSHIFT_BUILD_NAME=")) | split("=")[1]' | tr -d '"' | sed 's/-amd64$//') |
| 85 | + regex="^$src_tag-${{ env.RELEASE_VERSION_N}}-\d+-${{ steps.hash-n.outputs.HASH_N }}\$" |
| 86 | + latest_tag=$(echo "${skopeo_metadata}" | jq -r --arg regex "$regex" '.RepoTags | map(select(. | test($regex))) | .[0]') |
| 87 | + # use `--no-tags` for skopeo once available in newer version |
| 88 | + digest=$(skopeo inspect --retry-times 3 "docker://${registry}:${latest_tag}" | jq .Digest | tr -d '"') |
| 89 | + output="${registry}@${digest}" |
| 90 | + echo "NEW: ${output}" |
| 91 | + sed -i "s|${image}=.*|${image}=${output}|" "${PARAMS_ENV_PATH}" |
| 92 | + done |
| 93 | +
|
| 94 | + if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then |
| 95 | + git fetch origin ${{ env.DIGEST_UPDATER_BRANCH }} && \ |
| 96 | + git pull origin ${{ env.DIGEST_UPDATER_BRANCH }} && \ |
| 97 | + git add "${PARAMS_ENV_PATH}" && \ |
| 98 | + git commit -m "Update images for release N via ${{ env.DIGEST_UPDATER_BRANCH }} GitHub action" && \ |
| 99 | + git push origin ${{ env.DIGEST_UPDATER_BRANCH }} |
| 100 | + else |
| 101 | + echo "There were no changes detected in the images for the ${{ env.RELEASE_VERSION_N }}" |
| 102 | + fi |
| 103 | +
|
| 104 | + - name: Update the commit.env file |
| 105 | + run: | |
| 106 | + COMMIT_ENV_PATH="manifests/base/commit.env" |
| 107 | +
|
| 108 | + echo Latest commit is: ${{ steps.hash-n.outputs.HASH_N }} on ${{ env.RELEASE_VERSION_N }} |
| 109 | + # Get the complete list of commits N-version to update |
| 110 | + COMMIT=$(grep "\-n=" "${COMMIT_ENV_PATH}" | cut -d "=" -f 1) |
| 111 | +
|
| 112 | + for val in ${COMMIT}; do |
| 113 | + echo "${val}" |
| 114 | + sed -i "s|${val}=.*|${val}=${{ steps.hash-n.outputs.HASH_N }}|" "${COMMIT_ENV_PATH}" |
| 115 | + done |
| 116 | +
|
| 117 | + if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then |
| 118 | + git fetch origin ${{ env.DIGEST_UPDATER_BRANCH }} && \ |
| 119 | + git pull origin ${{ env.DIGEST_UPDATER_BRANCH }} && \ |
| 120 | + git add "${COMMIT_ENV_PATH}" && \ |
| 121 | + git commit -m "Update image commits for release N via ${{ env.DIGEST_UPDATER_BRANCH }} GitHub action" && \ |
| 122 | + git push origin ${{ env.DIGEST_UPDATER_BRANCH }} |
| 123 | + else |
| 124 | + echo "There were no changes detected in the images for the ${{ env.RELEASE_VERSION_N }}" |
| 125 | + fi |
| 126 | +
|
| 127 | + update-n-1-version: |
| 128 | + needs: [initialize, update-n-version] |
| 129 | + runs-on: ubuntu-latest |
| 130 | + permissions: |
| 131 | + contents: write |
| 132 | + steps: |
| 133 | + - name: Configure Git |
| 134 | + run: | |
| 135 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 136 | + git config --global user.name "GitHub Actions" |
| 137 | +
|
| 138 | + # Get latest build commit from the https://github.com/opendatahub-io/notebooks/${release_branch} using this as identifier for the latest tag name |
| 139 | + - name: Retrive latest commit hash from the release branch |
| 140 | + id: hash-n-1 |
| 141 | + shell: bash |
| 142 | + run: | |
| 143 | + PAYLOAD=$(curl --silent -H 'Accept: application/vnd.github.v4.raw' https://api.github.com/repos/opendatahub-io/notebooks/commits?sha=$RELEASE_VERSION_N_1&per_page=1) |
| 144 | + echo "HASH_N_1=$(echo $PAYLOAD | jq -r '.[0].sha[0:7]')" >> ${GITHUB_OUTPUT} |
| 145 | +
|
| 146 | + # Checkout the release branch to apply the updates |
| 147 | + - name: Checkout release branch |
| 148 | + uses: actions/checkout@v4 |
| 149 | + with: |
| 150 | + ref: ${{ env.DIGEST_UPDATER_BRANCH }} |
| 151 | + |
| 152 | + - name: Update the param.env file |
| 153 | + run: | |
| 154 | + PARAMS_ENV_PATH="manifests/base/params.env" |
| 155 | +
|
| 156 | + echo Latest commit is: ${{ steps.hash-n-1.outputs.HASH_N_1 }} on ${{ env.RELEASE_VERSION_N_1 }} |
| 157 | +
|
| 158 | + # Get the complete list of images N-1-version to update |
| 159 | + IMAGES=$(grep "\-n-1=" "${PARAMS_ENV_PATH}" | cut -d "=" -f 1) |
| 160 | +
|
| 161 | + for image in ${IMAGES}; do |
| 162 | + echo "CHECKING: '${image}'" |
| 163 | + img=$(grep -E "${image}=" "${PARAMS_ENV_PATH}" | cut -d '=' -f2) |
| 164 | + registry=$(echo "${img}" | cut -d '@' -f1) |
| 165 | +
|
| 166 | + skopeo_metadata=$(skopeo inspect --retry-times 3 "docker://${img}") |
| 167 | +
|
| 168 | + src_tag=$(echo "${skopeo_metadata}" | jq '.Env[] | select(startswith("OPENSHIFT_BUILD_NAME=")) | split("=")[1]' | tr -d '"' | sed 's/-amd64$//') |
| 169 | + regex="^$src_tag-${{ env.RELEASE_VERSION_N_1}}-\d+-${{ steps.hash-n-1.outputs.HASH_N_1 }}\$" |
| 170 | + latest_tag=$(echo "${skopeo_metadata}" | jq -r --arg regex "$regex" '.RepoTags | map(select(. | test($regex))) | .[0]') |
| 171 | + # use `--no-tags` for skopeo once available in newer version |
| 172 | + digest=$(skopeo inspect --retry-times 3 "docker://${registry}:${latest_tag}" | jq .Digest | tr -d '"') |
| 173 | + output="${registry}@${digest}" |
| 174 | + echo "NEW: ${output}" |
| 175 | + sed -i "s|${image}=.*|${image}=${output}|" "${PARAMS_ENV_PATH}" |
| 176 | + done |
| 177 | +
|
| 178 | + if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then |
| 179 | + git fetch origin ${{ env.DIGEST_UPDATER_BRANCH }} && \ |
| 180 | + git pull origin ${{ env.DIGEST_UPDATER_BRANCH }} && \ |
| 181 | + git add "${PARAMS_ENV_PATH}" && \ |
| 182 | + git commit -m "Update images for release N-1 via ${{ env.DIGEST_UPDATER_BRANCH }} GitHub action" && \ |
| 183 | + git push origin ${{ env.DIGEST_UPDATER_BRANCH }} |
| 184 | + else |
| 185 | + echo "There were no changes detected in the images for the ${{ env.RELEASE_VERSION_N_1 }}" |
| 186 | + fi |
| 187 | +
|
| 188 | + - name: Update the commit.env file |
| 189 | + run: | |
| 190 | + COMMIT_ENV_PATH="manifests/base/commit.env" |
| 191 | +
|
| 192 | + echo Latest commit is: ${{ steps.hash-n-1.outputs.HASH_N_1 }} on ${{ env.RELEASE_VERSION_N_1 }} |
| 193 | + # Get the complete list of images N-1-version to update |
| 194 | + COMMIT=$(grep "\-n-1=" "${COMMIT_ENV_PATH}" | cut -d "=" -f 1) |
| 195 | +
|
| 196 | + for val in ${COMMIT}; do |
| 197 | + echo "${val}" |
| 198 | + sed -i "s|${val}=.*|${val}=${{ steps.hash-n-1.outputs.HASH_N_1 }}|" "${COMMIT_ENV_PATH}" |
| 199 | + done |
| 200 | +
|
| 201 | + if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then |
| 202 | + git fetch origin ${{ env.DIGEST_UPDATER_BRANCH }} && \ |
| 203 | + git pull origin ${{ env.DIGEST_UPDATER_BRANCH }} && \ |
| 204 | + git add "${COMMIT_ENV_PATH}" && \ |
| 205 | + git commit -m "Update image commits for release N-1 via ${{ env.DIGEST_UPDATER_BRANCH }} GitHub action" && \ |
| 206 | + git push origin ${{ env.DIGEST_UPDATER_BRANCH }} |
| 207 | + else |
| 208 | + echo "There were no changes detected in the images for the ${{ env.RELEASE_VERSION_N_1 }}" |
| 209 | + fi |
| 210 | +
|
| 211 | + open-pull-request: |
| 212 | + needs: [update-n-version, update-n-1-version] |
| 213 | + runs-on: ubuntu-latest |
| 214 | + permissions: |
| 215 | + pull-requests: write |
| 216 | + steps: |
| 217 | + - name: Checkout repo |
| 218 | + uses: actions/checkout@v4 |
| 219 | + |
| 220 | + - name: pull-request |
| 221 | + uses: repo-sync/pull-request@v2 |
| 222 | + with: |
| 223 | + source_branch: ${{ env.DIGEST_UPDATER_BRANCH }} |
| 224 | + destination_branch: ${{ env.BRANCH_NAME }} |
| 225 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 226 | + pr_label: "automated pr" |
| 227 | + pr_title: "[Digest Updater Action] Update Notebook Images" |
| 228 | + pr_body: | |
| 229 | + :rocket: This is an automated Pull Request. |
| 230 | + Created by `/.github/workflows/notebooks-digest-updater-upstream.yaml` |
| 231 | +
|
| 232 | + This PR updates the following files: |
| 233 | + - `manifests/base/params.env` file with the latest updated SHA digests of the notebooks (N & N-1). |
| 234 | + - `manifests/base/commit.env` file with the latest commit (N & N-1). |
| 235 | +
|
| 236 | + :exclamation: **IMPORTANT NOTE**: Remember to delete the `${{ env.DIGEST_UPDATER_BRANCH }}` branch after merging the changes |
0 commit comments