Merge pull request #11 from selectel/add-envoy-gateway #25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish Helm Chart to GHCR | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - '**/**' | |
| paths: | |
| - '.github/workflows/release.yml' | |
| - 'charts/**' | |
| - '!**.md' | |
| jobs: | |
| get-charts: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| output_charts_changed: ${{ steps.get-charts.outputs.output_charts_changed }} | |
| output_publish_charts: ${{ steps.get-charts.outputs.output_publish_charts }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| path: charts | |
| fetch-depth: 2 # to be able to obtain files changed in the latest commit | |
| - name: Setup Helm | |
| uses: azure/setup-helm@v4.3.1 | |
| with: | |
| version: '3.18.3' | |
| - name: Get modified charts | |
| id: get-charts | |
| run: | | |
| cd charts | |
| files_changed="$(git show --pretty="" --name-only)" | |
| echo "files_changed:" | |
| echo "$files_changed" | |
| charts_changed=($(echo "$files_changed" | xargs dirname | grep -o "charts/[^/]*" | sed "s/charts\///g" | sort | uniq || true)) | |
| if [ ${#charts_changed[@]} -eq 0 ]; then | |
| echo "No charts changed, skip publish job" | |
| else | |
| echo "List of changed charts, go to publish job:" | |
| for chart in "${charts_changed[@]}" | |
| do | |
| echo $chart $(helm show chart ./charts/$chart | yq .version) | |
| done | |
| # Join array elements with a comma | |
| joined_string=$(IFS=,; echo "${charts_changed[*]}") | |
| echo "output_charts_changed=${joined_string}" >> $GITHUB_OUTPUT | |
| echo "output_publish_charts=true" >> $GITHUB_OUTPUT | |
| fi | |
| publish-helm-chart: | |
| runs-on: ubuntu-latest | |
| needs: get-charts | |
| if: ${{ needs.get-charts.outputs.output_publish_charts == 'true' }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Helm | |
| uses: azure/setup-helm@v4.3.1 | |
| with: | |
| version: '3.18.3' | |
| - name: Setup yq | |
| uses: mikefarah/yq@v4.47.1 | |
| - name: Package Helm charts and push to GHCR | |
| run: | | |
| # Access the output as a string | |
| string_chaged_charts="${{ needs.get-charts.outputs.output_charts_changed }}" | |
| # Convert the string back to an array | |
| IFS=, read -r -a charts_list <<< "$string_chaged_charts" | |
| for chart in "${charts_list[@]}" | |
| do | |
| chart_map_version[$chart]=$(helm show chart ./charts/$chart | yq .version) | |
| echo $chart ${chart_map_version[$chart]} | |
| helm package ./charts/${chart} | |
| helm push ${chart}-${chart_map_version[$chart]}.tgz oci://ghcr.io/${{ github.repository_owner }}/mks-charts | |
| done |