Skip to content

Commit

Permalink
Convert to composite action and use cache dir (#55)
Browse files Browse the repository at this point in the history
Switch to composite action so we can get rid of Javascript and install
cr to the cache location.

Signed-off-by: Reinhard Nägele <unguiculus@gmail.com>
  • Loading branch information
unguiculus committed Nov 4, 2020
1 parent 7e3f32e commit 565e779
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 76 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A GitHub action to turn a GitHub project into a self-hosted Helm chart repo, usi

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

- `version`: The chart-releaser version to use (default: v1.0.0)
- `version`: The chart-releaser version to use (default: v1.1.1)
- `config`: Optional config file for chart-releaser
- `charts_dir`: The charts directory
- `charts_repo_url`: The GitHub Pages URL to the charts repo (default: `https://<owner>.github.io/<project>`)
Expand Down Expand Up @@ -46,8 +46,13 @@ jobs:
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.4.0

- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.0.0
uses: helm/chart-releaser-action@v1.1.1
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
```
Expand Down
28 changes: 24 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,35 @@ branding:
icon: anchor
inputs:
version:
description: "The chart-releaser version to use (default: v1.0.0)"
description: "The chart-releaser version to use (default: v1.1.1)"
config:
description: "The relative path to the chart-releaser config file"
charts_dir:
description: The charts directory
default: charts
charts_repo_url:
description: "The GitHub Pages URL to the charts repo (default: https://<owner>.github.io/<repo>)"
required: true
runs:
using: "node12"
main: "main.js"
using: composite
steps:
- run: |
owner=$(cut -d '/' -f 1 <<< "$GITHUB_REPOSITORY")
repo=$(cut -d '/' -f 2 <<< "$GITHUB_REPOSITORY")
args=(--owner "$owner" --repo "$repo")
args+=(--charts-dir "${{ inputs.charts_dir }}")
if [[ -n "${{ inputs.version }}" ]]; then
args+=(--version "${{ inputs.version }}")
fi
if [[ -n "${{ inputs.config }}" ]]; then
args+=(--config "${{ inputs.config }}")
fi
if [[ -n "${{ inputs.charts_repo_url }}" ]]; then
args+=(--charts-repo-url "${{ inputs.charts_repo_url }}")
fi
"$GITHUB_ACTION_PATH/cr.sh" "${args[@]}"
shell: bash
27 changes: 21 additions & 6 deletions cr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set -o errexit
set -o nounset
set -o pipefail

DEFAULT_CHART_RELEASER_VERSION=v1.1.0
DEFAULT_CHART_RELEASER_VERSION=v1.1.1

show_help() {
cat << EOF
Expand Down Expand Up @@ -177,11 +177,26 @@ parse_command_line() {
}

install_chart_releaser() {
echo "Installing chart-releaser..."
if [[ ! -d "$RUNNER_TOOL_CACHE" ]]; then
echo "Cache directory '$RUNNER_TOOL_CACHE' does not exist" >&2
exit 1
fi

local arch
arch=$(uname -m)

curl -sSLo cr.tar.gz "https://github.com/helm/chart-releaser/releases/download/$version/chart-releaser_${version#v}_linux_amd64.tar.gz"
tar -xzf cr.tar.gz
sudo mv cr /usr/local/bin/cr
local cache_dir="$RUNNER_TOOL_CACHE/ct/$version/$arch"
if [[ ! -d "$cache_dir" ]]; then
mkdir -p "$cache_dir"

echo "Installing chart-releaser..."
curl -sSLo cr.tar.gz "https://github.com/helm/chart-releaser/releases/download/$version/chart-releaser_${version#v}_linux_amd64.tar.gz"
tar -xzf cr.tar.gz -C "$cache_dir"
rm -f cr.tar.gz

echo 'Adding cr directory to PATH...'
export PATH="$cache_dir:$PATH"
fi
}

lookup_latest_tag() {
Expand Down Expand Up @@ -219,7 +234,7 @@ lookup_changed_charts() {
package_chart() {
local chart="$1"

local args=(--package-path .cr-release-packages)
local args=("$chart" --package-path .cr-release-packages)
if [[ -n "$config" ]]; then
args+=(--config "$config")
fi
Expand Down
19 changes: 0 additions & 19 deletions main.js

This file was deleted.

45 changes: 0 additions & 45 deletions main.sh

This file was deleted.

0 comments on commit 565e779

Please sign in to comment.