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

97 lines
3.5 KiB
YAML

name: "Charts: Lint"
on:
workflow_call:
inputs:
checkoutCommit:
required: true
type: string
chartChangesDetected:
required: true
type: string
jobs:
lint-and-verify:
name: Lint Charts and Verify Dependencies
runs-on: ubuntu-latest
container:
image: tccr.io/truecharts/devcontainer:v3.1.38@sha256:2fd9355bc6791461430db87a04f5fe7b49c46bc5957bc348f1efbff4c6c7913d
steps:
- name: Checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3
with:
fetch-depth: 0
ref: ${{ inputs.checkoutCommit }}
- name: Setting repo parent dir as safe safe.directory
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Prep Helm
run: |
helm repo add truecharts https://charts.truecharts.org
helm repo add truecharts-deps https://deps.truecharts.org
helm repo add truecharts-library https://library-charts.truecharts.org
helm repo add truecharts-deps https://deps.truecharts.org
helm repo update
- name: Collect changes (branch-based)
id: list-changed
if: inputs.chartChangesDetected == 'true'
shell: bash
run: |
CHARTS=$(ct list-changed --config .github/ct-lint.yaml)
EXCLUDED_JSON=$(go-yq eval -o=json '.excluded-charts // []' .github/ct-lint.yaml)
CHARTS_JSON=$(echo "${CHARTS}" | jq --raw-input '.' | jq --compact-output --slurp '.')
OUTPUT_JSON=$(echo "{\"excluded\": ${EXCLUDED_JSON}, \"all\": ${CHARTS_JSON}}" | jq --compact-output '.all-.excluded')
echo CHANGED_CHARTS=${OUTPUT_JSON} >> "$GITHUB_OUTPUT"
if [[ $(echo ${OUTPUT_JSON} | jq --compact-output '. | length') -gt 0 ]]; then
echo "detected=true" >> "$GITHUB_OUTPUT"
fi
- name: Fetch and Verify dependencies
shell: bash
if: steps.list-changed.outputs.detected == 'true'
env:
charts_path: "./"
run: |
CHANGED=$(echo '${{ steps.list-changed.outputs.CHANGED_CHARTS }}' | jq --raw-output '.[]')
for changed in ${CHANGED}; do
.github/scripts/fetch_helm_deps.sh "${changed}"
done
- name: Run Chart Linting
continue-on-error: true
id: lint
if: steps.list-changed.outputs.detected == 'true'
env:
result_file: /tmp/lint_result.txt
run: |
CHANGED=$(echo '${{ steps.list-changed.outputs.CHANGED_CHARTS }}' | jq --raw-output '.[]')
# If the github.base_ref is empty (eg it runs outside of a PR) it fails back to origin/master
.github/scripts/tc-lint.sh '${{ steps.list-changed.outputs.CHANGED_CHARTS }}' "origin/${{ github.base_ref }}"
- name: Create/Update comment
if: steps.list-changed.outputs.detected == 'true'
uses: thollander/actions-comment-pull-request@632cf9ce90574d125be56b5f3405cda41a84e2fd # v2
with:
filePath: /tmp/lint_result.txt
comment_tag: lint_results
mode: recreate
- name: Lint Result
if: steps.list-changed.outputs.detected == 'true'
shell: bash
run: |
if [ "${{ steps.lint.outcome }}" != "success" ]; then
echo "Linting failed"
exit 1
fi
- uses: vishnudxb/cancel-workflow@c3c77eb4383ba7d023e6614a07d94fe990501ac6 # tag=v1.2
if: failure()
with:
repo: truecharts/chart
workflow_id: ${{ github.run_id }}
access_token: ${{ github.token }}