-
Notifications
You must be signed in to change notification settings - Fork 1
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
729b418
commit 66a058a
Showing
1 changed file
with
66 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,24 +23,72 @@ jobs: | |
token: ${{ steps.generate_token.outputs.token }} | ||
command: manifest | ||
monorepo-tags: true | ||
- uses: actions/checkout@v2 | ||
- name: test | ||
# - uses: actions/checkout@v2 | ||
# - name: test | ||
# run: | | ||
# # find the chart that contains changes | ||
# if [ "$(git rev-parse --abbrev-ref HEAD)" == "HEAD" ]; then | ||
# # Detached HEAD state, use HEAD~1 instead | ||
# CHANGED_CHARTS=$(git diff --name-only HEAD~1 HEAD | grep "^charts/") | ||
# else | ||
# CHANGED_CHARTS=$(git diff --name-only HEAD^ HEAD | grep "^charts/") | ||
# fi | ||
|
||
# echo "changed charts: $CHANGED_CHARTS" | ||
|
||
# for chart_dir in $CHANGED_CHARTS; do | ||
# echo $chart_dir | ||
# done | ||
# - name: Run chart-releaser | ||
# if: ${{ steps.release.outputs.releases_created }} | ||
# uses: helm/[email protected] | ||
# env: | ||
# CR_TOKEN: ${{ steps.generate_token.outputs.token }} | ||
get-chart: | ||
runs-on: ubuntu-latest | ||
# needs: release-please | ||
name: 'Get modified charts' | ||
permissions: | ||
contents: read | ||
outputs: | ||
chart: ${{ steps.get-chart.outputs.chart }} | ||
result: ${{ steps.get-chart.outputs.result }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
path: charts | ||
fetch-depth: 2 # to be able to obtain files changed in the latest commit | ||
- id: get-chart | ||
name: 'Get modified charts' | ||
run: | | ||
# find the chart that contains changes | ||
if [ "$(git rev-parse --abbrev-ref HEAD)" == "HEAD" ]; then | ||
# Detached HEAD state, use HEAD~1 instead | ||
CHANGED_CHARTS=$(git diff --name-only HEAD~1 HEAD | grep "^charts/") | ||
cd charts | ||
files_changed="$(git show --pretty="" --name-only)" | ||
# Adding || true to avoid "Process exited with code 1" errors | ||
charts_dirs_changed="$(echo "$files_changed" | xargs dirname | grep -o "charts/[^/]*" | 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 "charts" || true)" | ||
num_version_bumps="$(echo "$files_changed" | grep Chart.yaml | xargs git show | grep -c "+version" || true)" | ||
if [[ "$num_charts_changed" -ne "$num_version_bumps" ]]; then | ||
# Changes done in charts but version not bumped -> ERROR | ||
charts_changed_str="$(echo ${charts_dirs_changed[@]})" | ||
echo "error=Detected changes in charts without version bump in Chart.yaml. Charts changed: ${num_charts_changed} ${charts_changed_str}. Version bumps detected: ${num_version_bumps}" >> $GITHUB_OUTPUT | ||
echo "result=fail" >> $GITHUB_OUTPUT | ||
elif [[ "$num_charts_changed" -eq "1" ]]; then | ||
# Changes done in only one chart -> OK | ||
chart_name=$(echo "$charts_dirs_changed" | sed "s|charts/||g") | ||
echo "chart=${chart_name}" >> $GITHUB_OUTPUT | ||
echo "result=ok" >> $GITHUB_OUTPUT | ||
else | ||
CHANGED_CHARTS=$(git diff --name-only HEAD^ HEAD | grep "^charts/") | ||
# Changes done in more than chart -> FAIL | ||
charts_changed_str="$(echo ${charts_dirs_changed[@]})" | ||
echo "error=Changes detected in more than one chart directory: ${charts_changed_str}. The publish process will be stopped. Please create different commits for each chart." >> $GITHUB_OUTPUT | ||
echo "result=fail" >> $GITHUB_OUTPUT | ||
fi | ||
echo "changed charts: $CHANGED_CHARTS" | ||
for chart_dir in $CHANGED_CHARTS; do | ||
echo $chart_dir | ||
done | ||
- name: Run chart-releaser | ||
if: ${{ steps.release.outputs.releases_created }} | ||
uses: helm/[email protected] | ||
env: | ||
CR_TOKEN: ${{ steps.generate_token.outputs.token }} | ||
- id: show-error | ||
name: 'Show error' | ||
if: ${{ steps.get-chart.outputs.result == 'fail' }} | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
core.setFailed('${{ steps.get-chart.outputs.error }}') |