name: "helm: publish charts" on: # Only run on GitHub releases, not raw tag pushes release: types: [published] # Allow manual trigger with approval workflow_dispatch: permissions: contents: write pages: write jobs: release: runs-on: ubuntu-latest # Require manual approval via environment protection environment: name: helm-release url: https://github.com/${{ github.repository }}/releases steps: - uses: actions/checkout@v4 - name: Setup Helm uses: azure/setup-helm@v4 with: version: v3.12.0 - name: Get chart version id: chart_version run: | CHART_VERSION=$(grep '^version:' deploy/helm/seaweedfs-csi-driver/Chart.yaml | awk '{print $2}') echo "version=$CHART_VERSION" >> $GITHUB_OUTPUT echo "Chart version: $CHART_VERSION" - name: Check if version already exists id: check_version run: | # Fetch gh-pages branch git fetch origin gh-pages || echo "gh-pages branch not found" # Check if gh-pages branch exists if git rev-parse --verify origin/gh-pages >/dev/null 2>&1; then # Check if the version already exists in the index git checkout origin/gh-pages -- helm/index.yaml 2>/dev/null || echo "index.yaml not found" if [ -f helm/index.yaml ]; then CHART_VERSION="${{ steps.chart_version.outputs.version }}" if grep -q "version: $CHART_VERSION" helm/index.yaml; then echo "ERROR: Chart version $CHART_VERSION already exists in the Helm repository!" echo "Please update the version in deploy/helm/seaweedfs-csi-driver/Chart.yaml" exit 1 else echo "Version check passed: $CHART_VERSION is new" fi else echo "No existing index.yaml found, first release" fi else echo "No gh-pages branch found, first release" fi - name: Publish Helm charts uses: stefanprodan/helm-gh-pages@master with: token: ${{ secrets.GITHUB_TOKEN }} charts_dir: deploy/helm/ target_dir: helm branch: gh-pages - name: Comment on release if: github.event_name == 'release' uses: actions/github-script@v7 with: script: | github.rest.issues.createComment({ issue_number: context.payload.release.id, owner: context.repo.owner, repo: context.repo.repo, body: 'Helm chart version ${{ steps.chart_version.outputs.version }} has been published successfully!' })