TrueChartsClone/.github/workflows/charts-test.yaml

187 lines
5.3 KiB
YAML
Raw Normal View History

name: "Charts: Test"
on:
workflow_call:
inputs:
checkoutCommit:
required: true
type: string
chartChangesDetected:
required: true
type: string
jobs:
unit-test:
name: Run unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout
2022-03-30 15:01:34 -04:00
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ inputs.checkoutCommit }}
- name: Install Kubernetes tools
2022-03-30 15:01:34 -04:00
uses: yokawasa/action-setup-kube-tools@v0.8.0
with:
setup-tools: |
helmv3
helm: "3.8.0"
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
- name: Install dependencies
env:
RUBYJQ_USE_SYSTEM_LIBRARIES: 1
run: |
sudo apt-get update
sudo apt-get install libjq-dev
bundle install
- name: Run tests
run: |
bundle exec m -r ./test/
generate-install-matrix:
name: Generate matrix for install
runs-on: ubuntu-latest
outputs:
2022-03-30 15:01:34 -04:00
matrix1: |
{
2022-03-30 15:01:34 -04:00
"chart": ${{ steps.list-changed.outputs.charts1 }}
}
matrix2: |
{
"chart": ${{ steps.list-changed.outputs.charts2 }}
}
detected: ${{ steps.list-changed.outputs.detected }}
steps:
- name: Checkout
2022-03-30 15:01:34 -04:00
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ inputs.checkoutCommit }}
- name: Set up chart-testing
2022-03-30 15:01:34 -04:00
uses: helm/chart-testing-action@v2.2.1
- name: Run chart-testing (list-changed)
id: list-changed
if: inputs.chartChangesDetected == 'true'
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')
2022-03-30 15:01:34 -04:00
OUTPUT_JSON1=$(echo $CHARTS_JSON | jq -r -c '.[:254]')
OUTPUT_JSON2=$(echo $CHARTS_JSON | jq -r -c '.[254:500]')
echo ::set-output name=charts1::${OUTPUT_JSON1}
echo ::set-output name=charts2::${OUTPUT_JSON2}
if [[ $(echo ${OUTPUT_JSON} | jq -c '. | length') -gt 0 ]]; then
echo "::set-output name=detected::true"
fi
2022-03-30 15:01:34 -04:00
install-charts1:
needs:
- generate-install-matrix
if: needs.generate-install-matrix.outputs.detected == 'true'
name: Install charts Part 1
strategy:
matrix: ${{ fromJson(needs.generate-install-matrix.outputs.matrix1) }}
2022-03-30 15:22:26 -04:00
fail-fast: false
2022-03-30 15:17:30 -04:00
max-parallel: 10
2022-03-30 15:01:34 -04:00
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
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.8.0"
- uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Set up chart-testing
uses: helm/chart-testing-action@v2.2.1
- name: Create k3d cluster
uses: nolar/setup-k3d-k3s@v1
with:
version: v1.20
- 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 }} --upgrade
install-charts2:
needs:
- generate-install-matrix
if: needs.generate-install-matrix.outputs.detected == 'true'
2022-03-30 15:01:34 -04:00
name: Install charts Part 2
strategy:
2022-03-30 15:01:34 -04:00
matrix: ${{ fromJson(needs.generate-install-matrix.outputs.matrix1) }}
2022-03-30 15:22:26 -04:00
fail-fast: false
2022-03-30 15:17:30 -04:00
max-parallel: 5
runs-on: ubuntu-latest
steps:
- name: Checkout
2022-03-30 15:01:34 -04:00
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ inputs.checkoutCommit }}
- name: Install Kubernetes tools
2022-03-30 15:01:34 -04:00
uses: yokawasa/action-setup-kube-tools@v0.8.0
with:
setup-tools: |
helmv3
2022-03-30 05:30:23 -04:00
helm: "3.8.0"
2022-03-30 15:01:34 -04:00
- uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Set up chart-testing
2022-03-30 15:01:34 -04:00
uses: helm/chart-testing-action@v2.2.1
- name: Create k3d cluster
uses: nolar/setup-k3d-k3s@v1
with:
2022-03-30 06:43:07 -04:00
version: v1.20
- name: Remove node taints
run: |
kubectl taint --all=true nodes node.cloudprovider.kubernetes.io/uninitialized- || true
- name: Run chart-testing (install)
2022-03-30 06:51:25 -04:00
run: ct install --config .github/ct-install.yaml --charts ${{ matrix.chart }} --upgrade
# Summarize matrix https://github.community/t/status-check-for-a-matrix-jobs/127354/7
install_success:
needs:
- generate-install-matrix
2022-03-30 15:01:34 -04:00
- install-charts1
- install-charts2
if: |
always()
name: Install successful
runs-on: ubuntu-latest
steps:
- name: Check install matrix status
2022-03-30 15:01:34 -04:00
if: ${{ (needs.generate-install-matrix.outputs.detected == 'true') && (needs.install-charts1.result != 'success') && (needs.install-charts2.result != 'success') }}
run: exit 1