ci: Restructure PR validation

Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs <me@bjw-s.dev>
This commit is contained in:
Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs 2022-02-03 19:39:40 +01:00
parent 085bd01f1a
commit a101402e74
No known key found for this signature in database
GPG Key ID: BC5E2BD907F9A8EC
5 changed files with 160 additions and 371 deletions

View File

@ -6,13 +6,10 @@ on:
checkoutCommit:
required: true
type: string
modifiedCharts:
required: true
type: string
jobs:
lint:
name: Lint successful
name: Lint charts
runs-on: ubuntu-latest
steps:
- name: Checkout

130
.github/workflows/charts-test.yaml vendored Normal file
View File

@ -0,0 +1,130 @@
name: "Charts: Test"
on:
workflow_call:
inputs:
checkoutCommit:
required: true
type: string
jobs:
unit-test:
name: Run unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ inputs.checkoutCommit }}
- name: Install Kubernetes tools
uses: yokawasa/action-setup-kube-tools@v0.8.0
with:
setup-tools: |
helmv3
helm: 3.6.3
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
- name: Install dependencies
env:
RUBYJQ_USE_SYSTEM_LIBRARIES: 1
run: |
bundle install
- name: Run tests
run: |
bundle exec m -r ./test/
generate-install-matrix:
name: Generate matrix for install
runs-on: ubuntu-latest
outputs:
matrix: |
{
"chart": ${{ steps.list-changed.outputs.charts }}
}
detected: ${{ steps.list-changed.outputs.detected }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ inputs.checkoutCommit }}
- name: Set up chart-testing
uses: helm/chart-testing-action@v2.1.0
- name: Run chart-testing (list-changed)
id: list-changed
run: |
EXCLUDED=$(yq eval -o=json '.excluded-charts // []' .github/ct-install.yaml)
CHARTS=$(ct list-changed --config .github/ct-install.yaml)
CHARTS_JSON=$(echo "${CHARTS}" | jq -R -s -c 'split("\n")[:-1]')
OUTPUT_JSON=$(echo "{\"excluded\": ${EXCLUDED}, \"all\": ${CHARTS_JSON}}" | jq -c '.all-.excluded')
echo ::set-output name=charts::${OUTPUT_JSON}
if [[ $(echo ${OUTPUT_JSON} | jq -c '. | length') -gt 0 ]]; then
echo "::set-output name=detected::true"
fi
install-charts:
needs:
- generate-install-matrix
if: needs.generate-install-matrix.outputs.detected == 'true'
name: Install charts
strategy:
matrix: ${{ fromJson(needs.generate-install-matrix.outputs.matrix) }}
fail-fast: true
max-parallel: 15
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ inputs.checkoutCommit }}
- name: Install Kubernetes tools
uses: yokawasa/action-setup-kube-tools@v0.8.0
with:
setup-tools: |
helmv3
helm: 3.6.3
- uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Set up chart-testing
uses: helm/chart-testing-action@v2.1.0
- name: Create k3d cluster
uses: nolar/setup-k3d-k3s@v1
with:
version: v1.19
- name: Remove node taints
run: |
kubectl taint --all=true nodes node.cloudprovider.kubernetes.io/uninitialized- || true
- name: Run chart-testing (install)
run: ct install --config .github/ct-install.yaml --charts ${{ matrix.chart }}
# Summarize matrix https://github.community/t/status-check-for-a-matrix-jobs/127354/7
install_success:
needs:
- generate-install-matrix
- install-charts
if: |
always() &&
needs.install.result != 'skipped'
name: Install successful
runs-on: ubuntu-latest
steps:
- name: Check install matrix status
if: ${{ needs.changes-generate-install-matrix.outputs.detected == 'true' && needs.install-charts.result != 'success' }}
run: exit 1

View File

