Skip to content

Commit 0780c7d

Browse files
Action Improvements (#6)
Helm Release Action 1.0.0
1 parent 30b07cf commit 0780c7d

File tree

4 files changed

+113
-39
lines changed

4 files changed

+113
-39
lines changed

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ RUN apk add --no-cache ca-certificates curl bash git openssl && \
1919
chmod +x ./cr && \
2020
mv ./cr /usr/local/bin/
2121

22+
## Install Helm Plugins
23+
##
24+
RUN helm plugin install https://github.com/karuppiah7890/helm-schema-gen
25+
2226
## Execute Action Handler
2327
##
2428
CMD [ "bash", "/usr/local/src/release.sh" ]

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ With the following steps you can use this action in your repository:
1616
Here is a list which variables can be given/used by the script. Some values can be set over action input values. If not, there's an environment variable to change the behavior.
1717

1818
| Input | Description | Environment Variable | Default |
19-
|:---|:---|:---|:---|
19+
| :---- | :---------- | :------------------- | :------ |
2020
| `config` | Define a Chart Releaser config file. | - | `${HOME}/cr.yaml` |
21+
| `chartConfig` | Define filename for [Chart Configurations](#chart-configuration) | - | `.chart-config` |
2122
| `chartRoot` | Define the root directory for your charts. If you have multiple chart directories I would advise doing multiple Github jobs. | - | `charts/` |
2223
| `token` | Define a token which is used to create the chart releases and make changes to the gh-pages branch. | `$CR_TOKEN` | - |
2324
| `repository` | Define where to index for the helm repository is published. This is mainly used to append new changes to an existing index via Chart Releaser. If no index is found, a new index will be created. | `$CR_REPO_URL` | `https://$(cut -d '/' -f 1 <<< $GITHUB_REPOSITORY).github.io/$(cut -d '/' -f 2 <<< $GITHUB_REPOSITORY)/` |
@@ -26,6 +27,36 @@ Here is a list which variables can be given/used by the script. Some values can
2627
| `user` | Define the user name used for commits (pages update). | `$GIT_USER` | `$GITHUB_ACTOR` |
2728
| `email` | Define the user email used for commits (pages update). | `$GIT_EMAIL` | `[email protected]` |
2829

30+
## Chart Configuration
31+
32+
Certain configurations are required on chart basis. With the following variables there's the possibility to change a single charts behavior. By default you can place these variables in a file called `.chart-config` in a chart directory.
33+
34+
| Variable | Description | Values |
35+
| :------- | :---------- | :----- |
36+
| `DISABLE` | Disables the chart during the release process. | `true`/`false` |
37+
| `SCHEMA_GENERATE` | Generates Schema with [helm-schema-gen](https://github.com/karuppiah7890/helm-schema-gen) if no values.schema.json file exists. | `true`/`false` |
38+
| `SCHEMA_VALUES` | Define the location of the values file within the chart directory, which is used to generate the values schema. | `values.yaml` |
39+
| `SCHEMA_FORCE` | If there is already a `values.schema.json` file present in the chart directory, no schema will be generated. This option forces to generate the schema and overwrite present schema files. | `true`/`false` |
40+
41+
### Examples
42+
43+
Disable a chart (Won't create a new release)
44+
45+
**charts/sample-chart/.chart-config**
46+
47+
```
48+
DISABLE=true
49+
```
50+
51+
Enable enforced Schema Generation
52+
53+
**charts/sample-chart-2/.chart-config**
54+
55+
```
56+
SCHEMA_GENERATE=true
57+
SCHEMA_FORCE=true
58+
```
59+
2960
## Usage
3061

3162
Using this action with it's default values is very easy. Just pass the Built-In `$GITHUB_TOKEN` environment variable and you are good to go:

action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ inputs:
1313
required: true
1414

1515
## Configuration fo a Chart Releaser COnfiguration
16-
## Reference:
1716
##
1817
config:
1918
description: 'Chart Releaser configuration file'
2019
required: false
2120
default: './cr.yaml'
2221

22+
## Chart Configuration filename
23+
##
24+
chartConfig:
25+
description: 'Chart Configuration file'
26+
required: false
27+
28+
2329
## Configuration for the git username (Release owner)
2430
##
2531
user:

release.sh

Lines changed: 70 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ createDirs() {
1414
rm -rf .cr-index && mkdir -p .cr-index ## Recreates Index File
1515
}
1616

17+
## Chart Configuration
18+
##
19+
CONFIG_NAME=${INPUT_CHARTCONFIG:-".chart-config"}
20+
CONFIG_SUPPORTED_VALUES=( "DISABLE" "GENERATE_SCHEMA" "SCHEMA_VALUES" "SCHEMA_FORCE" )
21+
22+
## Install Helm Plugins
23+
##
24+
helm plugin install https://github.com/karuppiah7890/helm-schema-gen
25+
1726
## Environment Variables
1827
## CR Configuration Variables (Required)
1928

@@ -80,19 +89,6 @@ HEAD_REV=$(git rev-parse --verify HEAD);
8089
LATEST_TAG_REV=$(git rev-parse --verify "$(latestTag)");
8190
if [[ "$LATEST_TAG_REV" == "$HEAD_REV" ]]; then echo -e "\n\e[33mNothing to do!\e[0m\n"; exit 0; fi
8291

83-
## Instead make two seperate jobs in your action
84-
##
85-
## Evaluate Chart directories
86-
## Checks if the variable is split with ,
87-
## if so, the variable is parsed as array otherwise
88-
## as single directory
89-
##
90-
#if [[ ${CHART_ROOT} == *","* ]]; then
91-
# IFS=', ' read -r -a ROOT_DIRS <<< "${CHART_ROOT}"
92-
#else
93-
# ROOT_DIRS=(${CHART_ROOT})
94-
#fi
95-
9692
## Initialize for each directory a matching regex
9793
## which finds changes in the diff statement
9894
##
@@ -103,14 +99,14 @@ CHANGED_CHARTS="${CHANGED_CHARTS} $(git diff --find-renames --name-only $LATEST_
10399
## All changed charts are parsed as array
104100
## Xargs is used to trim spaces left and right
105101
##
106-
readarray -t PUBLISH_CHARTS <<< "$(echo ${CHANGED_CHARTS} | xargs )"
102+
IFS=' ' read -a PUBLISH_CHARTS <<< "$(echo ${CHANGED_CHARTS} | xargs )"
107103

108104
## Checks if there were any changes made
109105
## Because the variable structing is not super clean
110106
## I ended up with these two checks. Might be
111107
## improved in the future
112108
##
113-
if ! [[ -z $(echo "${CHANGED_CHARTS}" | xargs) ]] && [[ ${#PUBLISH_CHARTS[@]} -gt 0 ]]; then
109+
if [[ ${#PUBLISH_CHARTS[@]} -gt 0 ]]; then
114110

115111
## Check if charts exist as directory, this
116112
## serves as simple handler when a chart is removed
@@ -143,34 +139,71 @@ if ! [[ -z $(echo "${CHANGED_CHARTS}" | xargs) ]] && [[ ${#PUBLISH_CHARTS[@]} -g
143139
echo -e "\n\e[33m- Crafting Packages\e[0m"
144140
for CHART in "${EXISTING_CHARTS[@]}"; do
145141
echo -e "\n\e[32m-- Package: $CHART\e[0m"
146-
helm package $CHART --dependency-update --destination ${CR_RELEASE_LOCATION}
142+
143+
## Lookup Release Configuration
144+
c_config="${CHART%/}/${CONFIG_NAME}"
145+
echo -e "--- Configuration lookup ($c_config)"
146+
if [ -f "$c_config" ]; then
147+
echo -e "--- Found Configuration"
148+
# shellcheck source=/dev/null
149+
source "$c_config"
150+
fi
151+
152+
## Filter disabled Charts
153+
if [[ "${DISABLE,,}" == "true" ]]; then
154+
echo -e "--- Chart Disabled"
155+
else
156+
## Chart Schema Generator
157+
SCHEMA_PATH="${CHART%/}/values.schema.json"
158+
if [[ "${SCHEMA_GENERATE,,}" == "true" ]]; then
159+
echo -e "--- Attempt to generate Values Schema"
160+
if ! [ -f "${SCHEMA_PATH}" ] || [[ "${SCHEMA_FORCE,,}" == "true" ]]; then
161+
echo -e "--- Generating Values Schema"
162+
helm schema-gen "${CHART%/}/${SCHEMA_VALUES:values.yaml}" > "${SCHEMA_PATH}"
163+
else
164+
echo -e "--- Skipping Values Schema"
165+
fi
166+
else
167+
echo -e "--- Values Schema Disabled"
168+
fi
169+
170+
echo -e "--- Creating Helm Package"
171+
helm package $CHART --dependency-update --destination ${CR_RELEASE_LOCATION}
172+
fi
173+
174+
## Unset Configuration Values
175+
unset "$(echo ${CONFIG_SUPPORTED_VALUES[*]})"
147176
done
148177

149178
## For each package made by helm cr will
150179
## create a helm release on the GitHub Repository
151180
##
152181
echo -e "\n\e[33m- Creating Releases\e[0m\n"
153-
if ! cr upload $CR_ARGS; then echo -e "\n\e[91mSomething went wrong! Checks the logs above\e[0m\n"; exit 1; fi
154-
155-
## Setup git with the given Credentials
156-
##
157-
git config user.name "$GIT_USER"
158-
git config user.email "$GIT_EMAIL"
159-
160-
## Recreate Index for the Pages index
161-
##
162-
if ! cr index -c "$CR_REPO_URL" $CR_ARGS; then echo -e "\n\e[91mSomething went wrong! Checks the logs above\e[0m\n"; exit 1; fi
163-
164-
## Checkout the pages branch and
165-
## add Index as new addition and make a signed
166-
## commit to the origin
167-
##
168-
git checkout -f gh-pages
169-
cp -f .cr-index/index.yaml index.yaml || true
170-
git add index.yaml
171-
git status
172-
git commit -sm "Update index.yaml"
173-
git push origin gh-pages
182+
if [ "$(ls -A ${CR_RELEASE_LOCATION})" ]; then
183+
if ! cr upload $CR_ARGS; then echo -e "\n\e[91mSomething went wrong! Checks the logs above\e[0m\n"; exit 1; fi
184+
185+
## Setup git with the given Credentials
186+
##
187+
git config user.name "$GIT_USER"
188+
git config user.email "$GIT_EMAIL"
189+
190+
## Recreate Index for the Pages index
191+
##
192+
if ! cr index -c "$CR_REPO_URL" $CR_ARGS; then echo -e "\n\e[91mSomething went wrong! Checks the logs above\e[0m\n"; exit 1; fi
193+
194+
## Checkout the pages branch and
195+
## add Index as new addition and make a signed
196+
## commit to the origin
197+
##
198+
git checkout -f gh-pages
199+
cp -f .cr-index/index.yaml index.yaml || true
200+
git add index.yaml
201+
git status
202+
git commit -sm "Update index.yaml"
203+
git push origin gh-pages
204+
else
205+
echo "Nothing to release" && exit 0
206+
fi
174207
else
175208
## Some Feedback
176209
echo -e "\n\e[33mChanges to non existent chart detected.\e[0m\n"; exit 0;

0 commit comments

Comments
 (0)