Skip to content

Commit 8ce0284

Browse files
authored
feat: add new github action for tidb-operator-publish release v1.x (#6611)
1 parent 2359588 commit 8ce0284

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

.github/workflows/release-v1.yaml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Release Charts v1
2+
3+
on:
4+
push:
5+
tags:
6+
- "v1.*.*"
7+
workflow_dispatch:
8+
inputs:
9+
git_ref:
10+
description: 'Branch or commit hash (for v1.x branch)'
11+
required: true
12+
type: string
13+
release_tag:
14+
description: 'Release tag (empty means the same with GitRef)'
15+
required: false
16+
type: string
17+
br_federation:
18+
description: 'Whether to release BR federation manager'
19+
required: false
20+
type: boolean
21+
default: true
22+
fips:
23+
description: 'Whether to enable FIPS'
24+
required: false
25+
type: boolean
26+
default: false
27+
28+
jobs:
29+
release-charts:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
with:
34+
ref: ${{ github.event.inputs.git_ref || github.ref }}
35+
36+
- name: Set up Helm
37+
uses: azure/setup-helm@v4
38+
with:
39+
version: '3.14.0'
40+
41+
- name: Determine release tag and validate
42+
id: release_tag
43+
run: |
44+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
45+
RELEASE_TAG="${{ github.event.inputs.release_tag }}"
46+
if [ -z "$RELEASE_TAG" ]; then
47+
RELEASE_TAG="${{ github.event.inputs.git_ref }}"
48+
fi
49+
if [ "${{ github.event.inputs.fips }}" == "true" ]; then
50+
RELEASE_TAG="${RELEASE_TAG}-fips"
51+
fi
52+
BR_FEDERATION="${{ github.event.inputs.br_federation }}"
53+
if [ -z "$BR_FEDERATION" ]; then
54+
BR_FEDERATION="true"
55+
fi
56+
else
57+
# push tags
58+
RELEASE_TAG="${{ github.ref_name }}"
59+
BR_FEDERATION="true"
60+
fi
61+
62+
if [[ ! "$RELEASE_TAG" =~ ^v1\.[0-9]+\.[0-9]+ ]]; then
63+
echo "Error: Release tag must be v1.x.x format, got: $RELEASE_TAG"
64+
echo "This workflow is only for v1.x releases. Please use the correct version format."
65+
exit 1
66+
fi
67+
68+
echo "tag=${RELEASE_TAG}" >> $GITHUB_OUTPUT
69+
echo "br_federation=${BR_FEDERATION}" >> $GITHUB_OUTPUT
70+
71+
- name: Build charts
72+
env:
73+
V_RELEASE: ${{ steps.release_tag.outputs.tag }}
74+
BR_FEDERATION: ${{ steps.release_tag.outputs.br_federation }}
75+
run: |
76+
make charts/build
77+
78+
- name: Update index.yaml
79+
if: ${{ !contains(steps.release_tag.outputs.tag, 'latest') && !contains(steps.release_tag.outputs.tag, 'nightly') && !contains(steps.release_tag.outputs.tag, 'test') }}
80+
run: |
81+
set -e
82+
CHARTS_BUILD_DIR="output/chart"
83+
cd ${CHARTS_BUILD_DIR}
84+
curl -f http://charts.pingcap.org/index.yaml -o index.yaml 2>/dev/null || true
85+
helm repo index . --url https://charts.pingcap.org/ --merge index.yaml 2>/dev/null || helm repo index . --url https://charts.pingcap.org/
86+
87+
- name: Upload all charts and index.yaml to Tencent COS
88+
uses: sylingd/tencent-cos-and-cdn-action@v1
89+
with:
90+
secret_id: ${{ secrets.TENCENT_COS_ACCESS_KEY }}
91+
secret_key: ${{ secrets.TENCENT_COS_SECRET_KEY }}
92+
cos_bucket: ${{ vars.TENCENT_COS_BUCKET_NAME }}
93+
cos_region: ap-beijing
94+
local_path: ./output/chart
95+
remote_path: /

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,8 @@ docker-release:
259259
.PHONY: help
260260
help: ## Display this help.
261261
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
262+
263+
264+
.PHONY: charts/build
265+
charts/build:
266+
$(ROOT)/hack/charts-build.sh

hack/charts-build.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2020 PingCAP, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
ROOT=$(cd $(dirname "${BASH_SOURCE[0]}")/..; pwd -P)
22+
23+
RELEASE_TAG=${V_RELEASE:-"test"}
24+
CHARTS_BUILD_DIR="output/chart"
25+
CHART_ITEMS="tidb-operator tidb-drainer tidb-lightning"
26+
BR_FEDERATION=${BR_FEDERATION:-"true"}
27+
28+
mkdir -p ${CHARTS_BUILD_DIR}
29+
30+
# Build charts
31+
for chartItem in ${CHART_ITEMS}; do
32+
[ ! -d "charts/${chartItem}" ] && continue
33+
34+
chartPrefixName="${chartItem}-${RELEASE_TAG}"
35+
36+
# Update Chart.yaml
37+
sed -i.bak "s/^version:.*/version: ${RELEASE_TAG}/g" charts/${chartItem}/Chart.yaml
38+
sed -i.bak "s/^appVersion:.*/appVersion: ${RELEASE_TAG}/g" charts/${chartItem}/Chart.yaml
39+
rm -f charts/${chartItem}/Chart.yaml.bak
40+
41+
# Update values.yaml
42+
sed -i.bak -E "s#pingcap/(tidb-operator|tidb-backup-manager):[^[:space:]]*#pingcap/\\1:${RELEASE_TAG}#g" charts/${chartItem}/values.yaml 2>/dev/null || true
43+
rm -f charts/${chartItem}/values.yaml.bak 2>/dev/null || true
44+
45+
# Package chart
46+
tar -zcf ${CHARTS_BUILD_DIR}/${chartPrefixName}.tgz -C charts ${chartItem}
47+
sha256sum ${CHARTS_BUILD_DIR}/${chartPrefixName}.tgz > ${CHARTS_BUILD_DIR}/${chartPrefixName}.sha256
48+
done
49+
50+
# Handle br-federation
51+
if [[ "$BR_FEDERATION" == "true" ]] && [ -d "charts/br-federation" ]; then
52+
chartItem="br-federation"
53+
chartPrefixName="${chartItem}-${RELEASE_TAG}"
54+
sed -i.bak "s/^version:.*/version: ${RELEASE_TAG}/g" charts/${chartItem}/Chart.yaml
55+
sed -i.bak "s/^appVersion:.*/appVersion: ${RELEASE_TAG}/g" charts/${chartItem}/Chart.yaml
56+
rm -f charts/${chartItem}/Chart.yaml.bak
57+
sed -i.bak -E "s#pingcap/br-federation-manager:[^[:space:]]*#pingcap/br-federation-manager:${RELEASE_TAG}#g" charts/${chartItem}/values.yaml
58+
rm -f charts/${chartItem}/values.yaml.bak
59+
tar -zcf ${CHARTS_BUILD_DIR}/${chartPrefixName}.tgz -C charts ${chartItem}
60+
sha256sum ${CHARTS_BUILD_DIR}/${chartPrefixName}.tgz > ${CHARTS_BUILD_DIR}/${chartPrefixName}.sha256
61+
fi

0 commit comments

Comments
 (0)