From 13d52b463777baedc492861c9b25b54de8294bf0 Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Tue, 12 Mar 2024 20:47:09 +0800 Subject: [PATCH] chore(apps/prod/tekton/configs/tasks): add tag for release branches when building (#1025) Signed-off-by: wuhuizuo --------- Signed-off-by: wuhuizuo --- .../pingcap-build-package-darwin.yaml | 2 +- .../pipelines/pingcap-build-package.yaml | 2 +- .../tekton/configs/tasks/kustomization.yaml | 3 +- .../tasks/pingcap-get-release-version.yaml | 2 +- .../pingcap-get-set-release-version.yaml | 50 +++++++++++++++++++ .../tasks/publish-tiup-from-oci-artifact.yaml | 14 +++--- 6 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 apps/prod/tekton/configs/tasks/pingcap-get-set-release-version.yaml diff --git a/apps/prod/tekton/configs/pipelines/pingcap-build-package-darwin.yaml b/apps/prod/tekton/configs/pipelines/pingcap-build-package-darwin.yaml index d9e50540e..6a9315ca5 100644 --- a/apps/prod/tekton/configs/pipelines/pingcap-build-package-darwin.yaml +++ b/apps/prod/tekton/configs/pipelines/pingcap-build-package-darwin.yaml @@ -87,7 +87,7 @@ spec: runAfter: - checkout taskRef: - name: pingcap-get-release-version + name: pingcap-get-set-release-version workspaces: - name: source workspace: source diff --git a/apps/prod/tekton/configs/pipelines/pingcap-build-package.yaml b/apps/prod/tekton/configs/pipelines/pingcap-build-package.yaml index 6ef4f04b6..a52e8a92c 100644 --- a/apps/prod/tekton/configs/pipelines/pingcap-build-package.yaml +++ b/apps/prod/tekton/configs/pipelines/pingcap-build-package.yaml @@ -93,7 +93,7 @@ spec: runAfter: - checkout taskRef: - name: pingcap-get-release-version + name: pingcap-get-set-release-version workspaces: - name: source workspace: source diff --git a/apps/prod/tekton/configs/tasks/kustomization.yaml b/apps/prod/tekton/configs/tasks/kustomization.yaml index f59001543..419e33f42 100644 --- a/apps/prod/tekton/configs/tasks/kustomization.yaml +++ b/apps/prod/tekton/configs/tasks/kustomization.yaml @@ -30,8 +30,9 @@ resources: - pingcap-compose-offline-pkgs.yaml - pingcap-deliver-image.yaml - pingcap-get-builder-image.yaml - - pingcap-git-clone-ext.yaml - pingcap-get-release-version.yaml + - pingcap-get-set-release-version.yaml + - pingcap-git-clone-ext.yaml - publish-tiup-from-oci-artifact.yaml - restore-cache-with-ks3.yaml - save-cache-with-ks3.yaml diff --git a/apps/prod/tekton/configs/tasks/pingcap-get-release-version.yaml b/apps/prod/tekton/configs/tasks/pingcap-get-release-version.yaml index 054686037..f981aca26 100644 --- a/apps/prod/tekton/configs/tasks/pingcap-get-release-version.yaml +++ b/apps/prod/tekton/configs/tasks/pingcap-get-release-version.yaml @@ -25,7 +25,7 @@ spec: if [[ "$RESULT_VERSION" == *"-alpha-"* ]]; then echo "First patch version detected. Skipping patch increment." else - echo "The code is checkouted on branch, I will increase the path version." + echo "The code is checkouted on branch, I will increase the patch version." # Extract version components version_part=$(echo "$RESULT_VERSION" | cut -d '-' -f 1) diff --git a/apps/prod/tekton/configs/tasks/pingcap-get-set-release-version.yaml b/apps/prod/tekton/configs/tasks/pingcap-get-set-release-version.yaml new file mode 100644 index 000000000..6a60f4122 --- /dev/null +++ b/apps/prod/tekton/configs/tasks/pingcap-get-set-release-version.yaml @@ -0,0 +1,50 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: pingcap-get-set-release-version +spec: + results: + - description: The release version of the git repo + name: version + type: string + steps: + - image: alpine/git:2.40.1 + name: git-describe + workingDir: $(workspaces.source.path) + resources: + requests: + memory: 512Mi + cpu: '100m' + script: | + #!/bin/sh + set -e + + RESULT_VERSION="$(git describe --tags --always --dirty --exclude 'v20[0-9][0-9].[0-1][0-9].[0-3][0-9]*')" + if [[ "$RESULT_VERSION" =~ "-[0-9]+-g[0-9a-f]{7,10}(-dirty)?$" ]]; then + # Check if "-alpha-" is included in the version string + if [[ "$RESULT_VERSION" == *"-alpha-"* ]]; then + echo "First patch version detected. Skipping patch increment." + else + echo "The code is checkouted on branch, I will increase the patch version." + # Extract version components + version_part=$(echo "$RESULT_VERSION" | cut -d '-' -f 1) + + major=$(echo "$version_part" | cut -d '.' -f 1) + minor=$(echo "$version_part" | cut -d '.' -f 2) + patch=$(echo "$version_part" | cut -d '.' -f 3) + + # Increment the patch version + ((++patch)) + # force add a local tag for build. + git_tag="$major.$minor.$patch" + git tag --contains | git tag -d + git tag -f ${git_tag} + + RESULT_VERSION="${git_tag}-pre" + fi + fi + + printf "%s" "${RESULT_VERSION}" > $(results.version.path) + + workspaces: + - name: source diff --git a/apps/prod/tekton/configs/tasks/publish-tiup-from-oci-artifact.yaml b/apps/prod/tekton/configs/tasks/publish-tiup-from-oci-artifact.yaml index a66f95599..748272a73 100644 --- a/apps/prod/tekton/configs/tasks/publish-tiup-from-oci-artifact.yaml +++ b/apps/prod/tekton/configs/tasks/publish-tiup-from-oci-artifact.yaml @@ -42,9 +42,9 @@ spec: # publish the tiup packages :> publish.sh tiup_last_index=$(yq --output-format=yaml '.["net.pingcap.tibuild.tiup"] | length - 1' artifact-config.json) - os="$(yq --output-format=yaml '.os' artifact-config.json)" - architecture="$(yq --output-format=yaml '.architecture' artifact-config.json)" - version="$(yq --output-format=yaml '.version' artifact-config.json)" + os=$(yq --output-format=yaml '.["net.pingcap.tibuild.os"]' artifact-config.json) + architecture=$(yq --output-format=yaml '.["net.pingcap.tibuild.architecture"]' artifact-config.json) + version=$(yq --output-format=yaml '.["org.opencontainers.image.version"]' artifact-config.json) if [ "$(params.nightly)" == "true" ]; then # from vX.Y.Z-alpha-574-g75b451c454 => vX.Y.Z-alpha-nightly version=`echo "$version" | sed -E 's/\-[0-9]+-g[0-9a-f]+$//'` @@ -52,13 +52,13 @@ spec: fi for i in `seq 0 $tiup_last_index`; do - pkg_file="$(yq --output-format=yaml .["net.pingcap.tibuild.tiup"][$i].file artifact-config.json)" + pkg_file="$(yq --output-format=yaml .[\"net.pingcap.tibuild.tiup\"][$i].file artifact-config.json)" pkg_name=$(echo "$pkg_file" | sed -E "s/-v[0-9]+.+//") - entrypoint="$(yq --output-format=yaml .["net.pingcap.tibuild.tiup"][$i].entrypoint artifact-config.json)" - desc="$(yq --output-format=yaml .["net.pingcap.tibuild.tiup"][$i].description artifact-config.json)" + entrypoint="$(yq --output-format=yaml .[\"net.pingcap.tibuild.tiup\"][$i].entrypoint artifact-config.json)" + desc="$(yq --output-format=yaml .[\"net.pingcap.tibuild.tiup\"][$i].description artifact-config.json)" # tiup mirror publish [flags] - if yq -e -oy ".["net.pingcap.tibuild.tiup"][$i].standalone" artifact-config.json; then + if yq -e -oy ".[\"net.pingcap.tibuild.tiup\"][$i].standalone" artifact-config.json; then printf 'tiup mirror publish %s %s %s %s --os %s --arch %s --standalone --desc "%s"\n' \ $pkg_name $version $pkg_file $entrypoint $os $architecture "$desc" \ >> publish.sh