Commit 6a5f8f37 authored by James Hutcheon's avatar James Hutcheon Committed by Pierre Smeyers
Browse files

feat(publish): add ability to override default snapshot suffix to enable atomic snapshot builds

parent b77e556c
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -393,6 +393,7 @@ This job [packages](https://helm.sh/docs/helm/helm_package/) the Helm chart. It
| ----------------------------------- | --------------------------------------------- | --------------------------------- |
| `package-args` / `HELM_PACKAGE_ARGS` | The Helm [command with options](https://helm.sh/docs/helm/helm_package/) to perform the packaging (_without dynamic arguments such as the chart path_)   | `package --dependency-update` |
| `publish-snapshot-enabled` / `HELM_PUBLISH_SNAPSHOT_ENABLED` | Set to `true` to enable publishing the snapshot (untested) chart during the packaging step | _none_ (disabled) |
| `publish-snapshot-suffix` / `HELM_PUBLISH_SNAPSHOT_SUFFIX` | Suffix is applied to snapshot chart builds, if one is published | `snapshot` |
| `semrel-release-disabled` / `HELM_SEMREL_RELEASE_DISABLED` | Set to `true` to disable usage of `semantic-release` release info for helm package (see next chapter) | _none_ (enabled) |

#### `semantic-release` integration
@@ -416,8 +417,11 @@ The general version format will be `<x.y.z>-<label>`:
    * on the production branch (`main` or `main` or `master` by default), no trailing label is used
    * on any other branch, `$CI_COMMIT_REF_SLUG` is used as trailing label<br/>
    _(ex: `review-feature-12` on branch `review/feature-12`)_
    * :warning: when `HELM_PUBLISH_SNAPSHOT_ENABLED` is enabled, the chart is additionally packaged (and published) with a label suffixed with `snapshot`<br/>
    * :warning: when `HELM_PUBLISH_SNAPSHOT_ENABLED` is enabled, the chart is additionally packaged (and published) with a label suffixed with the value of `HELM_PUBLISH_SNAPSHOT_SUFFIX`, which defaults to `snapshot`<br/>
    _(ex: `snapshot` on production branch and `review-feature-12-snapshot` on branch `review/feature-12`)_
      * setting `HELM_PUBLISH_SNAPSHOT_SUFFIX` allows you to add a build identifier to the snapshot version, using any valid Gitlab CI variables, e.g. 
        ```HELM_PUBLISH_SNAPSHOT_SUFFIX: snapshot-$CI_PIPELINE_ID```. This is useful if you are producing multiple snapshot builds on the same branch and want the snapshots to be stored uniquely.
      * note that helm chart versions must be valid SemVer2, so any suffix must match valid pre-release and optionally build metadata requirements, as per [semver spec](https://semver.org/#spec-item-9)

#### Package output variables

+6 −0
Original line number Diff line number Diff line
@@ -180,6 +180,12 @@
          "type": "boolean",
          "advanced": true
        },
        {
          "name": "HELM_PUBLISH_SNAPSHOT_SUFFIX",
          "description": "Suffix is applied to snapshot chart builds, if one is published",
          "default": "snapshot",
          "advanced": true
        },
        {
          "name": "HELM_SEMREL_RELEASE_DISABLED",
          "description": "Disable semantic-release integration",
+10 −3
Original line number Diff line number Diff line
@@ -108,6 +108,9 @@ spec:
      description: Set to `true` to enable publishing the snapshot (untested) chart during the packaging step
      type: boolean
      default: false
    publish-snapshot-suffix:
      description: Suffix is applied to snapshot chart builds, if one is published
      default: 'snapshot'
    semrel-release-disabled:
      description: Disable semantic-release integration
      type: boolean
@@ -290,6 +293,7 @@ variables:
  HELM_KUBE_SCORE_ARGS: $[[ inputs.kube-score-args ]]
  HELM_K8S_VERSION: $[[ inputs.k8s-version ]]
  HELM_PUBLISH_SNAPSHOT_ENABLED: $[[ inputs.publish-snapshot-enabled ]]
  HELM_PUBLISH_SNAPSHOT_SUFFIX: $[[ inputs.publish-snapshot-suffix ]]
  HELM_SEMREL_RELEASE_DISABLED: $[[ inputs.semrel-release-disabled ]]
  HELM_CM_PUSH_PLUGIN_VERSION: $[[ inputs.cm-push-plugin-version ]]
  HELM_REVIEW_ENABLED: $[[ inputs.review-enabled ]]
@@ -871,13 +875,16 @@ stages:
    # publish snapshot version if enabled (but not on tag pipeline)
    if [[ "${HELM_PUBLISH_SNAPSHOT_ENABLED}" == "true" ]] && [[ -z "${CI_COMMIT_TAG}" ]]
    then
      log_info "snapshot enabled: also package and publish chart with version: \\e[33;1m${base_version}${version_label}-snapshot\\e[0m"
      # default value of HELM_PUBLISH_SNAPSHOT_SUFFIX is "snapshot"
      snapshot_label="${base_version}${version_label}-${HELM_PUBLISH_SNAPSHOT_SUFFIX}"

      log_info "snapshot enabled: also package and publish chart with version: \\e[33;1m${snapshot_label}\\e[0m"
      mkdir -p /tmp/helm_snapshot
      # shellcheck disable=SC2086
      helm ${TRACE+--debug} $HELM_PACKAGE_ARGS --version ${base_version}${version_label}-snapshot $HELM_CHART_DIR --destination /tmp/helm_snapshot
      helm ${TRACE+--debug} $HELM_PACKAGE_ARGS --version ${snapshot_label} $HELM_CHART_DIR --destination /tmp/helm_snapshot
      snapshot_package=$(ls -1 /tmp/helm_snapshot/*.tgz 2>/dev/null || echo "")
      helm_publish "$snapshot_package"
      echo -e "helm_snapshot_package_name=${chart_name}\\nhelm_snapshot_package_version=${base_version}${version_label}-snapshot\\nhelm_snapshot_package_remote_url=${HELM_PUBLISH_URL}" >> helm-package.env
      echo -e "helm_snapshot_package_name=${chart_name}\\nhelm_snapshot_package_version=${snapshot_label}\\nhelm_snapshot_package_remote_url=${HELM_PUBLISH_URL}" >> helm-package.env
    fi
  }