2022-03-30 08:46:56 +00:00
|
|
|
name: "Charts: Lint"
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_call:
|
|
|
|
inputs:
|
|
|
|
checkoutCommit:
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
chartChangesDetected:
|
|
|
|
required: true
|
|
|
|
type: string
|
2023-05-24 18:01:18 +00:00
|
|
|
modifiedFiles:
|
|
|
|
required: true
|
|
|
|
type: string
|
2023-05-28 17:28:55 +00:00
|
|
|
modifiedCharts:
|
|
|
|
required: true
|
|
|
|
type: string
|
2022-03-30 08:46:56 +00:00
|
|
|
|
|
|
|
jobs:
|
2023-05-23 08:26:41 +00:00
|
|
|
lint-and-verify:
|
|
|
|
name: Lint Charts and Verify Dependencies
|
2023-05-05 20:36:14 +00:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2023-05-30 10:54:44 +00:00
|
|
|
- name: Checkout [master]
|
2023-09-04 16:23:21 +00:00
|
|
|
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
|
2023-05-07 11:02:51 +00:00
|
|
|
with:
|
2023-05-28 17:28:55 +00:00
|
|
|
fetch-depth: 1
|
|
|
|
ref: master
|
2023-05-28 19:36:35 +00:00
|
|
|
|
2023-05-30 10:54:44 +00:00
|
|
|
- name: Checkout [commit]
|
2023-09-04 16:23:21 +00:00
|
|
|
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
|
2023-05-28 17:28:55 +00:00
|
|
|
with:
|
|
|
|
fetch-depth: 1
|
2023-05-23 08:26:41 +00:00
|
|
|
ref: ${{ inputs.checkoutCommit }}
|
2023-05-07 11:02:51 +00:00
|
|
|
|
|
|
|
- name: Setting repo parent dir as safe safe.directory
|
|
|
|
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
2023-05-30 10:54:44 +00:00
|
|
|
|
2023-05-29 09:20:59 +00:00
|
|
|
- name: Install go-yq
|
|
|
|
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
|
2023-05-30 10:54:44 +00:00
|
|
|
|
2023-05-29 09:20:59 +00:00
|
|
|
- name: Install pre-commit, yamale and yamllint
|
|
|
|
run: |
|
|
|
|
pip3 install --no-cache-dir pre-commit yamale yamllint
|
2023-05-07 11:02:51 +00:00
|
|
|
|
2023-05-23 08:26:41 +00:00
|
|
|
- name: Prep Helm
|
2023-05-05 20:36:14 +00:00
|
|
|
run: |
|
2023-05-23 08:26:41 +00:00
|
|
|
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
|
2023-07-15 17:22:49 +00:00
|
|
|
helm repo add jetstack https://charts.jetstack.io
|
2023-05-23 08:26:41 +00:00
|
|
|
helm repo update
|
2022-03-30 08:46:56 +00:00
|
|
|
|
2023-05-23 08:26:41 +00:00
|
|
|
- name: Collect changes (branch-based)
|
2022-03-30 08:46:56 +00:00
|
|
|
id: list-changed
|
|
|
|
if: inputs.chartChangesDetected == 'true'
|
2022-06-07 17:41:19 +00:00
|
|
|
shell: bash
|
2022-03-30 08:46:56 +00:00
|
|
|
run: |
|
2023-05-28 19:36:35 +00:00
|
|
|
CHARTS="${{ inputs.modifiedCharts }}"
|
2023-05-28 17:28:55 +00:00
|
|
|
echo "Modified Charts: ${CHARTS}"
|
2023-05-28 19:36:35 +00:00
|
|
|
|
2023-05-23 08:26:41 +00:00
|
|
|
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')
|
2022-03-30 08:46:56 +00:00
|
|
|
|
2023-05-23 08:26:41 +00:00
|
|
|
echo CHANGED_CHARTS=${OUTPUT_JSON} >> "$GITHUB_OUTPUT"
|
|
|
|
if [[ $(echo ${OUTPUT_JSON} | jq --compact-output '. | length') -gt 0 ]]; then
|
|
|
|
echo "detected=true" >> "$GITHUB_OUTPUT"
|
|
|
|
fi
|
2023-05-30 10:54:44 +00:00
|
|
|
|
2023-05-24 18:36:24 +00:00
|
|
|
- name: Test and Fix Pre-Commit Issues
|
2023-05-24 18:04:47 +00:00
|
|
|
shell: bash
|
2023-05-30 10:54:44 +00:00
|
|
|
# TODO: Only run pre-commit on changed files
|
2023-06-16 21:10:56 +00:00
|
|
|
# TODO: Commit fixes
|
2023-05-24 18:04:47 +00:00
|
|
|
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
|
2023-05-29 09:20:59 +00:00
|
|
|
pre-commit run --all || pre-commit run --all
|
2023-05-24 18:01:18 +00:00
|
|
|
|
2023-05-23 08:26:41 +00:00
|
|
|
- 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
|
2022-04-05 17:30:02 +00:00
|
|
|
|
2023-05-23 08:26:41 +00:00
|
|
|
- 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 }}"
|
2022-04-05 17:30:02 +00:00
|
|
|
|
2023-05-23 08:26:41 +00:00
|
|
|
- name: Create/Update comment
|
|
|
|
if: steps.list-changed.outputs.detected == 'true'
|
2023-05-25 17:28:12 +00:00
|
|
|
continue-on-error: true
|
2023-08-06 21:21:46 +00:00
|
|
|
uses: thollander/actions-comment-pull-request@d61db783da9abefc3437960d0cce08552c7c004f # v2
|
2022-04-05 17:30:02 +00:00
|
|
|
with:
|
2023-05-23 08:26:41 +00:00
|
|
|
filePath: /tmp/lint_result.txt
|
|
|
|
comment_tag: lint_results
|
|
|
|
mode: recreate
|
2023-05-25 17:46:40 +00:00
|
|
|
GITHUB_TOKEN: ${{ github.token }}
|
2022-04-05 17:30:02 +00:00
|
|
|
|
2023-05-23 08:26:41 +00:00
|
|
|
- name: Lint Result
|
|
|
|
if: steps.list-changed.outputs.detected == 'true'
|
|
|
|
shell: bash
|
2023-01-09 16:28:10 +00:00
|
|
|
run: |
|
2023-05-23 08:26:41 +00:00
|
|
|
if [ "${{ steps.lint.outcome }}" != "success" ]; then
|
2023-05-30 18:31:22 +00:00
|
|
|
echo "❌ Linting failed ❌"
|
|
|
|
echo '###############################################################'
|
|
|
|
echo '## 👀 Expand [Run Chart Linting] step to view the results 👀 ##'
|
|
|
|
echo '###############################################################'
|
2023-01-09 16:28:10 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2022-07-06 11:25:34 +00:00
|
|
|
|
2022-07-06 18:09:28 +00:00
|
|
|
- uses: vishnudxb/cancel-workflow@c3c77eb4383ba7d023e6614a07d94fe990501ac6 # tag=v1.2
|
2022-07-06 11:25:34 +00:00
|
|
|
if: failure()
|
|
|
|
with:
|
2022-08-08 21:57:58 +00:00
|
|
|
repo: truecharts/chart
|
2022-07-06 11:25:34 +00:00
|
|
|
workflow_id: ${{ github.run_id }}
|
|
|
|
access_token: ${{ github.token }}
|