name: Build and publish chart on: pull_request: push: branches: - main tags: - 'v*' jobs: chart: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 with: fetch-depth: 0 - name: Install yq uses: mikefarah/yq@v4.28.2 - name: Build chart for CI if: ${{ !startsWith(github.ref, 'refs/tags/') }} run: | make chart - name: Build chart for release if: startsWith(github.ref, 'refs/tags/') run: | REPO=quay.io/costoolkit/elemental-operator TAG=${GITHUB_REF##*/} make chart - name: Publish chart to release uses: fnkr/github-action-ghr@v1 if: startsWith(github.ref, 'refs/tags/') env: GHR_COMPRESS: tgz GHR_PATH: build/ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GHR_REPLACE: true - name: Install Helm if: startsWith(github.ref, 'refs/tags/') uses: azure/setup-helm@v1 with: version: v3.7.1 - name: Set chart output id: chart run: | CHART=$(find . -type f -name "elemental-operator*.tgz" -print) echo "chart_name=$CHART" >> $GITHUB_OUTPUT - name: Test chart values if: ${{ !startsWith(github.ref, 'refs/tags/') }} run: | REPO=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .image.repository) TAG=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .image.tag) if [ "$REPO" != "quay.io/costoolkit/elemental-operator-ci" ];then echo "REPO on the built chart is not the expected value" echo "Expected quay.io/costoolkit/elemental-operator but got $REPO" exit 1 fi - name: Test release chart values if: startsWith(github.ref, 'refs/tags/') run: | REPO=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .image.repository) TAG=$(helm show values ${{ steps.chart.outputs.chart_name }}|yq .image.tag) if [ "$REPO" != "quay.io/costoolkit/elemental-operator" ];then echo "REPO on the built chart is not the expected value" echo "Expected quay.io/costoolkit/elemental-operator but got $REPO" exit 1 fi if [ "$TAG" != "${GITHUB_REF##*/}" ];then echo "TAG on the built chart is not the expected value" echo "Expected ${GITHUB_REF##*/} but got $TAG" exit 1 fi - name: Build and push index if: startsWith(github.ref, 'refs/tags/') run: | git config --global user.email "${{ github.actor }}@users.noreply.github.com" git config --global user.name "${{ github.actor }}" git checkout gh-pages rm index.yaml helm repo index --url https://rancher.github.io/elemental-operator . git add index.yaml build/ -f git commit -m "Updating helm repo to main commit ${{ github.sha }}" git push --set-upstream origin gh-pages