forked from sunggun-yu/meowhq-helm-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (101 loc) · 4.54 KB
/
onboarding.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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}}