@ -1,334 +0,0 @@
name: "Charts: Validate"
on:
workflow_dispatch:
pull_request:
paths:
- "charts/**"
concurrency:
group: ${{ github.head_ref }}-validate
# cancel-in-progress: true
jobs:
pr-metadata:
name: Collect PR metadata
runs-on: ubuntu-20.04
outputs:
branch: ${{ steps.branch-name.outputs.current_branch }}
isFork: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
addedOrModified: ${{ steps.filter.outputs.addedOrModified }}
addedOrModifiedFiles: ${{ steps.filter.outputs.addedOrModified_files }}
addedOrModifiedCharts: ${{ steps.filter-charts.outputs.addedOrModified }}
steps:
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v5.1
- name: Checkout
uses: actions/checkout@v2
- name: Collect changed files
uses: dorny/paths-filter@v2
id: filter
with:
list-files: shell
filters: |
addedOrModified:
- added|modified: 'charts/**'
- name: Collect changed charts
if: |
steps.filter.outputs.addedOrModified == 'true'
id: filter-charts
run: |
CHARTS=()
PATHS=(${{ steps.filter.outputs.addedOrModified_files }})
# Get only the chart paths
for CHARTPATH in "${PATHS[@]}"
do
IFS='/' read -r -a path_parts <<< "${CHARTPATH}"
CHARTS+=("${path_parts[1]}/${path_parts[2]}")
done
# Remove duplicates
CHARTS=( `printf "%s\n" "${CHARTS[@]}" | sort -u` )
# Set output to changed charts
printf "::set-output name=addedOrModified::%s\n" "${CHARTS[*]}"
generate-readme:
name: Generate chart README files
runs-on: ubuntu-20.04
outputs:
commitHash: ${{ steps.create-commit.outputs.commit_hash }}
needs:
- pr-metadata
if: |
needs.pr-metadata.outputs.isFork == 'false'
steps:
- name: Generate Token
uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.K8S_AT_HOME_APP_ID }}
private_key: ${{ secrets.K8S_AT_HOME_APP_PRIVATE_KEY }}
- name: Checkout with app-token
uses: actions/checkout@v2
with:
fetch-depth: 0
token: ${{ steps.generate-token.outputs.token }}
- uses: yokawasa/action-setup-kube-tools@v0.8.0
if: |
needs.pr-metadata.outputs.addedOrModified == 'true'
with:
setup-tools: |
yq
yq: "4.16.2"
- name: Install helm-docs
if: |
needs.pr-metadata.outputs.addedOrModified == 'true'
run: |
wget -O /tmp/helm-docs.deb https://github.com/k8s-at-home/helm-docs/releases/download/v0.1.1/helm-docs_0.1.1_Linux_x86_64.deb
sudo dpkg -i /tmp/helm-docs.deb
- name: Annotate Charts.yaml for Renovate PR's
if: |
needs.pr-metadata.outputs.addedOrModified == 'true' &&
startsWith(needs.pr-metadata.outputs.branch, 'renovate/')
run: |
export DEFAULT_BRANCH=$(git remote show origin | awk '/HEAD branch/ {print $NF}')
CHARTS=(${{ needs.pr-metadata.outputs.addedOrModifiedCharts }})
for i in "${CHARTS[@]}"
do
IFS='/' read -r -a chart_parts <<< "$i"
if [ -f "charts/${chart_parts[0]}"/"${chart_parts[1]}/Chart.yaml" ]; then
./hack/renovate-releasenotes.sh "charts/${chart_parts[0]}"/"${chart_parts[1]}"
fi
echo ""
done
- name: Generate README for changed charts
if: |
needs.pr-metadata.outputs.addedOrModified == 'true'
run: |
CHARTS=(${{ needs.pr-metadata.outputs.addedOrModifiedCharts }})
for i in "${CHARTS[@]}"
do
printf "Rendering README for chart %s\n" "${i}"
echo " ${i}"
IFS='/' read -r -a chart_parts <<< "$i"
if [ -f "charts/${chart_parts[0]}"/"${chart_parts[1]}/Chart.yaml" ]; then
./hack/gen-helm-docs.sh "${chart_parts[0]}" "${chart_parts[1]}"
fi
echo ""
done
- name: Create commit
id: create-commit
if: |
needs.pr-metadata.outputs.addedOrModified == 'true'
uses: stefanzweifel/git-auto-commit-action@v4
with:
file_pattern: charts/**/
commit_message: Auto-update chart metadata and README
commit_user_name: ${{ github.actor }}
commit_user_email: ${{ github.actor }}@users.noreply.github.com
changes-lint:
name: Detect changes for linting
runs-on: ubuntu-20.04
outputs:
matrix: |
{
"chart": ${{ steps.list-changed.outputs.charts }}
}
detected: ${{ steps.list-changed.outputs.detected }}
needs:
- pr-metadata
- generate-readme
if: |
always() &&
needs.generate-readme.outputs.commitHash == ''
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up chart-testing
uses: helm/chart-testing-action@v2.1.0
- name: Run chart-testing (list-changed)
id: list-changed
run: |
EXCLUDED=$(yq eval -o=json '.excluded-charts // []' .github/ct-lint.yaml)
CHARTS=$(ct list-changed --config .github/ct-lint.yaml)
CHARTS_JSON=$(echo "${CHARTS}" | jq -R -s -c 'split("\n")[:-1]')
OUTPUT_JSON=$(echo "{\"excluded\": ${EXCLUDED}, \"all\": ${CHARTS_JSON}}" | jq -c '.all-.excluded')
echo ::set-output name=charts::${OUTPUT_JSON}
if [[ $(echo ${OUTPUT_JSON} | jq -c '. | length') -gt 0 ]]; then
echo "::set-output name=detected::true"
fi
changes-install:
name: Detect changes for install
runs-on: ubuntu-20.04
outputs:
matrix: |
{
"chart": ${{ steps.list-changed.outputs.charts }}
}
detected: ${{ steps.list-changed.outputs.detected }}
needs:
- pr-metadata
- generate-readme
if: |
always() &&
needs.generate-readme.outputs.commitHash == ''
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up chart-testing
uses: helm/chart-testing-action@v2.1.0
- name: Run chart-testing (list-changed)
id: list-changed
run: |
EXCLUDED=$(yq eval -o=json '.excluded-charts // []' .github/ct-install.yaml)
CHARTS=$(ct list-changed --config .github/ct-install.yaml)
CHARTS_JSON=$(echo "${CHARTS}" | jq -R -s -c 'split("\n")[:-1]')
OUTPUT_JSON=$(echo "{\"excluded\": ${EXCLUDED}, \"all\": ${CHARTS_JSON}}" | jq -c '.all-.excluded')
echo ::set-output name=charts::${OUTPUT_JSON}
if [[ $(echo ${OUTPUT_JSON} | jq -c '. | length') -gt 0 ]]; then
echo "::set-output name=detected::true"
fi
lint:
needs:
- changes-lint
if: always() &&
needs.changes-lint.outputs.detected == 'true'
name: Lint successful
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.6.3
- uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Set up chart-testing
uses: helm/chart-testing-action@v2.1.0
- name: Run chart-testing (lint)
id: lint
run: ct lint --config .github/ct-lint.yaml
unittest:
needs:
- lint
if: |
always() &&
needs.lint.result == 'success'
name: Run unit tests
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install Dev tools
run: sudo apt-get update && sudo apt-get install -y jq libjq-dev
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.6.3
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
- name: Install dependencies
env:
RUBYJQ_USE_SYSTEM_LIBRARIES: 1
run: |
bundle install
- name: Run tests
run: |
bundle exec m -r ./test/
install:
needs:
- changes-install
- lint
if: always() &&
needs.lint.result == 'success' &&
needs.changes-install.outputs.detected == 'true'
name: Install charts
strategy:
matrix: ${{ fromJson(needs.changes-install.outputs.matrix) }}
fail-fast: true
max-parallel: 15
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.6.3
- uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Set up chart-testing
uses: helm/chart-testing-action@v2.1.0
- name: Create k3d cluster
uses: nolar/setup-k3d-k3s@v1
with:
version: v1.19
- name: Remove node taints
run: |
kubectl taint --all=true nodes node.cloudprovider.kubernetes.io/uninitialized- || true
- name: Run chart-testing (install)
run: ct install --config .github/ct-install.yaml --charts ${{ matrix.chart }}
# Summarize matrix https://github.community/t/status-check-for-a-matrix-jobs/127354/7
install_success:
needs:
- changes-install
- install
if: |
always() &&
needs.install.result != 'skipped'
name: Install successful
runs-on: ubuntu-20.04
steps:
- name: Check install matrix status
if: ${{ needs.changes-install.outputs.detected == 'true' && needs.install.result != 'success' }}
run: exit 1

