publish.sh 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. #!/bin/bash
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. set -euo pipefail
  11. . misc/shlib/shlib.bash
  12. CHARTS_DIR=misc/helm-charts
  13. GITHUB_PAGES_BRANCH=gh-pages
  14. RELEASE_DIR=.cr-release-packages
  15. export GIT_AUTHOR_NAME=Materialize Bot
  16. export GIT_AUTHOR_EMAIL=infra+bot@materialize.com
  17. export GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME
  18. export GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL
  19. export GIT_PAGER=cat
  20. : "${CI_HELM_CHART_VERSION:=}"
  21. : "${CI_MZ_VERSION:=}"
  22. : "${CI_NO_TERRAFORM_BUMP:=0}"
  23. : "${CI_DRY_RUN:=0}"
  24. if [[ -z "$CI_HELM_CHART_VERSION" || -z "$CI_MZ_VERSION" ]]; then
  25. echo "\$CI_HELM_CHART_VERSION and \$CI_MZ_VERSION have to be set, use https://trigger-ci.dev.materialize.com to trigger this pipeline"
  26. exit 1
  27. fi
  28. cat > ~/.netrc <<EOF
  29. machine github.com
  30. login materializebot
  31. password $GITHUB_TOKEN
  32. EOF
  33. chmod 600 ~/.netrc
  34. run_if_not_dry() {
  35. if ! is_truthy "$CI_DRY_RUN"; then
  36. "$@"
  37. else
  38. echo "[DRY RUN] $*"
  39. fi
  40. }
  41. echo "--- Publishing Helm Chart $CI_HELM_CHART_VERSION with Materialize $CI_MZ_VERSION"
  42. bin/helm-chart-version-bump --helm-chart-version "$CI_HELM_CHART_VERSION" "$CI_MZ_VERSION"
  43. git commit -a -m "Bumping helm-chart version to $CI_HELM_CHART_VERSION with Materialize $CI_MZ_VERSION"
  44. TAG="self-managed-$CI_HELM_CHART_VERSION"
  45. git tag "$TAG"
  46. git diff HEAD~
  47. run_if_not_dry git push "https://github.com/MaterializeInc/materialize.git" "$TAG"
  48. # Find directories containing Chart.yaml
  49. CHARTS=""
  50. for dir in "$CHARTS_DIR"/*/; do
  51. if [ -f "${dir}Chart.yaml" ]; then
  52. chart_name=$(basename "$dir")
  53. CHARTS="${CHARTS:+${CHARTS} }$chart_name"
  54. fi
  55. done
  56. if [ -z "$CHARTS" ]; then
  57. echo "No valid Helm charts found"
  58. exit 0
  59. fi
  60. echo "Found valid charts: $CHARTS"
  61. rm -rf gh-pages
  62. git clone --branch "$GITHUB_PAGES_BRANCH" --depth 1 https://github.com/MaterializeInc/materialize.git gh-pages
  63. mkdir -p $RELEASE_DIR
  64. CHANGES_MADE=0
  65. for CHART in $CHARTS; do
  66. CHART_PATH="$CHARTS_DIR/$CHART"
  67. VERSION=$(yq eval '.version' "$CHART_PATH"/Chart.yaml)
  68. echo "Processing chart: $CHART version: $VERSION"
  69. # Check if version already exists
  70. if [ -f "gh-pages/$CHART-$VERSION.tgz" ]; then
  71. echo "Chart $CHART version $VERSION already exists, skipping"
  72. continue
  73. fi
  74. # Lint chart
  75. if ! helm lint "$CHART_PATH"; then
  76. echo "Linting failed for $CHART"
  77. exit 1
  78. fi
  79. # Package chart
  80. helm package "$CHART_PATH" --destination $RELEASE_DIR
  81. CHANGES_MADE=1
  82. done
  83. # Only proceed if we have new packages
  84. if [ $CHANGES_MADE -eq 1 ]; then
  85. # Copy new charts to gh-pages
  86. cp $RELEASE_DIR/*.tgz gh-pages/
  87. # Update the repository index
  88. cd gh-pages
  89. REPO_URL="https://materializeinc.github.io/materialize"
  90. if [ -f index.yaml ]; then
  91. helm repo index . --url "$REPO_URL" --merge index.yaml
  92. else
  93. helm repo index . --url "$REPO_URL"
  94. fi
  95. # Commit and push changes
  96. git add .
  97. git config user.email "noreply@materialize.com"
  98. git config user.name "Buildkite"
  99. git commit -m "helm-charts: publish updated charts"
  100. git diff HEAD~
  101. run_if_not_dry git push origin $GITHUB_PAGES_BRANCH
  102. cd ..
  103. else
  104. echo "No new chart versions to publish"
  105. exit 0
  106. fi
  107. echo "--- Verifying that Helm Chart has been published"
  108. i=0
  109. if ! is_truthy "$CI_DRY_RUN"; then
  110. HELM_CHART_PUBLISHED=false
  111. while (( i < 30 )); do
  112. YAML=$(curl -s "https://materializeinc.github.io/materialize/index.yaml")
  113. CURRENT_HELM_CHART_VERSION=$(echo "$YAML" | yq '.entries["materialize-operator"][0].version')
  114. CURRENT_MZ_VERSION=$(echo "$YAML" | yq '.entries["materialize-operator"][0].appVersion')
  115. if [[ "$CURRENT_HELM_CHART_VERSION" == "$CI_HELM_CHART_VERSION" && "$CURRENT_MZ_VERSION" == "$CI_MZ_VERSION" ]]; then
  116. echo "Helm Chart $CURRENT_HELM_CHART_VERSION with Materialize $CURRENT_MZ_VERSION has successfully been published"
  117. HELM_CHART_PUBLISHED=true
  118. break
  119. fi
  120. echo "Latest version seems to be Helm Chart $CURRENT_HELM_CHART_VERSION with Materialize $CURRENT_MZ_VERSION"
  121. sleep 10
  122. ((i += 1))
  123. done
  124. if [ "$HELM_CHART_PUBLISHED" = false ]; then
  125. echo "Failing because Helm Chart was not successfully published"
  126. exit 1
  127. fi
  128. HIGHEST_HELM_CHART_VERSION=$(echo "$YAML" | yq '.entries["materialize-operator"][].version' | grep -v beta | sort -V | tail -n 1)
  129. if [ "$HIGHEST_HELM_CHART_VERSION" != "$CI_HELM_CHART_VERSION" ]; then
  130. echo "--- Higher helm-chart version $HIGHEST_HELM_CHART_VERSION > $CI_HELM_CHART_VERSION has already been released, not bumping terraform versions"
  131. CI_NO_TERRAFORM_BUMP=1
  132. fi
  133. else
  134. echo "[DRY RUN] Nothing to verify"
  135. fi
  136. if is_truthy "$CI_NO_TERRAFORM_BUMP"; then
  137. echo "--- Not bumping terraform versions"
  138. else
  139. echo "--- Bumping terraform-helm-materialize"
  140. rm -rf terraform-helm-materialize
  141. git clone https://github.com/MaterializeInc/terraform-helm-materialize.git
  142. cd terraform-helm-materialize
  143. sed -i "s/\".*\"\(.*\) # META: helm-chart version/\"$CI_HELM_CHART_VERSION\"\\1 # META: helm-chart version/" variables.tf
  144. sed -i "s/\".*\"\(.*\) # META: mz version/\"$CI_MZ_VERSION\"\\1 # META: mz version/" variables.tf
  145. terraform-docs markdown table --output-file README.md --output-mode inject .
  146. git config user.email "noreply@materialize.com"
  147. git config user.name "Buildkite"
  148. git add variables.tf README.md
  149. git commit -m "Bump to helm-chart $CI_HELM_CHART_VERSION, materialize $CI_MZ_VERSION"
  150. # Bump the patch version by one (v0.1.12 -> v0.1.13)
  151. TERRAFORM_HELM_VERSION=$(git for-each-ref --sort=creatordate --format '%(refname:strip=2)' refs/tags | grep '^v' | tail -n1 | awk -F. -v OFS=. '{$NF += 1; print}')
  152. git tag "$TERRAFORM_HELM_VERSION"
  153. git diff HEAD~
  154. run_if_not_dry git push origin main "$TERRAFORM_HELM_VERSION"
  155. cd ..
  156. declare -A TERRAFORM_VERSION
  157. for repo in terraform-aws-materialize terraform-azurerm-materialize terraform-google-materialize; do
  158. echo "--- Bumping $repo"
  159. rm -rf $repo
  160. git clone https://github.com/MaterializeInc/$repo.git
  161. cd $repo
  162. sed -i "s|github.com/MaterializeInc/terraform-helm-materialize?ref=v[0-9.]*|github.com/MaterializeInc/terraform-helm-materialize?ref=$TERRAFORM_HELM_VERSION|" main.tf
  163. terraform-docs markdown table --output-file README.md --output-mode inject .
  164. # Initialize Terraform to update the lock file
  165. if ! is_truthy "$CI_DRY_RUN"; then
  166. terraform init -upgrade
  167. # If lock file doesn't exist yet (unlikely but possible)
  168. if [ ! -f .terraform.lock.hcl ]; then
  169. echo "No lock file found. Creating it with terraform init."
  170. terraform init
  171. fi
  172. fi
  173. git config user.email "noreply@materialize.com"
  174. git config user.name "Buildkite"
  175. git add main.tf README.md .terraform.lock.hcl
  176. git commit -m "Bump to terraform-helm-materialize $TERRAFORM_HELM_VERSION"
  177. # Bump the patch version by one (v0.1.12 -> v0.1.13)
  178. TERRAFORM_VERSION[$repo]=$(git for-each-ref --sort=creatordate --format '%(refname:strip=2)' refs/tags | grep '^v' | tail -n1 | awk -F. -v OFS=. '{$NF += 1; print}')
  179. git tag "${TERRAFORM_VERSION[$repo]}"
  180. git diff HEAD~
  181. run_if_not_dry git push origin main "${TERRAFORM_VERSION[$repo]}"
  182. cd ..
  183. done
  184. fi
  185. echo "--- Bumping versions in Self-Managed Materialize documentation"
  186. ORCHESTRATORD_VERSION=$(yq -r '.operator.image.tag' misc/helm-charts/operator/values.yaml)
  187. DOCS_BRANCH=self-managed-docs/$(echo "$CI_HELM_CHART_VERSION" | cut -d. -f1,2)
  188. git fetch origin "$DOCS_BRANCH"
  189. git checkout "origin/$DOCS_BRANCH"
  190. git submodule update --init --recursive
  191. git config user.email "noreply@materialize.com"
  192. git config user.name "Buildkite"
  193. VERSIONS_YAML_PATH=doc/user/data/self_managed/latest_versions.yml
  194. yq -i ".operator_helm_chart_version = \"$CI_HELM_CHART_VERSION\"" $VERSIONS_YAML_PATH
  195. yq -i ".environmentd_version = \"$CI_MZ_VERSION\"" $VERSIONS_YAML_PATH
  196. yq -i ".orchestratord_version = \"$ORCHESTRATORD_VERSION\"" $VERSIONS_YAML_PATH
  197. if ! is_truthy "$CI_NO_TERRAFORM_BUMP"; then
  198. yq -i ".terraform_helm_version= \"$TERRAFORM_HELM_VERSION\"" $VERSIONS_YAML_PATH
  199. yq -i ".terraform_gcp_version= \"${TERRAFORM_VERSION[terraform-google-materialize]}\"" $VERSIONS_YAML_PATH
  200. yq -i ".terraform_azure_version= \"${TERRAFORM_VERSION[terraform-azurerm-materialize]}\"" $VERSIONS_YAML_PATH
  201. yq -i ".terraform_aws_version= \"${TERRAFORM_VERSION[terraform-aws-materialize]}\"" $VERSIONS_YAML_PATH
  202. fi
  203. git add $VERSIONS_YAML_PATH
  204. git commit -m "docs: Bump to helm-chart $CI_HELM_CHART_VERSION, environmentd $CI_MZ_VERSION, orchestratord $ORCHESTRATORD_VERSION"
  205. git diff HEAD~
  206. run_if_not_dry git push origin "HEAD:$DOCS_BRANCH"
  207. if ! is_truthy "$CI_NO_TERRAFORM_BUMP"; then
  208. echo "--- Bumping versions in Terraform Nightly tests"
  209. git fetch origin main
  210. git checkout origin/main
  211. git submodule update --init --recursive
  212. sed -i "s|\"git::https://github.com/MaterializeInc/terraform-aws-materialize.git?ref=.*\"|\"git::https://github.com/MaterializeInc/terraform-aws-materialize.git?ref=${TERRAFORM_VERSION[terraform-aws-materialize]}\"|" test/terraform/aws-*/main.tf
  213. sed -i "s|\"git::https://github.com/MaterializeInc/terraform-azurerm-materialize.git?ref=.*\"|\"git::https://github.com/MaterializeInc/terraform-azurerm-materialize.git?ref=${TERRAFORM_VERSION[terraform-azurerm-materialize]}\"|" test/terraform/azure-*/main.tf
  214. sed -i "s|\"git::https://github.com/MaterializeInc/terraform-google-materialize.git?ref=.*\"|\"git::https://github.com/MaterializeInc/terraform-google-materialize.git?ref=${TERRAFORM_VERSION[terraform-google-materialize]}\"|" test/terraform/gcp-*/main.tf
  215. git add test/terraform/*/main.tf
  216. git commit -m "terraform tests: Bump to AWS ${TERRAFORM_VERSION[terraform-aws-materialize]}, GCP ${TERRAFORM_VERSION[terraform-google-materialize]}, Azure ${TERRAFORM_VERSION[terraform-azurerm-materialize]}"
  217. git diff HEAD~
  218. run_if_not_dry git push origin HEAD:main
  219. fi