forked from truecharts/public
-
Notifications
You must be signed in to change notification settings - Fork 0
141 lines (125 loc) · 5.38 KB
/
charts-lint.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: "Charts: Lint"
on:
workflow_call:
inputs:
checkoutCommit:
required: true
type: string
chartChangesDetected:
required: true
type: string
modifiedFiles:
required: true
type: string
modifiedCharts:
required: true
type: string
jobs:
lint-and-verify:
name: Lint Charts and Verify Dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout [master]
if: inputs.chartChangesDetected == 'true'
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
with:
fetch-depth: 1
ref: master
- name: Checkout [commit]
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
with:
fetch-depth: 1
ref: ${{ inputs.checkoutCommit }}
- name: Setting repo parent dir as safe safe.directory
if: inputs.chartChangesDetected == 'true'
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Install go-yq
if: inputs.chartChangesDetected == 'true'
run: |
mkdir -p $HOME/.local/bin
wget https://github.com/mikefarah/yq/releases/download/v4.26.1/yq_linux_amd64 -O $HOME/.local/bin/go-yq && \
chmod +x $HOME/.local/bin/go-yq
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install pre-commit, yamale and yamllint
if: inputs.chartChangesDetected == 'true'
run: |
pip3 install --no-cache-dir pre-commit yamale yamllint
- name: Install Helm
if: inputs.chartChangesDetected == 'true'
uses: azure/setup-helm@fe7b79cd5ee1e45176fcad797de68ecaf3ca4814 # v4
with:
version: v3.14.2
- name: Prep Helm
if: inputs.chartChangesDetected == 'true'
run: |
helm repo add jetstack https://charts.jetstack.io
helm repo add vmwaretanzu https://vmware-tanzu.github.io/helm-charts
helm repo add cnpg https://cloudnative-pg.github.io/charts
helm repo add metallb https://metallb.github.io/metallb
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add openebs https://openebs.github.io/charts
helm repo add csi-driver-smb https://raw.githubusercontent.com/kubernetes-csi/csi-driver-smb/master/charts
helm repo add csi-driver-nfs https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/charts
helm repo update
- name: Collect changes (branch-based)
id: list-changed
if: inputs.chartChangesDetected == 'true'
shell: bash
run: |
CHARTS="${{ inputs.modifiedCharts }}"
echo "Modified Charts: ${CHARTS}"
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: Test and Fix Pre-Commit Issues
shell: bash
# TODO: Only run pre-commit on changed files
# TODO: Commit fixes
if: inputs.chartChangesDetected == 'true'
run: |
echo "Running pre-commit test-and-cleanup..."
# Fix sh files to always be executable
find . -name '*.sh' | xargs chmod +x
pre-commit run --all || pre-commit run --all
- 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 '.[]')
./charttool deps ${CHANGED}
- 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'
continue-on-error: true
uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3
with:
filePath: /tmp/lint_result.txt
comment_tag: lint_results
mode: recreate
GITHUB_TOKEN: ${{ github.token }}
- name: Lint Result
if: steps.list-changed.outputs.detected == 'true'
shell: bash
run: |
if [ "${{ steps.lint.outcome }}" != "success" ]; then
echo "❌ Linting failed ❌"
echo '###############################################################'
echo '## 👀 Expand [Run Chart Linting] step to view the results 👀 ##'
echo '###############################################################'
exit 1
fi