k8s-monitoring 2.0 alpha #4
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Test Chart | |
# yamllint disable-line rule:truthy | |
on: | |
push: | |
branches: ["main"] | |
paths: | |
- 'charts/**' | |
- '!charts/k8s-monitoring-v1/**' | |
pull_request: | |
paths: | |
- 'charts/**' | |
- '!charts/k8s-monitoring-v1/**' | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
jobs: | |
detect-changed-charts: | |
name: Detect Changed Charts | |
runs-on: ubuntu-latest | |
outputs: | |
changed_charts: ${{ steps.changed_charts.outputs.changed_charts }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Detect Changed Charts | |
id: changed_charts | |
run: | | |
if [ "${{ github.event_name }}" == "pull_request" ]; then | |
# In pull request, compare against the base branch (upstream) | |
base_branch="${{ github.event.pull_request.base.ref }}" | |
echo "Comparing against base branch: $base_branch" | |
git fetch origin $base_branch | |
base_commit="origin/$base_branch" | |
elif [ "${{ github.event_name }}" == "push" ]; then | |
# In push to main, compare the last commit with HEAD^ | |
base_commit="HEAD^" | |
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
# In manual trigger, run for all charts | |
echo "Manual dispatch detected, running tests for all charts" | |
# shellcheck disable=SC2010 | |
echo "changed_charts=$(ls charts | grep -v "k8s-monitoring-v1" | sort -u)" >> "${GITHUB_OUTPUT}" | |
exit 0 | |
fi | |
# Check if base commit exists, fallback to empty tree if none | |
if ! git rev-parse --verify "$base_commit" >/dev/null 2>&1; then | |
base_commit=$(git hash-object -t tree /dev/null) | |
fi | |
# Detect modified files | |
modified_charts=$(git diff --name-only "$base_commit" HEAD -- 'charts/*' | grep "^charts/" | cut -d "/" -f2 | sort -u) | |
# Detect newly added files (untracked files) | |
added_charts=$(git ls-files --others --exclude-standard -- 'charts/*' | grep "^charts/" | cut -d "/" -f2 | sort -u) | |
# Combine both added and modified charts | |
changed_charts=$(echo -e "$modified_charts\n$added_charts" | grep -v "k8s-monitoring" | sort -u) | |
if [ -z "$changed_charts" ]; then | |
echo "No changes detected in charts" | |
changed_charts="none" | |
fi | |
echo "Changed charts: $changed_charts" | |
echo "changed_charts=$(echo "$changed_charts" | jq --raw-input --slurp --compact-output 'split("\n") | map(select(. != ""))')" >> "${GITHUB_OUTPUT}" | |
run-tests: | |
name: Testing | |
needs: detect-changed-charts | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
dir: ${{ fromJson(needs.detect-changed-charts.outputs.changed_charts) }} | |
fail-fast: false | |
if: ${{ needs.detect-changed-charts.outputs.changed_charts != 'none' }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Run tests | |
run: | | |
echo "Testing ${{ matrix.dir }}" | |
cd charts/${{ matrix.dir }} | |
make test | |
check-generated-files: | |
name: Check Generated Files | |
needs: detect-changed-charts | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
dir: ${{ fromJson(needs.detect-changed-charts.outputs.changed_charts) }} | |
fail-fast: false | |
if: ${{ needs.detect-changed-charts.outputs.changed_charts != 'none' }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Regenerate files | |
run: | | |
echo "Running make all in charts/${{ matrix.dir }}" | |
cd charts/${{ matrix.dir }} | |
make clean build | |
- name: Check for changes in generated files | |
run: | | |
cd charts/${{ matrix.dir }} | |
if ! git diff --exit-code .; then | |
echo "Generated files in charts/${{ matrix.dir }} are not up to date. Please run 'make all' and commit the changes." | |
exit 1 | |
else | |
echo "Generated files in charts/${{ matrix.dir }} are up to date." | |
fi |