Skip to content

Update acp.yaml

Update acp.yaml #420

Workflow file for this run

name: Test Charts
on:
push:
branches:
- main
paths:
- 'charts/**'
pull_request:
paths:
- 'charts/**'
workflow_dispatch:
env:
UNITTEST_VERSION: v0.3.4
jobs:
run_unit_tests_on_modified_charts:
runs-on: ubuntu-latest
name: Run tests on modified charts with unit tests
steps:
- uses: actions/checkout@v3
- id: list_modified_charts_with_unit_tests
name: List modified charts with unit tests
env:
GH_TOKEN: ${{ github.token }}
run: |
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
# Retrieve the list of modified chart names in the pull request
modifiedChartPaths=$(gh pr view ${{ github.event.pull_request.number }} --json files -q '.files[].path' | xargs dirname | grep "^charts/" | cut -d "/" -f1-2 | sort --unique)
else
# Retrieve all charts
modifiedChartPaths=$(find . -maxdepth 2 -type d | grep "^charts/" | cut -d "/" -f2-3 | sort --unique)
fi
# Keep only modified charts with unit tests
modifiedChartsWithUnitTests=""
while IFS= read -r chartPath; do
if [ -d "${chartPath}/tests" ]; then
modifiedChartsWithUnitTests+=",$(echo $chartPath | cut -d '/' -f 2)"
fi
done <<< "$modifiedChartPaths"
# Remove first comma
modifiedChartsWithUnitTests=${modifiedChartsWithUnitTests#,}
# Return early if there is no modified chart with unit tests
if [ -z "$modifiedChartsWithUnitTests" ]; then
echo "= no modified chart with unit tests found."
else
echo "= modified chart(s) with unit tests: ${modifiedChartsWithUnitTests}"
fi
# Store the result
echo "modified_charts_with_unit_tests=${modifiedChartsWithUnitTests}" >> "$GITHUB_OUTPUT"
- id: tools_versions
name: Get Tools Versions
if: steps.list_modified_charts_with_unit_tests.outputs.modified_charts_with_unit_tests != ''
run: |
current_helm_version="$(curl --silent --location https://raw.githubusercontent.com/jenkins-infra/docker-helmfile/main/Dockerfile | grep 'ARG' | grep 'HELM_VERSION=' | sort -u | cut -d'=' -f2)"
echo "CURRENT_HELM_VERSION=${current_helm_version}" >> $GITHUB_OUTPUT
- id: setup_helm
name: Set up Helm
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # v3
with:
version: "${{ steps.tools-versions.outputs.CURRENT_HELM_VERSION }}"
# if: steps.list_modified_charts_with_unit_tests.outputs.modified_charts_with_unit_tests != ''
- id: install_helm_unittests
name: install helm unittests
if: steps.list_modified_charts_with_unit_tests.outputs.modified_charts_with_unit_tests != ''
run: |
helm env
# Repeat 2 times to fight against network errors in GHA runners
# Always return true
helm plugin install https://github.com/helm-unittest/helm-unittest --version ${UNITTEST_VERSION} \
|| helm plugin install https://github.com/helm-unittest/helm-unittest --version ${UNITTEST_VERSION} \
|| true
# Fail if not installed
helm plugin list | grep unittest
- id: run_helm_unittests
name: run unit tests
if: steps.list_modified_charts_with_unit_tests.outputs.modified_charts_with_unit_tests != ''
working-directory: ./charts/
run: |
# Set IFS to a comma to split the string into an array
IFS=',' read -ra chartNames <<< "${{ steps.list_modified_charts_with_unit_tests.outputs.modified_charts_with_unit_tests }}"
for chartName in "${chartNames[@]}"; do
helm unittest "$chartName"
done