aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/helm_release.yaml
blob: a3d49465678a621957780954aa08331c01ce92fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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@v3
      
      - name: Setup Helm
        uses: azure/setup-helm@v3
        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!'
            })