helm-charts/.github/workflows/charts-lint.yaml

152 lines
5 KiB
YAML

name: "Charts: Lint (Reusable)"
on:
workflow_call:
inputs:
charts:
description: >
Json encoded list of Helm charts to release.
Defaults to releasing everything.
default: "[]"
required: true
type: string
helmVersion:
description: >
Helm version to use.
default: "latest"
required: false
type: string
permissions:
contents: read
jobs:
validate-required-changes:
name: Validate required changes
strategy:
matrix:
chart: ${{ fromJSON(inputs.charts) }}
fail-fast: false
if: |
${{
(inputs.charts != '[]' && inputs.charts != '') &&
github.event_name == 'pull_request'
}}
runs-on: ubuntu-24.04
steps:
- name: Checkout pull request branch
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: pull
- name: Checkout default branch
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: "${{ github.event.repository.default_branch }}"
path: default
- name: Get chart details for PR
id: chart-details-pr
uses: bjw-s-labs/helm-charts-actions/get-chart-details@0650ac557e715e21879e179ff838059211815171
with:
path: pull/charts/${{ matrix.chart }}
validateChartYaml: true
requireChangelog: true
- name: Get chart details for default branch
id: chart-details-default
uses: bjw-s-labs/helm-charts-actions/get-chart-details@0650ac557e715e21879e179ff838059211815171
with:
path: default/charts/${{ matrix.chart }}
allowChartToNotExist: true
validateChartYaml: false
requireChangelog: false
# - name: Check version update
# if: ${{ steps.chart-details-pr.outputs.version == steps.chart-details-default.outputs.version }}
# uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
# with:
# script: |
# core.setFailed("Chart version has not been updated for ${{ matrix.chart }}");
# - name: Check changelog update
# if: ${{ steps.chart-details-pr.outputs.changes == steps.chart-details-default.outputs.changes }}
# uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
# with:
# script: |
# core.setFailed("Changelog has not been updated for ${{ matrix.chart }}");
validate_success:
needs:
- validate-required-changes
if: ${{ !cancelled() }}
name: Validation successful
runs-on: ubuntu-latest
steps:
- name: Check matrix status
if: >-
${{
(inputs.chartsToLint != '' && inputs.chartsToLint != '[]') &&
contains(needs.*.result, 'failure')
}}
run: exit 1
lint-chart:
if: ${{ inputs.charts != '[]' && inputs.charts != '' }}
name: Lint chart
strategy:
matrix:
chart: ${{ fromJSON(inputs.charts) }}
fail-fast: false
needs:
- validate_success
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install Kubernetes tools
uses: yokawasa/action-setup-kube-tools@9e25a4277af127b60011c95b6ed2da7e3b3613b1 # v0.11.2
with:
setup-tools: |
helmv3
helm: "${{ inputs.helmVersion }}"
- name: Set up chart-testing
uses: helm/chart-testing-action@0d28d3144d3a25ea2cc349d6e59901c4ff469b3b # v2.7.0
- name: Dereference JSON schema
uses: bjw-s/helm-charts-actions/dereference-json-schema@main
with:
schemaFile: "charts/${{ matrix.chart }}/values.schema.json"
outputFile: "charts/${{ matrix.chart }}/values.schema.json"
allowFileNotFound: true
- name: Always assume in-repo common library
env:
COMMON_LIBRARY_LOCATION: ${{ github.workspace }}/charts/library/common
working-directory: charts/${{ matrix.chart }}
run: |
yq -i '. |= .dependencies |= map(select(.name == "common" and .repository == "https://bjw-s-labs.github.io/helm-charts").version = ">0.0.0-0")' Chart.yaml
yq -i '. |= .dependencies |= map(select(.name == "common" and .repository == "https://bjw-s-labs.github.io/helm-charts").repository = "file://${{ env.COMMON_LIBRARY_LOCATION }}")' Chart.yaml
echo "::group::Modified Chart.yaml"
cat Chart.yaml
echo "::endgroup::"
- name: Run chart-testing (lint)
run: ct lint --config .ci/ct/ct.yaml --charts "charts/${{ matrix.chart }}"
lint_success:
needs:
- lint-chart
if: ${{ !cancelled() }}
name: Lint successful
runs-on: ubuntu-latest
steps:
- name: Check matrix status
if: >-
${{
(inputs.chartsToLint != '' && inputs.chartsToLint != '[]') &&
contains(needs.*.result, 'failure')
}}
run: exit 1