index-render-template-1-18 #124
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
name: index-render-template-1-18 | |
on: | |
workflow_dispatch: {} | |
schedule: | |
- cron: "0 2 * * *" # At 2AM everyday | |
push: | |
branch: | |
- "release-v1.18.x" | |
branches-ignore: | |
- "konflux/**/1-18**" | |
paths: | |
- .konflux/olm-catalog/index/**/Dockerfile.catalog | |
- .konflux/olm-catalog/index/**/catalog-template.json | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build-matrix: | |
runs-on: ubuntu-latest | |
if: github.repository_owner == 'openshift-pipelines' # do not run this elsewhere | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v4 | |
with: | |
ref: release-v1.18.x | |
- id: set-matrix | |
run: | | |
pushd .konflux/olm-catalog/index | |
VERSIONS=$(ls -d v* | jq -R -s -c 'split("\n")[:-1]') | |
popd | |
echo "Versions: ${VERSIONS}" | |
echo "versions=${VERSIONS}" >> $GITHUB_OUTPUT | |
outputs: | |
versions: ${{ steps.set-matrix.outputs.versions }} | |
generate-catalog: | |
needs: build-matrix | |
if: github.repository_owner == 'openshift-pipelines' # do not run this elsewhere | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
version: ${{ fromJSON(needs.build-matrix.outputs.versions) }} | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v4 | |
with: | |
ref: release-v1.18.x | |
- name: Configure Docker authentication | |
env: | |
DOCKER_CONFIG: /home/runner/.docker | |
DOCKER_JSON: ${{ secrets.DOCKER_REGISTRY_SECRET }} | |
run: | | |
echo ${DOCKER_JSON} > $DOCKER_CONFIG/config.json | |
- name: Generate ${{matrix.version}} catalog | |
run: | | |
echo ${{matrix.version}} | |
curl -sSfLo /usr/local/bin/opm "https://github.com/operator-framework/operator-registry/releases/download/v1.47.0/linux-amd64-opm" | |
chmod +x /usr/local/bin/opm | |
VERSION=${{matrix.version}} | |
CATALOG_JSON=".konflux/olm-catalog/index/${VERSION}/catalog-template.json" | |
BUNDLE_IMAGE=$(yq '.images[] | select(.name == "IMAGE_OPERATOR_BUNDLE") | .value' project.yaml) | |
echo "Bundle Image from project.yaml : $BUNDLE_IMAGE" | |
TARGET_REGISTRY="registry.stage.redhat.io/openshift-pipelines" | |
SOURCE_PATTEN="quay.io/.*/(.*)-rhel9(@sha256:.+)" | |
TARGET_PATTEN="$TARGET_REGISTRY/pipelines-\1\2" | |
BUNDLE_IMAGE=$(echo "${BUNDLE_IMAGE}" | sed -E "s|$SOURCE_PATTEN|$TARGET_PATTEN|g") | |
echo "Bundle Image updated for index images : $BUNDLE_IMAGE" | |
##Update the image field with $BUNDLE_IMAGE | |
## There are multiple olm.bundle entries for all previously released versions. | |
## The releasing version is placed first to ensure proper replacement. | |
jq --arg BUNDLE_IMAGE "$BUNDLE_IMAGE" '( .entries | to_entries | map(select(.value.schema == "olm.bundle")) | .[0].key ) as $firstIndex | if $firstIndex then .entries[$firstIndex].image = $BUNDLE_IMAGE else . end' "$CATALOG_JSON" > temp.json && mv temp.json "$CATALOG_JSON" | |
echo "Update bundle Image in $CATALOG_JSON" | |
BUNDLE_VERSION=$(opm render --skip-tls-verify -o json ${BUNDLE_IMAGE} | jq -r '.name' | awk -F 'v' '{ print $2 }') | |
# Update catalog-template | |
sed -i "s%5.0.5-[0-9]\+%${BUNDLE_VERSION}%g" .konflux/olm-catalog/index/${{matrix.version}}/catalog-template.json | |
# as per this doc https://github.com/konflux-ci/olm-operator-konflux-sample/blob/main/docs/konflux-onboarding.md#create-the-fbc-in-the-git-repository | |
# Starting with OCP 4.17 we need the --migrate-level=bundle-object-to-csv-metadata flag. For rendering to older versions of OCP. | |
NUMERIC_VERSION=${VERSION#v} # Removes "v" prefix | |
if (( $(echo "$NUMERIC_VERSION >= 4.17" | bc -l) )); then | |
opm alpha render-template basic .konflux/olm-catalog/index/${{matrix.version}}/catalog-template.json --migrate-level=bundle-object-to-csv-metadata > .konflux/olm-catalog/index/${{matrix.version}}/catalog/openshift-pipelines-operator-rh/catalog.json | |
else | |
opm alpha render-template basic .konflux/olm-catalog/index/${{matrix.version}}/catalog-template.json > .konflux/olm-catalog/index/${{matrix.version}}/catalog/openshift-pipelines-operator-rh/catalog.json | |
fi | |
- name: Commit new changes | |
run: | | |
git config user.name openshift-pipelines-bot | |
git config user.email [email protected] | |
git checkout -b actions/index-1.18/${{matrix.version}} | |
git add .konflux/olm-catalog/index/${{matrix.version}}/ | |
if [[ -z $(git status --porcelain --untracked-files=no) ]]; then | |
echo "No change, exiting" | |
exit 0 | |
fi | |
git commit -F- <<EOF | |
[bot:1.18] Update ${{matrix.version}} generate catalog | |
EOF | |
git push -f origin actions/index-1.18/${{matrix.version}} | |
if [ "$(gh pr list --base 1.18 --head actions/index-1.18/${{matrix.version}} --json url --jq 'length')" = "0" ]; then | |
echo "creating PR..." | |
gh pr create -B release-v1.18.x -H actions/index-1.18/${{matrix.version}} --label=automated --label=lgtm --label=approved --fill | |
fi | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |