Zack Williams | be54231 | 2022-06-23 21:51:32 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
Joey Armstrong | 518f357 | 2024-02-11 07:56:25 -0500 | [diff] [blame] | 3 | # SPDX-FileCopyrightText: 2022-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Zack Williams | be54231 | 2022-06-23 21:51:32 -0700 | [diff] [blame] | 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | |
| 6 | set -eu -o pipefail |
| 7 | |
| 8 | echo "git version: $(git --version)" |
| 9 | |
| 10 | # Variables used in this and child scripts |
| 11 | export PUBLISH_URL="charts.opencord.org" |
| 12 | export OLD_REPO_DIR="cord-charts-repo" |
| 13 | export NEW_REPO_DIR="chart_repo" |
| 14 | |
| 15 | # Configure git |
| 16 | git config --global user.email "do-not-reply@opennetworking.org" |
| 17 | git config --global user.name "Jenkins" |
| 18 | |
| 19 | # Checkout 'cord-charts-repo' repo that contains updated charts |
| 20 | git clone "ssh://jenkins@gerrit.opencord.org:29418/$OLD_REPO_DIR.git" |
| 21 | |
| 22 | # Clone the `helm-repo-tools` which contains scripts |
| 23 | git clone ssh://jenkins@gerrit.opencord.org:29418/helm-repo-tools.git |
| 24 | |
| 25 | # Setup helm and external repos |
| 26 | helm repo add stable https://charts.helm.sh/stable |
| 27 | helm repo add rook-release https://charts.rook.io/release |
| 28 | helm repo add cord https://charts.opencord.org |
| 29 | helm repo add elastic https://helm.elastic.co |
| 30 | helm repo add kiwigrid https://kiwigrid.github.io |
| 31 | |
| 32 | # Update the repo |
| 33 | ./helm-repo-tools/helmrepo.sh |
| 34 | |
| 35 | # Tag and push to git the charts repo |
| 36 | pushd "$OLD_REPO_DIR" |
| 37 | |
| 38 | # only update if charts are changed |
| 39 | set +e |
| 40 | if git diff --exit-code index.yaml > /dev/null; then |
| 41 | echo "No changes to charts in patchset $GERRIT_CHANGE_NUMBER on project: $GERRIT_PROJECT, exiting." |
| 42 | exit 0 |
| 43 | fi |
| 44 | set -e |
| 45 | |
| 46 | # version tag is the current date in RFC3339 format |
| 47 | NEW_VERSION=$(date -u +%Y%m%dT%H%M%SZ) |
| 48 | |
| 49 | # Add changes and create commit |
| 50 | git add -A |
| 51 | git commit -m "Changed by CORD Jenkins publish-helm-repo job: $BUILD_NUMBER, for project: $GERRIT_PROJECT, patchset: $GERRIT_CHANGE_NUMBER" |
| 52 | |
| 53 | # create tag on new commit |
| 54 | git tag "$NEW_VERSION" |
| 55 | |
| 56 | echo "Tags including new tag:" |
| 57 | git tag -n |
| 58 | |
| 59 | # push new commit and tag back into repo |
| 60 | git push origin |
| 61 | git push origin "$NEW_VERSION" |
| 62 | popd |
| 63 | |
| 64 | rsync -rvzh --delete-after --exclude=.git "$OLD_REPO_DIR/" "static.opennetworking.org:/srv/sites/$PUBLISH_URL/" |