View File

@ -13,10 +13,18 @@ jobs:
pr-metadata:
uses: k8s-at-home/charts/.github/workflows/pr-get-metadata.yaml@master
pre-commit-check:
uses: k8s-at-home/charts/.github/workflows/pre-commit-check.yaml@master
needs:
- pr-metadata
with:
modifiedFiles: ${{ needs.pr-metadata.outputs.addedOrModifiedFiles }}
charts-readme:
uses: k8s-at-home/charts/.github/workflows/charts-update-readme.yaml@master
needs:
- pr-metadata
- pre-commit-check
with:
isRenovatePR: ${{ needs.pr-metadata.outputs.isRenovatePR }}
modifiedCharts: ${{ needs.pr-metadata.outputs.addedOrModifiedCharts }}
@ -28,4 +36,12 @@ jobs:
- charts-readme
with:
checkoutCommit: ${{ needs.charts-readme.outputs.commitHash }}
modifiedCharts: ${{ needs.pr-metadata.outputs.addedOrModifiedCharts }}
charts-test:
uses: k8s-at-home/charts/.github/workflows/charts-test.yaml@master
needs:
- pr-metadata
- charts-readme
- charts-lint
with:
checkoutCommit: ${{ needs.charts-readme.outputs.commitHash }}

View File

@ -1,41 +1,21 @@
name: "Pre-commit consistency check"
on:
workflow_dispatch:
pull_request:
concurrency:
group: ${{ github.head_ref }}-precommit
cancel-in-progress: true
workflow_call:
inputs:
modifiedFiles:
required: true
type: string
jobs:
pre-commit-check:
name: Run pre-commit checks
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Checkout
uses: actions/checkout@v2
- uses: dorny/paths-filter@v2
id: filter
with:
list-files: shell
filters: |
addedOrModified:
- added|modified: '**'
# run only if changed files were detected
- name: Run against changes
uses: pre-commit/action@v2.0.3
if: steps.filter.outputs.addedOrModified == 'true'
with:
extra_args: --files ${{ steps.filter.outputs.addedOrModified_files }}
# run if no changed files were detected (e.g. workflow_dispatch on master branch)
- name: Run against all files
uses: pre-commit/action@v2.0.3
if: steps.filter.outputs.addedOrModified != 'true'
with:
extra_args: --all-files
- name: Run against changes
uses: pre-commit/action@v2.0.3
with:
extra_args: --files ${{ inputs.modifiedFiles }}