|
| 1 | +name: release-chart |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - Chart.yaml |
| 8 | + - values.yaml |
| 9 | + - templates/** |
| 10 | + - .helmignore |
| 11 | + - .github/workflows/release-chart.yml |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + release: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - uses: azure/setup-helm@v4 |
| 25 | + |
| 26 | + - name: Read chart version |
| 27 | + id: chart |
| 28 | + run: echo "version=$(awk '/^version:/{print $2}' Chart.yaml)" >> "$GITHUB_OUTPUT" |
| 29 | + |
| 30 | + - name: Skip if version already published |
| 31 | + id: check |
| 32 | + run: | |
| 33 | + if git fetch origin gh-pages 2>/dev/null && \ |
| 34 | + git show origin/gh-pages:index.yaml 2>/dev/null \ |
| 35 | + | grep -q "version: ${{ steps.chart.outputs.version }}$"; then |
| 36 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 37 | + else |
| 38 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 39 | + fi |
| 40 | +
|
| 41 | + - name: Package chart |
| 42 | + if: steps.check.outputs.skip == 'false' |
| 43 | + run: | |
| 44 | + mkdir -p packaged |
| 45 | + helm package . -d packaged |
| 46 | +
|
| 47 | + - name: Publish to gh-pages |
| 48 | + if: steps.check.outputs.skip == 'false' |
| 49 | + run: | |
| 50 | + if git ls-remote --exit-code origin gh-pages >/dev/null 2>&1; then |
| 51 | + git worktree add gh-pages-tree origin/gh-pages |
| 52 | + else |
| 53 | + git worktree add --orphan -b gh-pages gh-pages-tree |
| 54 | + rm -rf gh-pages-tree/* gh-pages-tree/.gitignore 2>/dev/null || true |
| 55 | + fi |
| 56 | + cp packaged/*.tgz gh-pages-tree/ |
| 57 | + cd gh-pages-tree |
| 58 | + base_url="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}" |
| 59 | + if [ -f index.yaml ]; then |
| 60 | + helm repo index . --url "$base_url" --merge index.yaml |
| 61 | + else |
| 62 | + helm repo index . --url "$base_url" |
| 63 | + fi |
| 64 | + git add . |
| 65 | + git -c user.name="github-actions[bot]" \ |
| 66 | + -c user.email="41898282+github-actions[bot]@users.noreply.github.com" \ |
| 67 | + commit -m "publish static-webhost ${{ steps.chart.outputs.version }}" |
| 68 | + git push origin gh-pages |
0 commit comments