From 28978f9e1d50afe0c7313031d6acefdb86d27f33 Mon Sep 17 00:00:00 2001 From: Christian Bianchi Date: Wed, 7 Aug 2024 10:36:24 +0200 Subject: [PATCH] Release automation (#120) --- .github/workflows/make-release.yaml | 57 ++++++++++++++++++ .github/workflows/prepare-release.yaml | 58 +++++++++++++++++++ examples/PrivateLink/main.tf | 15 ----- examples/PrivateLink/provider.tf | 14 +++++ examples/PrivateLink/provider.tf.template | 14 +++++ examples/PrivateLinkAzure/main.tf | 21 ------- examples/PrivateLinkAzure/provider.tf | 20 +++++++ .../PrivateLinkAzure/provider.tf.template | 20 +++++++ examples/PrivateServiceConnect/main.tf | 15 ----- examples/PrivateServiceConnect/provider.tf | 14 +++++ .../provider.tf.template | 14 +++++ examples/basic/main.tf | 15 ----- examples/basic/provider.tf | 14 +++++ examples/basic/provider.tf.template | 14 +++++ 14 files changed, 239 insertions(+), 66 deletions(-) create mode 100644 .github/workflows/make-release.yaml create mode 100644 .github/workflows/prepare-release.yaml create mode 100644 examples/PrivateLink/provider.tf create mode 100644 examples/PrivateLink/provider.tf.template create mode 100644 examples/PrivateLinkAzure/provider.tf create mode 100644 examples/PrivateLinkAzure/provider.tf.template create mode 100644 examples/PrivateServiceConnect/provider.tf create mode 100644 examples/PrivateServiceConnect/provider.tf.template create mode 100644 examples/basic/provider.tf create mode 100644 examples/basic/provider.tf.template diff --git a/.github/workflows/make-release.yaml b/.github/workflows/make-release.yaml new file mode 100644 index 00000000..1b91a766 --- /dev/null +++ b/.github/workflows/make-release.yaml @@ -0,0 +1,57 @@ +name: Make release + +on: + push: + branches: + - "main" + +defaults: + run: + shell: bash + +jobs: + release: + permissions: + contents: write + pull-requests: write + + runs-on: [dataplane, self-hosted, linux, x64, small] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check release + id: check + run: | + last_commit_msg="$(git log -1 --pretty=%B|head -n1)" + + echo "Last commit msg = '${last_commit_msg}'" + + if [[ $last_commit_msg == \[RELEASE* ]] + then + version="$(echo "$last_commit_msg" | cut -d"]" -f1 | cut -d" " -f2)" + else + echo "Latest commit does not look like a release commit" + echo "release-version=null" >> $GITHUB_OUTPUT + exit 0 + fi + + # strip any leading "v" from the release. + version="${version#v}" + + # validate semver. + if [[ $version =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]; then + echo "Preparing release $version" + else + echo "Invalid semver $version in branch name" + exit 1 + fi + + echo "release-version=${version}" >> $GITHUB_OUTPUT + + - name: Create tag + if: ${{ steps.check.outputs.release-version != 'null' }} + run: | + tag="disabled-v${{ steps.check.outputs.release-version }}" + git tag $tag + git push origin $tag diff --git a/.github/workflows/prepare-release.yaml b/.github/workflows/prepare-release.yaml new file mode 100644 index 00000000..abede652 --- /dev/null +++ b/.github/workflows/prepare-release.yaml @@ -0,0 +1,58 @@ +name: Prepare release + +on: + workflow_dispatch: + inputs: + version: + required: true + description: "The semver formatted version for the new release i.e 0.3.1" + +defaults: + run: + shell: bash + +jobs: + bump: + permissions: + contents: write + pull-requests: write + + runs-on: [dataplane, self-hosted, linux, x64, small] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Bump provider version in examples + id: bump + run: | + version="${{ inputs.version }}" + + # strip any leading "v" from the release. + version="${version#v}" + + # validate semver. + if [[ $version =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]; then + echo "Preparing release $version" + else + echo "Invalid semver $version in branch name" + exit 1 + fi + + echo "release-version=${version}" >> $GITHUB_OUTPUT + + # Bump semver in examples + export CLICKHOUSE_TERRAFORM_PROVIDER_VERSION="$version" + for f in `find examples -name provider.tf.template` + do + dst="${f%.template}" + cat $f | envsubst > $dst + + sed -i '1s/^/# This file is generated automatically please do not edit\n/' $dst + done + + - name: Open PR with changes + id: pr + uses: peter-evans/create-pull-request@v6 + with: + branch: "bump-provider-to-${{ steps.bump.outputs.release-version }}" + title: "[RELEASE ${{ steps.bump.outputs.release-version }}] Bump provider version in examples" diff --git a/examples/PrivateLink/main.tf b/examples/PrivateLink/main.tf index 8615fbb0..89f3b7f5 100644 --- a/examples/PrivateLink/main.tf +++ b/examples/PrivateLink/main.tf @@ -1,12 +1,3 @@ -terraform { - required_providers { - clickhouse = { - version = "0.0.10" - source = "ClickHouse/clickhouse" - } - } -} - variable "organization_id" { type = string } @@ -19,12 +10,6 @@ variable "token_secret" { type = string } -provider "clickhouse" { - organization_id = var.organization_id - token_key = var.token_key - token_secret = var.token_secret -} - resource "clickhouse_service" "aws_red" { name = "red" cloud_provider = "aws" diff --git a/examples/PrivateLink/provider.tf b/examples/PrivateLink/provider.tf new file mode 100644 index 00000000..6ce74220 --- /dev/null +++ b/examples/PrivateLink/provider.tf @@ -0,0 +1,14 @@ +terraform { + required_providers { + clickhouse = { + version = "0.0.10" + source = "ClickHouse/clickhouse" + } + } +} + +provider "clickhouse" { + organization_id = var.organization_id + token_key = var.token_key + token_secret = var.token_secret +} diff --git a/examples/PrivateLink/provider.tf.template b/examples/PrivateLink/provider.tf.template new file mode 100644 index 00000000..f9e76961 --- /dev/null +++ b/examples/PrivateLink/provider.tf.template @@ -0,0 +1,14 @@ +terraform { + required_providers { + clickhouse = { + version = "${CLICKHOUSE_TERRAFORM_PROVIDER_VERSION}" + source = "ClickHouse/clickhouse" + } + } +} + +provider "clickhouse" { + organization_id = var.organization_id + token_key = var.token_key + token_secret = var.token_secret +} diff --git a/examples/PrivateLinkAzure/main.tf b/examples/PrivateLinkAzure/main.tf index eab761af..f230c8cb 100644 --- a/examples/PrivateLinkAzure/main.tf +++ b/examples/PrivateLinkAzure/main.tf @@ -1,18 +1,3 @@ -terraform { - required_providers { - clickhouse = { - version = "0.0.10" - source = "ClickHouse/clickhouse" - } - - azapi = { - source = "Azure/azapi" - version = "1.13.1" - } - - } -} - variable "organization_id" { type = string } @@ -40,12 +25,6 @@ variable "private_endpoint_azure_bar_uuid" { default = "" } -provider "clickhouse" { - organization_id = var.organization_id - token_key = var.token_key - token_secret = var.token_secret -} - resource "clickhouse_service" "azure_red" { name = "red" cloud_provider = "azure" diff --git a/examples/PrivateLinkAzure/provider.tf b/examples/PrivateLinkAzure/provider.tf new file mode 100644 index 00000000..95b40b4b --- /dev/null +++ b/examples/PrivateLinkAzure/provider.tf @@ -0,0 +1,20 @@ +terraform { + required_providers { + clickhouse = { + version = "0.0.10" + source = "ClickHouse/clickhouse" + } + + azapi = { + source = "Azure/azapi" + version = "1.13.1" + } + + } +} + +provider "clickhouse" { + organization_id = var.organization_id + token_key = var.token_key + token_secret = var.token_secret +} diff --git a/examples/PrivateLinkAzure/provider.tf.template b/examples/PrivateLinkAzure/provider.tf.template new file mode 100644 index 00000000..18807fd1 --- /dev/null +++ b/examples/PrivateLinkAzure/provider.tf.template @@ -0,0 +1,20 @@ +terraform { + required_providers { + clickhouse = { + version = "${CLICKHOUSE_TERRAFORM_PROVIDER_VERSION}" + source = "ClickHouse/clickhouse" + } + + azapi = { + source = "Azure/azapi" + version = "1.13.1" + } + + } +} + +provider "clickhouse" { + organization_id = var.organization_id + token_key = var.token_key + token_secret = var.token_secret +} diff --git a/examples/PrivateServiceConnect/main.tf b/examples/PrivateServiceConnect/main.tf index 5bea3615..3812bf10 100644 --- a/examples/PrivateServiceConnect/main.tf +++ b/examples/PrivateServiceConnect/main.tf @@ -1,12 +1,3 @@ -terraform { - required_providers { - clickhouse = { - version = "0.0.10" - source = "ClickHouse/clickhouse" - } - } -} - variable "organization_id" { type = string } @@ -19,12 +10,6 @@ variable "token_secret" { type = string } -provider "clickhouse" { - organization_id = var.organization_id - token_key = var.token_key - token_secret = var.token_secret -} - resource "clickhouse_service" "gcp_red" { name = "gcp_red" cloud_provider = "gcp" diff --git a/examples/PrivateServiceConnect/provider.tf b/examples/PrivateServiceConnect/provider.tf new file mode 100644 index 00000000..6ce74220 --- /dev/null +++ b/examples/PrivateServiceConnect/provider.tf @@ -0,0 +1,14 @@ +terraform { + required_providers { + clickhouse = { + version = "0.0.10" + source = "ClickHouse/clickhouse" + } + } +} + +provider "clickhouse" { + organization_id = var.organization_id + token_key = var.token_key + token_secret = var.token_secret +} diff --git a/examples/PrivateServiceConnect/provider.tf.template b/examples/PrivateServiceConnect/provider.tf.template new file mode 100644 index 00000000..f9e76961 --- /dev/null +++ b/examples/PrivateServiceConnect/provider.tf.template @@ -0,0 +1,14 @@ +terraform { + required_providers { + clickhouse = { + version = "${CLICKHOUSE_TERRAFORM_PROVIDER_VERSION}" + source = "ClickHouse/clickhouse" + } + } +} + +provider "clickhouse" { + organization_id = var.organization_id + token_key = var.token_key + token_secret = var.token_secret +} diff --git a/examples/basic/main.tf b/examples/basic/main.tf index 48e11e9d..813a5371 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -1,12 +1,3 @@ -terraform { - required_providers { - clickhouse = { - version = "0.0.10" - source = "ClickHouse/clickhouse" - } - } -} - variable "organization_id" { type = string } @@ -19,12 +10,6 @@ variable "token_secret" { type = string } -provider clickhouse { - organization_id = var.organization_id - token_key = var.token_key - token_secret = var.token_secret -} - resource "clickhouse_service" "service" { name = "My Terraform Service" cloud_provider = "aws" diff --git a/examples/basic/provider.tf b/examples/basic/provider.tf new file mode 100644 index 00000000..716343a1 --- /dev/null +++ b/examples/basic/provider.tf @@ -0,0 +1,14 @@ +terraform { + required_providers { + clickhouse = { + version = "0.0.10" + source = "ClickHouse/clickhouse" + } + } +} + +provider clickhouse { + organization_id = var.organization_id + token_key = var.token_key + token_secret = var.token_secret +} diff --git a/examples/basic/provider.tf.template b/examples/basic/provider.tf.template new file mode 100644 index 00000000..30db4fc6 --- /dev/null +++ b/examples/basic/provider.tf.template @@ -0,0 +1,14 @@ +terraform { + required_providers { + clickhouse = { + version = "${CLICKHOUSE_TERRAFORM_PROVIDER_VERSION}" + source = "ClickHouse/clickhouse" + } + } +} + +provider clickhouse { + organization_id = var.organization_id + token_key = var.token_key + token_secret = var.token_secret +}