Files
charts/.github/workflows/generate-chart-readme.yml
Fran Mulero 302eb6019f [bitnami/charts] GitHub actions hardening (#20675)
* GitHub actions hardening

Signed-off-by: Fran Mulero <fmulero@vmware.com>

* Fix typo

Signed-off-by: Fran Mulero <fmulero@vmware.com>

---------

Signed-off-by: Fran Mulero <fmulero@vmware.com>
2023-11-08 10:38:36 +01:00

79 lines
3.7 KiB
YAML

# Copyright VMware, Inc.
# SPDX-License-Identifier: APACHE-2.0
name: '[CI/CD] Update README metadata'
on:
pull_request_target:
branches:
- main
paths:
- 'bitnami/*/values.yaml'
# Remove all permissions by default
permissions: {}
jobs:
update-readme-metadata:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Install readme-generator-for-helm
run: npm install -g @bitnami/readme-generator-for-helm
- name: Checkout bitnami/charts
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
path: charts
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
token: ${{ github.actor == 'bitnami-bot' && secrets.GITHUB_TOKEN || secrets.BITNAMI_BOT_TOKEN }}
- name: Execute readme-generator-for-helm
env:
DIFF_URL: "${{github.event.pull_request.diff_url}}"
TEMP_FILE: "${{runner.temp}}/pr-${{github.event.number}}.diff"
run: |
exit_code=0
# This request doesn't consume API calls.
curl -Lkso $TEMP_FILE $DIFF_URL
files_changed="$(sed -nr 's/[\-\+]{3} [ab]\/(.*)/\1/p' $TEMP_FILE | sort | uniq)"
# Adding || true to avoid "Process exited with code 1" errors
charts_dirs_changed="$(echo "$files_changed" | xargs dirname | grep -o "bitnami/[^/]*" | sort | uniq || true)"
for chart in ${charts_dirs_changed}; do
echo "Validating README.md for ${chart}"
# Validating *.registry parameters
while read line; do
echo "$line" | grep --quiet "\[default: \(REGISTRY_NAME\|\"\"\)\]" || exit_code=$?
done < <(grep "@param\s\+[A-Za-z\.]\+\.registry\s\+" "charts/${chart}/values.yaml")
if [[ $exit_code -ne 0 ]]; then
echo "::error:: Please ensure all *.registry params include the [default: REGISTRY_NAME] modifier the chart/${chart}/values.yaml file"
exit "$exit_code"
fi
# Validating *.repository parameters
while read line; do
param=$(echo "$line" | awk '{print $3}')
# Checking if it's a image's registry-related param
registry_param=$(echo ${param} | sed 's/\.repository/\.registry/g')
grep --quiet "@param\s\+${registry_param}" "charts/${chart}/values.yaml" && ( echo "$line" | grep --quiet "\[default: \(REPOSITORY_NAME/.*\|\"\"\)\]" || exit_code=$? )
done < <(grep "@param\s\+[A-Za-z\.]\+\.repository\s\+" "charts/${chart}/values.yaml")
if [[ $exit_code -ne 0 ]]; then
echo "::error:: Please ensure all *.repository params include the [default: REPOSITORY_NAME] modifier the charts/${chart}/values.yaml file"
exit "$exit_code"
fi
# Validating *.tag parameters
! grep --quiet "@param\s\+[A-Za-z\.]\+\.tag\s\+" "charts/${chart}/values.yaml" || exit_code=$?
if [[ $exit_code -ne 0 ]]; then
echo "::error:: Please ensure all *.tag params are skipped (@skip) in the charts/${chart}/values.yaml file"
exit "$exit_code"
fi
echo "Updating README.md for ${chart}"
readme-generator --values "charts/${chart}/values.yaml" --readme "charts/${chart}/README.md" --schema "/tmp/schema.json"
done
- name: Push changes
run: |
# Push all the changes
cd charts
if git status -s | grep bitnami; then
git config user.name "Bitnami Containers"
git config user.email "bitnami-bot@vmware.com"
git add . && git commit -am "Update README.md with readme-generator-for-helm" --signoff && git push
fi