From a4a0bf6e68c1d006e2ed71e9441c0dfab2607378 Mon Sep 17 00:00:00 2001 From: Iain Sproat <68657+iainsproat@users.noreply.github.com> Date: Wed, 8 Feb 2023 18:00:55 +0000 Subject: [PATCH] feat(circleci): initial circleci configuration file --- .circleci/config.yml | 100 ++++++++++++++++++++++++++ .circleci/package_and_publish_helm.sh | 57 +++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 .circleci/config.yml create mode 100755 .circleci/package_and_publish_helm.sh diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..b31cce1 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,100 @@ +version: 2.1 + +workflows: + package-helm-chart: + jobs: + - get-version: + filters: + tags: &filter-allow-all + only: /.*/ + + - pre-commit: + filters: + tags: *filter-allow-all + + - helm-package-and-publish: + filters: + tags: *filter-allow-all + branches: &filter-only-main + only: + - main + +jobs: + get-version: + docker: &docker-image + - image: cimg/base:2022.04 + working_directory: &workingdir /tmp/ci + steps: + - checkout + - run: mkdir -p workspace + - run: + name: set version + command: | + echo "export VERSION=$(.circleci/get_version.sh)" >> workspace/env-vars + - run: + name: store version + command: | + cat workspace/env-vars >> $BASH_ENV + - run: + name: echo version + command: | + echo "VERSION=${VERSION}" + - persist_to_workspace: + root: workspace + paths: + - env-vars + + pre-commit: + parameters: + config_file: + default: ./.pre-commit-config.yaml + description: Optional, path to pre-commit config file. + type: string + cache_prefix: + default: '' + description: | + Optional cache prefix to be used on CircleCI. Can be used for cache busting or to ensure multiple jobs use different caches. + type: string + docker: + - image: speckle/pre-commit-runner:latest + resource_class: &docker-resource-class medium + working_directory: *workingdir + steps: + - checkout + - restore_cache: + keys: + - cache-pre-commit-<>-{{ checksum "<>" }} + - run: + name: Install pre-commit hooks + command: pre-commit install-hooks --config <> + - save_cache: + key: cache-pre-commit-<>-{{ checksum "<>" }} + paths: + - ~/.cache/pre-commit + - run: + name: Run pre-commit + command: pre-commit run --all-files --config <> + - run: + command: git --no-pager diff + name: git diff + when: on_fail + + helm-package-and-publish: + docker: + - image: quay.io/helmpack/chart-testing:v3.7.1-amd64 + resource_class: *docker-resource-class + working_directory: *workingdir + steps: + - checkout + - add_ssh_keys: + fingerprints: + - 'TODO: add fingerprint here' + - attach_workspace: + at: /tmp/workspace + - run: + name: populate environment variables + command: | + cat /tmp/workspace/env-vars >> $BASH_ENV + - run: + name: Build and Publish + command: ./.circleci/package_and_publish_helm.sh diff --git a/.circleci/package_and_publish_helm.sh b/.circleci/package_and_publish_helm.sh new file mode 100755 index 0000000..adca40d --- /dev/null +++ b/.circleci/package_and_publish_helm.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +set -eo pipefail + +TEMP_PACKAGE_DIR="${TEMP_PACKAGE_DIR:-"/tmp/.cr-release-packages"}" +HELM_PACKAGE_BRANCH="${HELM_PACKAGE_BRANCH:-"gh-pages"}" +HELM_STABLE_BRANCH="${HELM_STABLE_BRANCH:-"main"}" +HELM_CHART_DIR_PATH="${HELM_CHART_DIR_PATH:-"deploy/helm"}" + +if [[ -z "${VERSION}" ]]; then + echo "VERSION environment variable should be set" + exit 1 +fi + +if [[ -z "${GIT_EMAIL}" ]]; then + echo "GIT_EMAIL environment variable should be set" + exit 1 +fi +if [[ -z "${GIT_USERNAME}" ]]; then + echo "GIT_USERNAME environment variable should be set" + exit 1 +fi + +echo "๐Ÿงน cleaning temporary directory" +rm -rf "${TEMP_PACKAGE_DIR}" || true +mkdir "${TEMP_PACKAGE_DIR}" + +helm version -c + +echo "๐Ÿ—๏ธ building dependencies" +helm dependency build "${HELM_CHART_DIR_PATH}" +echo "๐ŸŽ packaging ${HELM_CHART_DIR_PATH} with version: ${VERSION}" +helm package "${HELM_CHART_DIR_PATH}" --dependency-update --version "${VERSION}" --app-version "${VERSION}" --destination "${TEMP_PACKAGE_DIR}" + +echo "โฌ checking out git branch '${HELM_PACKAGE_BRANCH}'" +git config user.email "${GIT_EMAIL}" +git config user.name "${GIT_USERNAME}" +git fetch +git switch "${HELM_PACKAGE_BRANCH}" +if [[ -n "${CIRCLE_TAG}" || "${CIRCLE_BRANCH}" == "${HELM_STABLE_BRANCH}" ]]; then + echo "๐Ÿ›ป copying packages to stable directory" + cp -a "${TEMP_PACKAGE_DIR}/." stable/ + pushd stable + helm repo index . + popd +else + cp -a "${TEMP_PACKAGE_DIR}/." incubator/ + echo "๐Ÿ›ป copying packages to incubator directory" + pushd incubator + helm repo index . + popd +fi + +echo "โซ adding, commiting, and pushing to git repository" +git add . +git commit -m "updating helm chart to version ${VERSION}" +git push --set-upstream origin "${HELM_PACKAGE_BRANCH}"