From d89925b17c9d1b2462f1c46b627aaf39f54a9d61 Mon Sep 17 00:00:00 2001 From: zyy17 Date: Tue, 13 Aug 2024 00:07:28 +0800 Subject: [PATCH] ci: release charts to ACR --- .github/workflows/release.yaml | 38 +++++++++++++++++++++++++++++--- scripts/release-charts-to-acr.sh | 24 ++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 scripts/release-charts-to-acr.sh diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 6cf32d7..a86e126 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,9 +1,19 @@ name: Release Charts on: + pull_request: + types: [ opened, synchronize, reopened, ready_for_review ] + paths-ignore: + - 'docs/**' + - '**.md' + - '.gitignore' push: branches: - main + paths-ignore: + - 'docs/**' + - '**.md' + - '.gitignore' workflow_dispatch: jobs: @@ -13,7 +23,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 @@ -23,7 +33,7 @@ jobs: git config user.email "$GITHUB_ACTOR@users.noreply.github.com" - name: Install Helm - uses: azure/setup-helm@v3 + uses: azure/setup-helm@v4.2.0 with: version: v3.12.1 @@ -35,6 +45,28 @@ jobs: CR_SKIP_EXISTING: true CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + release-charts-to-acr: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Helm + uses: azure/setup-helm@v4.2.0 + with: + version: v3.12.1 + + - name: Login to OCI Registry + run: echo '${{ secrets.ALICLOUD_PASSWORD }}' | helm registry login ${{ vars.OCI_REGISTRY_URL }} -u ${{ secrets.ALICLOUD_USERNAME }} --password-stdin + + - name: Package and Push Helm Charts + shell: bash + env: + OCI_REGISTRY_URL: ${{ vars.OCI_REGISTRY_URL }} + OCI_NAMESPACE: ${{ vars.OCI_NAMESPACE }} + run: | + ./scripts/release-charts-to-acr.sh + release-charts-to-s3: needs: [ release, @@ -42,7 +74,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/scripts/release-charts-to-acr.sh b/scripts/release-charts-to-acr.sh new file mode 100644 index 0000000..52f24e7 --- /dev/null +++ b/scripts/release-charts-to-acr.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +OCI_REGISTRY_URL=${OCI_REGISTRY_URL:-"greptime-registry.cn-hangzhou.cr.aliyuncs.com"} +OCI_NAMESPACE=${OCI_NAMESPACE:-"charts"} +CHARTS_DIR="charts" + +for dir in "$CHARTS_DIR"/*/; do + # Ensure the directory exists and is not empty. + if [ -d "$dir" ]; then + # Get the chart name from the directory path. + chart_name=$(basename "$dir") + + # Package the chart, specifying the directory and output path directly. + helm package "$dir" --destination "$dir" + + # Get the packaged chart file path. + packaged_file=$(find "$dir" -type f -name "*.tgz") + + echo "Package $chart_name to $packaged_file and push to oci://$OCI_REGISTRY_URL/$OCI_NAMESPACE/$chart_name ..." + + # Push the packaged chart to the OCI repository, handling the output path. + helm push "${packaged_file}" "oci://$OCI_REGISTRY_URL/$OCI_NAMESPACE/$chart_name" + fi +done