This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4fb3a49
commit 77a0b16
Showing
13 changed files
with
167 additions
and
140 deletions.
There are no files selected for viewing
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
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
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
107 changes: 38 additions & 69 deletions
107
.github/workflows/zz_generated.check_values_schema.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,53 @@ | ||
# DO NOT EDIT. Generated with: | ||
# | ||
# devctl@5.9.0 | ||
# devctl@6.5.0 | ||
# | ||
name: 'Check if values schema file has been updated' | ||
on: pull_request | ||
name: 'Values and schema' | ||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
- main | ||
paths: | ||
- 'helm/**/values.yaml' # default helm chart values | ||
- 'helm/**/values.schema.json' # schema | ||
- 'helm/**/ci/ci-values.yaml' # overrides for CI (can contain required entries) | ||
|
||
push: {} | ||
|
||
jobs: | ||
check: | ||
name: 'Check values.yaml and its schema in PR' | ||
name: 'validate values.yaml against values.schema.json' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 'Checkout' | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: 'Check if values.schema.json was updated' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
echo "Comparing ${GITHUB_BASE_REF}...${GITHUB_HEAD_REF}" | ||
# check if repo contains a schema file | ||
if grep -q "values.schema.json" <<< $(git ls-tree -r --name-only ${GITHUB_SHA}); then | ||
# get a list of files changed in the PR | ||
CHANGED_FILES=$(gh api repos/{owner}/{repo}/compare/${GITHUB_BASE_REF}...${GITHUB_HEAD_REF} \ | ||
--jq ".files[].filename") | ||
# check if values.yaml in main chart was modified by this PR | ||
# (this won't check values files in subcharts) | ||
if grep -q 'helm\/[-a-z].*\/values.yaml' <<< "${CHANGED_FILES}" ; then | ||
# get the path to values.yaml | ||
VALUES_FILE=$(gh api repos/{owner}/{repo}/compare/${GITHUB_BASE_REF}...${GITHUB_HEAD_REF} \ | ||
--jq ".files[].filename" | grep 'helm\/[-a-z].*\/values.yaml') | ||
# fetch branches so we can use them to compare | ||
git fetch &> /dev/null | ||
# calculate hash of the keys from values.yaml from the default branch | ||
DEFAULT_BRANCH_SHA=$(git show origin/${GITHUB_BASE_REF}:${VALUES_FILE} \ | ||
| yq -P 'sort_keys(..)' -o=json | jq -r '[paths | join(".")]' \ | ||
| sha1sum | awk '{print $1}') | ||
with: | ||
fetch-depth: 0 | ||
|
||
# calculate hash of the keys from values.yaml from this branch | ||
THIS_BRANCH_SHA=$(git show origin/${GITHUB_HEAD_REF}:${VALUES_FILE} \ | ||
| yq -P 'sort_keys(..)' -o=json | jq -r '[paths | join(".")]' \ | ||
| sha1sum | awk '{print $1}') | ||
# compare hashes of the values files | ||
if [[ "${DEFAULT_BRANCH_SHA}" != "${THIS_BRANCH_SHA}" ]]; then | ||
# values file structure has been modified so we need to ensure the schema | ||
# file is also updated | ||
if grep -q "values.schema.json" <<< "${CHANGED_FILES}" ; then | ||
# we assume that the schema has been updated, nothing to do | ||
echo "PASSED: values.yaml and values.schema.json both appear to have been updated" | ||
exit 0 | ||
else | ||
# schema must be updated | ||
echo "FAILED: values.yaml was updated but values.schema.json hasn't been regenerated" | ||
echo "Please refer to this document: https://intranet.giantswarm.io/docs/organizational-structure/teams/cabbage/app-updates/helm-values-schema/" | ||
exit 1 | ||
fi | ||
- name: Install validator | ||
run: | | ||
wget -q -O ${HOME}/yajsv https://github.com/neilpa/yajsv/releases/download/v1.4.1/yajsv.linux.amd64 | ||
chmod +x ${HOME}/yajsv | ||
else | ||
# values file structure hasn't changed, nothing to do | ||
echo "values.yaml structure hasn't been changed by this PR" | ||
exit 0 | ||
fi | ||
- name: 'Check if values.yaml is a valid instance of values.schema.json' | ||
run: | | ||
for chart_yaml in helm/*/Chart.yaml; do | ||
helm_dir="${chart_yaml%/Chart.yaml}" | ||
else | ||
# values file not included in PR, nothing to see here | ||
echo "values.yaml not included in this PR" | ||
exit 0 | ||
if [ ! -f ${helm_dir}/values.schema.json ]; then | ||
echo "Skipping validation for '${helm_dir}' folder, because 'values.schema.json' does not exist..." | ||
continue | ||
fi | ||
else | ||
# if grep returns negative then there isn't a values.schema.json to check | ||
echo "No values.schema.json file found in branch '${GITHUB_BASE_REF}', nothing to check" | ||
exit 0 | ||
values=${helm_dir}/values.yaml | ||
if [ -f ${helm_dir}/ci/ci-values.yaml ]; then | ||
# merge ci-values.yaml into values.yaml (providing required values) | ||
echo -e "\nMerged values:\n==============" | ||
yq '. *= load("'${helm_dir}'/ci/ci-values.yaml")' ${helm_dir}/values.yaml | tee ${helm_dir}/combined-values.yaml | ||
echo -e "\n==============\n" | ||
values=${helm_dir}/combined-values.yaml | ||
fi | ||
fi | ||
${HOME}/yajsv -s ${helm_dir}/values.schema.json ${values} | ||
done |
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
Oops, something went wrong.