name: "Charts: Validate" on: workflow_dispatch: pull_request: paths: - "charts/**" concurrency: group: ${{ github.head_ref }}-validate # cancel-in-progress: true jobs: pr-metadata: name: Collect PR metadata runs-on: ubuntu-20.04 outputs: branch: ${{ steps.branch-name.outputs.current_branch }} isFork: ${{ github.event.pull_request.head.repo.full_name != github.repository }} addedOrModified: ${{ steps.filter.outputs.addedOrModified }} addedOrModifiedFiles: ${{ steps.filter.outputs.addedOrModified_files }} addedOrModifiedCharts: ${{ steps.filter-charts.outputs.addedOrModified }} steps: - name: Get branch name id: branch-name uses: tj-actions/branch-names@v5.1 - name: Checkout uses: actions/checkout@v2 - name: Collect changed files uses: dorny/paths-filter@v2 id: filter with: list-files: shell filters: | addedOrModified: - added|modified: 'charts/**' - name: Collect changed charts if: | steps.filter.outputs.addedOrModified == 'true' id: filter-charts run: | CHARTS=() PATHS=(${{ steps.filter.outputs.addedOrModified_files }}) # Get only the chart paths for CHARTPATH in "${PATHS[@]}" do IFS='/' read -r -a path_parts <<< "${CHARTPATH}" CHARTS+=("${path_parts[1]}/${path_parts[2]}") done # Remove duplicates CHARTS=( `printf "%s\n" "${CHARTS[@]}" | sort -u` ) # Set output to changed charts printf "::set-output name=addedOrModified::%s\n" "${CHARTS[*]}" generate-readme: name: Generate chart README files runs-on: ubuntu-20.04 outputs: commitHash: ${{ steps.create-commit.outputs.commit_hash }} needs: - pr-metadata steps: - name: Checkout if: | needs.pr-metadata.outputs.isFork == 'true' uses: actions/checkout@v2 with: fetch-depth: 0 - name: Get app-token uses: getsentry/action-github-app-token@v1 id: get-app-token if: | needs.pr-metadata.outputs.isFork == 'false' with: app_id: ${{ secrets.K8S_AT_HOME_APP_ID }} private_key: ${{ secrets.K8S_AT_HOME_APP_PRIVATE_KEY }} - name: Checkout with app-token if: | needs.pr-metadata.outputs.isFork == 'false' uses: actions/checkout@v2 with: fetch-depth: 0 token: ${{ steps.get-app-token.outputs.token }} - uses: yokawasa/action-setup-kube-tools@v0.8.0 if: | needs.pr-metadata.outputs.addedOrModified == 'true' with: setup-tools: | yq yq: "4.16.2" - name: Install helm-docs if: | needs.pr-metadata.outputs.addedOrModified == 'true' run: | wget -O /tmp/helm-docs.deb https://github.com/k8s-at-home/helm-docs/releases/download/v0.1.1/helm-docs_0.1.1_Linux_x86_64.deb sudo dpkg -i /tmp/helm-docs.deb - name: Annotate Charts.yaml for Renovate PR's if: | needs.pr-metadata.outputs.addedOrModified == 'true' && startsWith(needs.pr-metadata.outputs.branch, 'renovate/') run: | export DEFAULT_BRANCH=$(git remote show origin | awk '/HEAD branch/ {print $NF}') CHARTS=(${{ needs.pr-metadata.outputs.addedOrModifiedCharts }}) for i in "${CHARTS[@]}" do IFS='/' read -r -a chart_parts <<< "$i" if [ -f "charts/${chart_parts[0]}"/"${chart_parts[1]}/Chart.yaml" ]; then ./hack/renovate-releasenotes.sh "charts/${chart_parts[0]}"/"${chart_parts[1]}" fi echo "" done - name: Generate README for changed charts if: | needs.pr-metadata.outputs.addedOrModified == 'true' run: | CHARTS=(${{ needs.pr-metadata.outputs.addedOrModifiedCharts }}) for i in "${CHARTS[@]}" do printf "Rendering README for chart %s\n" "${i}" echo " ${i}" IFS='/' read -r -a chart_parts <<< "$i" if [ -f "charts/${chart_parts[0]}"/"${chart_parts[1]}/Chart.yaml" ]; then ./hack/gen-helm-docs.sh "${chart_parts[0]}" "${chart_parts[1]}" fi echo "" done - name: Create commit id: create-commit if: | needs.pr-metadata.outputs.addedOrModified == 'true' uses: stefanzweifel/git-auto-commit-action@v4 with: file_pattern: charts/**/ commit_message: Auto-update chart metadata and README commit_user_name: ${{ github.actor }} commit_user_email: ${{ github.actor }}@users.noreply.github.com changes-lint: name: Detect changes for linting runs-on: ubuntu-20.04 outputs: matrix: | { "chart": ${{ steps.list-changed.outputs.charts }} } detected: ${{ steps.list-changed.outputs.detected }} needs: - pr-metadata - generate-readme if: | needs.generate-readme.outputs.commitHash == '' steps: - name: Checkout uses: actions/checkout@v2 with: fetch-depth: 0 - name: Set up chart-testing uses: helm/chart-testing-action@v2.1.0 - name: Run chart-testing (list-changed) id: list-changed run: | EXCLUDED=$(yq eval -o=json '.excluded-charts // []' .github/ct-lint.yaml) CHARTS=$(ct list-changed --config .github/ct-lint.yaml) CHARTS_JSON=$(echo "${CHARTS}" | jq -R -s -c 'split("\n")[:-1]') OUTPUT_JSON=$(echo "{\"excluded\": ${EXCLUDED}, \"all\": ${CHARTS_JSON}}" | jq -c '.all-.excluded') echo ::set-output name=charts::${OUTPUT_JSON} if [[ $(echo ${OUTPUT_JSON} | jq -c '. | length') -gt 0 ]]; then echo "::set-output name=detected::true" fi changes-install: name: Detect changes for install runs-on: ubuntu-20.04 outputs: matrix: | { "chart": ${{ steps.list-changed.outputs.charts }} } detected: ${{ steps.list-changed.outputs.detected }} needs: - pr-metadata - generate-readme if: | needs.generate-readme.outputs.commitHash == '' steps: - name: Checkout uses: actions/checkout@v2 with: fetch-depth: 0 - name: Set up chart-testing uses: helm/chart-testing-action@v2.1.0 - name: Run chart-testing (list-changed) id: list-changed run: | EXCLUDED=$(yq eval -o=json '.excluded-charts // []' .github/ct-install.yaml) CHARTS=$(ct list-changed --config .github/ct-install.yaml) CHARTS_JSON=$(echo "${CHARTS}" | jq -R -s -c 'split("\n")[:-1]') OUTPUT_JSON=$(echo "{\"excluded\": ${EXCLUDED}, \"all\": ${CHARTS_JSON}}" | jq -c '.all-.excluded') echo ::set-output name=charts::${OUTPUT_JSON} if [[ $(echo ${OUTPUT_JSON} | jq -c '. | length') -gt 0 ]]; then echo "::set-output name=detected::true" fi lint: needs: - changes-lint if: needs.changes-lint.outputs.detected == 'true' name: Lint charts strategy: matrix: ${{ fromJson(needs.changes-lint.outputs.matrix) }} fail-fast: true max-parallel: 15 runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v2 with: fetch-depth: 0 - name: Install Helm uses: azure/setup-helm@v1 with: version: v3.6.3 - uses: actions/setup-python@v2 with: python-version: 3.7 - name: Set up chart-testing uses: helm/chart-testing-action@v2.1.0 - name: Run chart-testing (lint) id: lint run: ct lint --config .github/ct-lint.yaml --charts ${{ matrix.chart }} # Summarize matrix https://github.community/t/status-check-for-a-matrix-jobs/127354/7 lint_success: needs: - lint if: ${{ always() }} name: Lint successful runs-on: ubuntu-20.04 steps: - name: Check lint matrix status if: ${{ needs.changes-lint.outputs.detected == 'true' && needs.lint.result != 'success' }} run: exit 1 unittest: needs: - lint_success name: Run unit tests runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v2 with: fetch-depth: 0 - name: Install Dev tools run: sudo apt-get update && sudo apt-get install -y jq libjq-dev - name: Install Helm uses: azure/setup-helm@v1 with: version: v3.6.3 - name: Install Ruby uses: ruby/setup-ruby@v1 with: ruby-version: 2.7 - name: Install dependencies env: RUBYJQ_USE_SYSTEM_LIBRARIES: 1 run: | bundle install - name: Run tests run: | bundle exec m -r ./test/ install: needs: - changes-install - lint_success if: needs.changes-install.outputs.detected == 'true' name: Install charts strategy: matrix: ${{ fromJson(needs.changes-install.outputs.matrix) }} fail-fast: true max-parallel: 15 runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v2 with: fetch-depth: 0 - name: Install Helm uses: azure/setup-helm@v1 with: version: v3.6.3 - uses: actions/setup-python@v2 with: python-version: 3.7 - name: Set up chart-testing uses: helm/chart-testing-action@v2.1.0 - name: Create k3d cluster uses: nolar/setup-k3d-k3s@v1 with: version: v1.19 - name: Remove node taints run: | kubectl taint --all=true nodes node.cloudprovider.kubernetes.io/uninitialized- || true - name: Run chart-testing (install) run: ct install --config .github/ct-install.yaml --charts ${{ matrix.chart }} # Summarize matrix https://github.community/t/status-check-for-a-matrix-jobs/127354/7 install_success: needs: - changes-install - install if: ${{ always() }} name: Install successful runs-on: ubuntu-20.04 steps: - name: Check install matrix status if: ${{ needs.changes-install.outputs.detected == 'true' && needs.install.result != 'success' }} run: exit 1