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