Files
charts/.github/workflows/vib-early-feedback.yaml
Javier J. Salmerón-García 6707a2c446 [bitnami/*]: test: 🚸 Make "Early Feedback" run in all PRs (#9077)
Signed-off-by: Javier Salmeron Garcia <jsalmeron@vmware.com>
2022-02-18 16:48:51 +01:00

81 lines
4.1 KiB
YAML

name: 'Early feedback'
on: # rebuild any PRs and main branch changes
pull_request_target:
branches:
- master
- bitnami:master
env:
CSP_API_URL: https://console.cloud.vmware.com
CSP_API_TOKEN: ${{ secrets.CSP_API_TOKEN }}
VIB_PUBLIC_URL: https://cp.bromelia.vmware.com
jobs:
get-chart:
runs-on: ubuntu-latest
name: 'Get modified charts'
outputs:
chart: ${{ steps.get-chart.outputs.chart }}
result: ${{ steps.get-chart.outputs.result }}
steps:
- uses: actions/checkout@v2
name: 'Checkout Repository'
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
fetch-depth: 0
- id: get-chart
name: 'Get modified charts'
run: |
# Using the Github API to detect the files changed as git merge-base stops working when the branch is behind
# and jitterbit/get-changed-files does not support pull_request_target
URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files"
files_changed="$(curl -s --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -X GET -G "$URL" | jq -r '.[] | .filename')"
# Adding || true to avoid "Process exited with code 1" errors
charts_dirs_changed="$(echo "$files_changed" | xargs dirname | grep -o "bitnami/[^/]*" | sort | uniq || true)"
# Using grep -c as a better alternative to wc -l when dealing with empty strings."
num_charts_changed="$(echo "$charts_dirs_changed" | grep -c "bitnami" || true)"
num_version_bumps="$(echo "$files_changed" | grep Chart.yaml | xargs git diff origin/master | grep -c "+version" || true)"
if [[ "$num_charts_changed" -ne "$num_version_bumps" ]]; then
# Changes done in charts but version not bumped -> ERROR
echo "::set-output name=error::Detected changes in charts without version bump in Chart.yaml.\nCharts changed: ${num_charts_changed}\n${charts_dirs_changed}\nVersion bumps detected: ${num_version_bumps}"
echo "::set-output name=result::fail"
elif [[ "$num_charts_changed" -eq "1" ]]; then
# Changes done in only one chart -> OK
echo "::set-output name=chart::${charts_dirs_changed}"
echo "::set-output name=result::ok"
elif [[ "$num_charts_changed" -le "0" ]]; then
# Changes done in the bitnami/ folder but not inside a chart subfolder -> SKIP
echo "::set-output name=error::No changes detected in charts. The rest of the tests will be skipped."
echo "::set-output name=result::skip"
else
# Changes done in more than chart -> SKIP
echo -e "::set-output name=error::Changes detected in more than one chart directory:\n${charts_dirs_changed}\nIt is strongly advised to change only one chart in a PR. The rest of the tests will be skipped."
echo "::set-output name=result::skip"
fi
# Using actions/github-scripts because using exit 1 in the script above would not provide any output
# Source: https://github.community/t/no-output-on-process-completed-with-exit-code-1/123821/3
- id: show-error
name: 'Show error'
if: ${{steps.get-chart.outputs.result == 'fail'}}
uses: actions/github-script@v3
with:
script: |
core.setFailed('${{steps.get-chart.outputs.error}}')
vib-execution:
runs-on: ubuntu-latest
needs: get-chart
if: ${{needs.get-chart.outputs.result == 'ok'}}
name: 'Package, Lint and Trivy scan'
steps:
- uses: actions/checkout@v2
name: 'Checkout Repository'
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- uses: vmware-samples/vmware-image-builder-examples/vib-action@main
name: 'Package, Lint and Trivy scan'
with:
pipeline: vib-early-feedback.json
env:
VIB_ENV_CHART_PATH: "${{needs.get-chart.outputs.chart}}"