Skip to content

Commit 565e779

Browse files
authored
Convert to composite action and use cache dir (#55)
Switch to composite action so we can get rid of Javascript and install cr to the cache location. Signed-off-by: Reinhard Nägele <[email protected]>
1 parent 7e3f32e commit 565e779

File tree

5 files changed

+52
-76
lines changed

5 files changed

+52
-76
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ A GitHub action to turn a GitHub project into a self-hosted Helm chart repo, usi
1515

1616
For more information on inputs, see the [API Documentation](https://developer.github.com/v3/repos/releases/#input)
1717

18-
- `version`: The chart-releaser version to use (default: v1.0.0)
18+
- `version`: The chart-releaser version to use (default: v1.1.1)
1919
- `config`: Optional config file for chart-releaser
2020
- `charts_dir`: The charts directory
2121
- `charts_repo_url`: The GitHub Pages URL to the charts repo (default: `https://<owner>.github.io/<project>`)
@@ -46,8 +46,13 @@ jobs:
4646
git config user.name "$GITHUB_ACTOR"
4747
git config user.email "[email protected]"
4848
49+
- name: Install Helm
50+
uses: azure/setup-helm@v1
51+
with:
52+
version: v3.4.0
53+
4954
- name: Run chart-releaser
50-
uses: helm/chart-releaser-action@v1.0.0
55+
uses: helm/chart-releaser-action@v1.1.1
5156
env:
5257
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
5358
```

action.yml

+24-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,35 @@ branding:
66
icon: anchor
77
inputs:
88
version:
9-
description: "The chart-releaser version to use (default: v1.0.0)"
9+
description: "The chart-releaser version to use (default: v1.1.1)"
1010
config:
1111
description: "The relative path to the chart-releaser config file"
1212
charts_dir:
1313
description: The charts directory
1414
default: charts
1515
charts_repo_url:
1616
description: "The GitHub Pages URL to the charts repo (default: https://<owner>.github.io/<repo>)"
17-
required: true
1817
runs:
19-
using: "node12"
20-
main: "main.js"
18+
using: composite
19+
steps:
20+
- run: |
21+
owner=$(cut -d '/' -f 1 <<< "$GITHUB_REPOSITORY")
22+
repo=$(cut -d '/' -f 2 <<< "$GITHUB_REPOSITORY")
23+
24+
args=(--owner "$owner" --repo "$repo")
25+
args+=(--charts-dir "${{ inputs.charts_dir }}")
26+
27+
if [[ -n "${{ inputs.version }}" ]]; then
28+
args+=(--version "${{ inputs.version }}")
29+
fi
30+
31+
if [[ -n "${{ inputs.config }}" ]]; then
32+
args+=(--config "${{ inputs.config }}")
33+
fi
34+
35+
if [[ -n "${{ inputs.charts_repo_url }}" ]]; then
36+
args+=(--charts-repo-url "${{ inputs.charts_repo_url }}")
37+
fi
38+
39+
"$GITHUB_ACTION_PATH/cr.sh" "${args[@]}"
40+
shell: bash

cr.sh

+21-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set -o errexit
1818
set -o nounset
1919
set -o pipefail
2020

21-
DEFAULT_CHART_RELEASER_VERSION=v1.1.0
21+
DEFAULT_CHART_RELEASER_VERSION=v1.1.1
2222

2323
show_help() {
2424
cat << EOF
@@ -177,11 +177,26 @@ parse_command_line() {
177177
}
178178

179179
install_chart_releaser() {
180-
echo "Installing chart-releaser..."
180+
if [[ ! -d "$RUNNER_TOOL_CACHE" ]]; then
181+
echo "Cache directory '$RUNNER_TOOL_CACHE' does not exist" >&2
182+
exit 1
183+
fi
184+
185+
local arch
186+
arch=$(uname -m)
181187

182-
curl -sSLo cr.tar.gz "https://github.com/helm/chart-releaser/releases/download/$version/chart-releaser_${version#v}_linux_amd64.tar.gz"
183-
tar -xzf cr.tar.gz
184-
sudo mv cr /usr/local/bin/cr
188+
local cache_dir="$RUNNER_TOOL_CACHE/ct/$version/$arch"
189+
if [[ ! -d "$cache_dir" ]]; then
190+
mkdir -p "$cache_dir"
191+
192+
echo "Installing chart-releaser..."
193+
curl -sSLo cr.tar.gz "https://github.com/helm/chart-releaser/releases/download/$version/chart-releaser_${version#v}_linux_amd64.tar.gz"
194+
tar -xzf cr.tar.gz -C "$cache_dir"
195+
rm -f cr.tar.gz
196+
197+
echo 'Adding cr directory to PATH...'
198+
export PATH="$cache_dir:$PATH"
199+
fi
185200
}
186201

187202
lookup_latest_tag() {
@@ -219,7 +234,7 @@ lookup_changed_charts() {
219234
package_chart() {
220235
local chart="$1"
221236

222-
local args=(--package-path .cr-release-packages)
237+
local args=("$chart" --package-path .cr-release-packages)
223238
if [[ -n "$config" ]]; then
224239
args+=(--config "$config")
225240
fi

main.js

-19
This file was deleted.

main.sh

-45
This file was deleted.

0 commit comments

Comments
 (0)