2021-08-17 11:21:13 +00:00
name : "Apps: Tests"
2021-05-09 16:11:00 +00:00
on :
pull_request :
branches :
- '**'
tags-ignore :
- '**'
paths :
2021-05-09 16:25:25 +00:00
- 'charts/**'
2021-07-01 09:17:31 +00:00
- '.github/workflows/apps.test.yaml'
2021-05-09 16:11:00 +00:00
- '.github/ct-install.yaml'
- '.github/ct-lint.yaml'
jobs :
2021-08-17 10:58:53 +00:00
prephelm :
2021-08-17 11:21:13 +00:00
name : Prepare Helm
2021-08-17 10:58:53 +00:00
runs-on : ubuntu-20.04
steps :
- name : Install Helm
uses : azure/setup-helm@v1
with :
version : v3.5.3
- name : Cache helm repo cache
uses : actions/cache@v2
with :
2021-08-17 11:55:54 +00:00
key : helmrepocache-${{ github.sha }}
2021-08-17 10:58:53 +00:00
path : |
~/.cache/helm/repository
~/.config/helm/repositories.yaml
- name : update helm repo cache
run : |
helm repo add truecharts https://truecharts.org
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
2021-05-09 16:11:00 +00:00
changes :
name : Get changed Apps
runs-on : ubuntu-20.04
outputs :
matrix : "{\"app\": ${{ steps.reduce.outputs.apps }} }"
empty_matrix : ${{ steps.reduce.outputs.empty_matrix }}
steps :
- name : Checkout
uses : actions/checkout@v2
- uses : dorny/paths-filter@v2
id : filter
with :
list-files : json
filters : |
changed :
2021-05-09 16:27:07 +00:00
- 'charts/stable/**'
- 'charts/incubator/**'
- 'charts/library/**'
2021-05-09 16:11:00 +00:00
- run : echo '${{ toJson(steps.filter.outputs) }}' > changes.json
- id : reduce
run : |
2021-05-09 16:48:14 +00:00
APPS=$(jq --raw-output '.changed_files | fromjson | .[] |= sub("(?<filepath>(?<first_directory>(?<root1>[\/]?)[^\/]+\/)(?<second_directory>(?<root2>[\/]?)[^\/]+\/)(?<third_directory>(?<root3>[\/]?)[^\/]+)(?<extra_paths>.+))"; "\(.third_directory)") | unique' changes.json)
2021-05-09 16:11:00 +00:00
echo ::set-output name=apps::${APPS}
2021-05-09 16:52:26 +00:00
if [ -z "${APPS[0]}" ]; then
echo "No Changed Apps"
echo "::set-output name=empty_matrix::true"
2021-05-09 16:11:00 +00:00
else
2021-05-09 16:47:43 +00:00
echo "Changed Apps: ${APPS[*]}"
2021-05-09 16:11:00 +00:00
echo "::set-output name=empty_matrix::false"
fi
2021-05-19 13:12:45 +00:00
app-tests :
2021-08-17 10:58:53 +00:00
needs : [ changes, prephelm]
2021-05-19 18:51:35 +00:00
if : ${{ needs.changes.outputs.empty_matrix == 'false' }}
2021-05-19 13:12:45 +00:00
name : App Tests
2021-05-19 18:51:35 +00:00
runs-on : ubuntu-latest
strategy :
matrix : ${{ fromJson(needs.changes.outputs.matrix) }}
fail-fast : false
steps :
2021-05-19 13:12:45 +00:00
##
# GENERAL SECTION
##
2021-05-19 18:51:35 +00:00
- name : Checkout
if : ${{ matrix.app != '.gitkee' }}
uses : actions/checkout@v2
with :
fetch-depth : 0
2021-08-17 10:58:53 +00:00
- name : Cache helm repo cache
2021-08-17 12:10:04 +00:00
id : cache
2021-08-17 10:58:53 +00:00
uses : actions/cache@v2
with :
2021-08-17 11:46:19 +00:00
key : helmrepocache-${{ github.sha }}
2021-08-17 10:58:53 +00:00
path : |
~/.cache/helm/repository
~/.config/helm/repositories.yaml
2021-05-19 18:51:35 +00:00
- name : Prepare-Lint
if : ${{ matrix.app != '.gitkee' }}
id : prep-lint
run : |
2021-09-03 10:07:03 +00:00
if test -f "./charts/incubator/${{ matrix.app }}/Chart.yaml"; then
2021-05-19 18:51:35 +00:00
train="incubator"
2021-09-03 10:16:39 +00:00
elif test -f "./charts/stable/${{ matrix.app }}/Chart.yaml"; then
2021-09-03 10:07:03 +00:00
train="stable"
2021-05-19 18:51:35 +00:00
elif test -f "./charts/library/${{ matrix.app }}/Chart.yaml"; then
train="library"
else
2021-08-23 19:32:52 +00:00
train="incubator"
2021-05-19 18:51:35 +00:00
fi
echo ::set-output name=train::${train}
if test -d "./charts/${train}/${{ matrix.app }}/tests/"; then
2021-05-19 13:12:45 +00:00
unittests='true'
2021-05-19 18:51:35 +00:00
echo "::set-output name=unittests::true"
else
unittests="false"
echo "::set-output name=unittests::false"
fi
2021-05-19 13:12:45 +00:00
- name : Install Helm
if : ${{ matrix.app != '.gitkee' }}
uses : azure/setup-helm@v1
with :
version : v3.5.3
2021-08-17 12:16:30 +00:00
- name : Cache-Error-Fix
if : steps.cache.outputs.cache-hit != 'true'
run : |
helm repo add truecharts https://truecharts.org
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
2021-05-19 13:12:45 +00:00
- uses : actions/setup-python@v2
if : ${{ matrix.app != '.gitkee' }}
with :
python-version : 3.7
- name : Set up chart-testing
if : ${{ matrix.app != '.gitkee' }}
2021-05-25 21:20:09 +00:00
uses : helm/chart-testing-action@v2.1.0
2021-05-19 13:12:45 +00:00
2021-05-19 18:51:35 +00:00
- uses : actions/setup-go@v2
if : ${{ steps.prep-lint.outputs.unittests == 'true' }}
with :
go-version : '^1.16'
2021-05-19 13:12:45 +00:00
##
# Unit-Test section
##
2021-05-19 18:51:35 +00:00
# Get values for cache paths to be used in later steps
- id : go-cache-paths
if : ${{ steps.prep-lint.outputs.unittests == 'true' }}
run : |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
2021-05-19 13:12:45 +00:00
2021-05-19 18:51:35 +00:00
# Cache go build cache, used to speedup go test
- name : Go Build Cache
if : ${{ steps.prep-lint.outputs.unittests == 'true' }}
uses : actions/cache@v2
with :
path : ${{ steps.go-cache-paths.outputs.go-build }}
key : ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
- name : Download modules
if : ${{ steps.prep-lint.outputs.unittests == 'true' }}
run : |
go mod download
2021-05-23 11:14:54 +00:00
- name : Run unit tests
2021-05-19 18:51:35 +00:00
if : ${{ steps.prep-lint.outputs.unittests == 'true' }}
run : |
go test ./charts/.../tests -json | tee test.json
2021-05-23 11:14:54 +00:00
- name : Annotate unit tests
2021-05-19 18:51:35 +00:00
if : ${{ steps.prep-lint.outputs.unittests == 'true' }}
2021-05-23 20:30:55 +00:00
uses : guyarb/golang-test-annotations@v0.4.0
2021-05-19 18:51:35 +00:00
with :
test-results : test.json
2021-05-23 11:14:54 +00:00
- name : Parse Unit Tests
2021-05-22 20:43:29 +00:00
if : ${{ steps.prep-lint.outputs.unittests == 'true' }}
run : |
if grep -q "FAIL" test.json
then
echo "Unit Test reported FAILED";
exit 1
else
echo "Unit Test reported OK";
exit 0
fi
2021-05-09 16:11:00 +00:00
2021-05-19 13:12:45 +00:00
##
# Chart-Testing Section
##
2021-05-09 16:11:00 +00:00
- name : Run chart-testing (lint)
if : ${{ matrix.app != '.gitkee' }}
id : lint
run : ct lint --config .github/ct-lint.yaml --charts 'charts/${{ steps.prep-lint.outputs.train }}/${{ matrix.app }}'
- name : Create k3d cluster
if : ${{ matrix.app != 'common' && matrix.app != '.gitkee' }}
uses : nolar/setup-k3d-k3s@v1
with :
version : v1.19
## TODO: Fix common-test
- name : Run chart-testing (install)
2021-05-10 12:13:17 +00:00
if : ${{ matrix.app != 'common' && matrix.app != '.gitkee' }}
2021-05-09 16:11:00 +00:00
run : ct install --config .github/ct-install.yaml --charts 'charts/${{ steps.prep-lint.outputs.train }}/${{ matrix.app }}'
app-tests-complete :
2021-05-19 13:12:45 +00:00
needs : [ app-tests]
2021-05-09 16:11:00 +00:00
name : Apps Test Complete
runs-on : ubuntu-latest
steps :
- name : complete message
run : echo "App Tests Completed Successfully"
2021-07-01 09:14:51 +00:00
catalog-test :
2021-08-17 11:37:41 +00:00
needs : [ prephelm]
2021-05-09 16:11:00 +00:00
runs-on : ubuntu-latest
2021-07-01 09:14:51 +00:00
container :
image : ixsystems/catalog_validation:latest
2021-05-09 16:11:00 +00:00
steps :
2021-08-17 12:04:31 +00:00
- name : Cache helm repo cache
2021-08-17 12:10:04 +00:00
id : cache
2021-08-17 12:04:31 +00:00
uses : actions/cache@v2
with :
key : helmrepocache-${{ github.sha }}
path : |
~/.cache/helm/repository
~/.config/helm/repositories.yaml
2021-05-09 16:11:00 +00:00
- uses : actions/checkout@v2
name : Checkout
2021-08-17 11:21:13 +00:00
2021-05-09 16:11:00 +00:00
- name : Checkout
2021-05-23 11:14:54 +00:00
uses : actions/checkout@v2
with :
fetch-depth : 0
path : master
- name : Checkout
uses : actions/checkout@v2
with :
fetch-depth : 0
repository : truecharts/catalog
path : catalog
2021-08-17 10:23:52 +00:00
2021-08-17 11:21:13 +00:00
- name : Install Helm
uses : azure/setup-helm@v1
with :
version : v3.5.3
2021-08-17 12:16:30 +00:00
- name : Cache-Error-Fix
if : steps.cache.outputs.cache-hit != 'true'
run : |
helm repo add truecharts https://truecharts.org
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
2021-05-09 16:11:00 +00:00
- name : Remove if release already exists
run : |
2021-08-17 11:35:13 +00:00
removetask(){
if [ -d "$2/SCALE" ]; then
maxchartversion=$(cat $2/Chart.yaml | grep "^version: " | awk -F" " '{ print $2 }')
chartname=$(basename $2)
echo "Processing... cleanup-existing... Chart: ${chartname} - Version: ${maxchartversion}"
rm -Rf catalog/$1/${chartname}/${maxchartversion} || echo "Chart release ${chartname} with version ${maxchartversion} does not exist yet... Skipping..."
rm -Rf catalog/$1/${chartname}/item.yaml || echo "No old catalog item.yaml found for ${chartname}"
else
echo "Skipping chart ${chart}, no correct SCALE compatibility layer detected"
fi
}
2021-08-23 19:32:52 +00:00
for train in stable incubator
2021-05-09 16:11:00 +00:00
do
for chart in master/charts/${train}/*; do
2021-08-17 11:46:19 +00:00
removetask "${train}" "${chart}" &
2021-05-09 16:11:00 +00:00
done
done
2021-08-17 11:35:13 +00:00
wait
2021-05-09 16:11:00 +00:00
- name : fetch dependencies
run : |
2021-08-17 12:04:31 +00:00
fetchtask(){
2021-08-17 12:29:16 +00:00
if [ -d "$1" ]; then
cd $1
helm dependency update --skip-refresh
cd -
fi
2021-08-17 12:04:31 +00:00
}
2021-08-23 19:32:52 +00:00
for train in stable incubator
2021-08-17 12:04:31 +00:00
do
for chart in master/charts/${train}/*; do
2021-08-17 13:25:50 +00:00
fetchtask "${chart}"
2021-05-09 16:11:00 +00:00
done
done
- name : Apply SCALE Patches
run : |
2021-08-17 12:35:02 +00:00
patchtask(){
if [ -d "$1/SCALE" ]; then
chartname=$(basename $1)
echo "Processing... Applying SCALE patch... Chart: ${chartname}"
mv $1/SCALE/item.yaml $1/
mv $1/SCALE/ix_values.yaml $1/
mv $1/SCALE/questions.yaml $1/
cp -rf $1/SCALE/templates/* $1/templates || echo "ignoring templates directory..."
rm -rf $1/SCALE
mv $1/values.yaml $1/test_values.yaml
touch $1/values.yaml
description=$(cat $1/Chart.yaml | grep "^description: " | sed -r 's/^description: //')
echo "${description}" >> $1/app-readme.md
else
echo "Skipping chart $1, no correct SCALE compatibility layer detected"
fi
}
2021-08-23 19:32:52 +00:00
for train in stable incubator
2021-05-09 16:11:00 +00:00
do
for chart in master/charts/${train}/*; do
2021-08-17 12:35:02 +00:00
patchtask "${chart}" &
2021-05-09 16:11:00 +00:00
done
done
2021-08-17 12:35:02 +00:00
wait
2021-05-09 16:11:00 +00:00
- name : Add Chart release
run : |
2021-08-17 12:35:02 +00:00
addtask(){
if [ -f "$1/item.yaml" ]; then
maxchartversion=$(cat $1/Chart.yaml | grep "^version: " | awk -F" " '{ print $2 }')
chartname=$(basename $1)
echo "Processing... Copying charts... Chart: ${chartname} - Version: ${maxchartversion}"
mkdir -p catalog/${train}/${chartname}/${maxchartversion}
cp -Rf $1/* catalog/${train}/${chartname}/${maxchartversion}/
mv catalog/${train}/${chartname}/${maxchartversion}/item.yaml catalog/${train}/${chartname}/item.yaml
else
echo "Skipping, chart $1 does not contain SCALE compatibility layer..."
fi
}
2021-08-23 19:32:52 +00:00
for train in stable incubator
2021-05-09 16:11:00 +00:00
do
for chart in master/charts/${train}/*; do
2021-08-17 12:35:02 +00:00
addtask "${chart}" &
2021-05-09 16:11:00 +00:00
done
done
2021-08-17 12:35:02 +00:00
wait
2021-05-09 16:11:00 +00:00
- name : Validate catalog format
run : |
cd catalog
/bin/bash -c "PWD=${pwd}; /usr/local/bin/catalog_validate validate --path $PWD"