chore: release main #10
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
name: onboarding | |
on: | |
pull_request: | |
branches: | |
- main | |
paths: | |
- "charts/**" | |
types: | |
- opened | |
env: | |
GIT_USER_NAME: ${{github.triggering_actor}} | |
GIT_USER_EMAIL: "${{github.triggering_actor}}@users.noreply.github.com" | |
RELEASE_PLEASE_CONFIG_FILE: "release-please-config.json" | |
RELEASE_PLEASE_MANIFEST_FILE: ".release-please-manifest.json" | |
jobs: | |
onboarding: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref }} | |
- id: onboarding | |
name: "Onboard new charts" | |
run: | | |
charts_dir="charts" | |
release_please_config_file="$RELEASE_PLEASE_CONFIG_FILE" | |
release_please_manifest_file="$RELEASE_PLEASE_MANIFEST_FILE" | |
tmp_config_file=$(mktemp) | |
tmp_manifest_file=$(mktemp) | |
onboarding_chart_version="0.0.0" | |
has_changes=false | |
# Check if release_please_config_file exists | |
if [ ! -f "$release_please_config_file" ]; then | |
echo "Error: $release_please_config_file not found." | |
exit 1 | |
fi | |
# initialize array to store updated charts | |
updated_charts=() | |
# Iterate through subdirectories in charts_dir | |
for sub_dir in "$charts_dir"/*; do | |
# Check if sub_dir is a directory | |
if [ -d "$sub_dir" ]; then | |
# find Chart.yaml/yml for chart | |
chart_file=$(find $sub_dir -maxdepth 1 -type f -name "Chart.yaml" -o -name "Chart.yml") | |
# Check if either Chart.yaml or Chart.yml exists and is non-empty | |
if [ -s "$chart_file" ]; then | |
if ! jq -e --arg sub_dir "$sub_dir" '.packages | has($sub_dir)' "$release_please_config_file" >/dev/null; then | |
# Use jq to update the JSON file | |
jq --arg sub_dir "$sub_dir" '.packages |= . + {($sub_dir): {}}' "$release_please_config_file" > "$tmp_config_file" | |
mv "$tmp_config_file" "$release_please_config_file" | |
# set inititial version as 0.0.0 in release-please manifest to get bumped to 1.0.0 in release-please workflow | |
jq --arg sub_dir "$sub_dir" \ | |
--arg chart_version "$onboarding_chart_version" \ | |
'. |= if has($sub_dir) then . else . + {($sub_dir): ($chart_version)} end' \ | |
"$release_please_manifest_file" > "$tmp_manifest_file" | |
mv "$tmp_manifest_file" "$release_please_manifest_file" | |
# update name of chart in Chart.yaml file with directory name of chart | |
chart_name=$(basename $sub_dir) | |
yq e ".name = \"$chart_name\"" $chart_file -i | |
# set inititial version as Chart version | |
yq e ".version = \"$onboarding_chart_version\"" $chart_file -i | |
cat $chart_file | |
# set has_changes true | |
has_changes=true | |
# add name of chart, which is directory name, into updated_chars array | |
updated_charts+=($sub_dir) | |
fi | |
else | |
echo "$sub_dir has no Chart.yaml/Chart.yml file or it is empty. it will be ignored" | |
fi | |
fi | |
done | |
# Output the updated JSON file | |
cat "$release_please_config_file" | |
cat "$release_please_manifest_file" | |
# Set GITHUB_OUTPUT | |
echo "has_new_charts=$has_changes" >>$GITHUB_OUTPUT | |
echo "updated_charts=${updated_charts[@]}" >>$GITHUB_OUTPUT | |
- name: Set git identity | |
if: ${{ steps.onboarding.outputs.has_new_charts == 'true' }} | |
run: | | |
git config user.name $GIT_USER_NAME | |
git config user.email $GIT_USER_EMAIL | |
- name: Commit the changes | |
if: ${{ steps.onboarding.outputs.has_new_charts == 'true' }} | |
run: | | |
git add $RELEASE_PLEASE_CONFIG_FILE $RELEASE_PLEASE_MANIFEST_FILE ${{ steps.onboarding.outputs.updated_charts }} | |
git commit --allow-empty -m "chore: onboarding new charts | |
Adding new chart directories | |
- actor: ${{github.triggering_actor}} | |
- type: auto commit | |
- workflow name: ${{github.workflow}} | |
- workflow branch: ${{github.head_ref}}(${{github.ref_name}}) | |
" | |
- name: Push the changes to base branch | |
if: ${{ steps.onboarding.outputs.has_new_charts == 'true' }} | |
run: | | |
git status | |
git push origin ${{github.head_ref}} |