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 <unguiculus@gmail.com>
This commit is contained in:
Reinhard Nägele
2020-11-04 21:04:47 +01:00
committed by GitHub
parent 7e3f32e98a
commit 565e7795ce
5 changed files with 52 additions and 76 deletions
+7 -2
View File
@@ -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) 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 - `config`: Optional config file for chart-releaser
- `charts_dir`: The charts directory - `charts_dir`: The charts directory
- `charts_repo_url`: The GitHub Pages URL to the charts repo (default: `https://<owner>.github.io/<project>`) - `charts_repo_url`: The GitHub Pages URL to the charts repo (default: `https://<owner>.github.io/<project>`)
@@ -46,8 +46,13 @@ jobs:
git config user.name "$GITHUB_ACTOR" git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com" 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 - name: Run chart-releaser
uses: helm/chart-releaser-action@v1.0.0 uses: helm/chart-releaser-action@v1.1.1
env: env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
``` ```
+24 -4
View File
@@ -6,7 +6,7 @@ branding:
icon: anchor icon: anchor
inputs: inputs:
version: version:
description: "The chart-releaser version to use (default: v1.0.0)" description: "The chart-releaser version to use (default: v1.1.1)"
config: config:
description: "The relative path to the chart-releaser config file" description: "The relative path to the chart-releaser config file"
charts_dir: charts_dir:
@@ -14,7 +14,27 @@ inputs:
default: charts default: charts
charts_repo_url: charts_repo_url:
description: "The GitHub Pages URL to the charts repo (default: https://<owner>.github.io/<repo>)" description: "The GitHub Pages URL to the charts repo (default: https://<owner>.github.io/<repo>)"
required: true
runs: runs:
using: "node12" using: composite
main: "main.js" 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
+21 -6
View File
@@ -18,7 +18,7 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
DEFAULT_CHART_RELEASER_VERSION=v1.1.0 DEFAULT_CHART_RELEASER_VERSION=v1.1.1
show_help() { show_help() {
cat << EOF cat << EOF
@@ -177,11 +177,26 @@ parse_command_line() {
} }
install_chart_releaser() { 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
curl -sSLo cr.tar.gz "https://github.com/helm/chart-releaser/releases/download/$version/chart-releaser_${version#v}_linux_amd64.tar.gz" local arch
tar -xzf cr.tar.gz arch=$(uname -m)
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() { lookup_latest_tag() {
@@ -219,7 +234,7 @@ lookup_changed_charts() {
package_chart() { package_chart() {
local chart="$1" local chart="$1"
local args=(--package-path .cr-release-packages) local args=("$chart" --package-path .cr-release-packages)
if [[ -n "$config" ]]; then if [[ -n "$config" ]]; then
args+=(--config "$config") args+=(--config "$config")
fi fi
-19
View File
@@ -1,19 +0,0 @@
// Copyright The Helm Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// # You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// # See the License for the specific language governing permissions and
// limitations under the License.
const spawnSync = require('child_process').spawnSync;
const path = require("path");
const proc = spawnSync('bash', [path.join(__dirname, 'main.sh')], {stdio: 'inherit'});
process.exit(proc.status)
-45
View File
@@ -1,45 +0,0 @@
#!/usr/bin/env bash
# Copyright The Helm Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
SCRIPT_DIR=$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}" || realpath "${BASH_SOURCE[0]}")")
main() {
owner=$(cut -d '/' -f 1 <<< "$GITHUB_REPOSITORY")
repo=$(cut -d '/' -f 2 <<< "$GITHUB_REPOSITORY")
args=(--owner "$owner" --repo "$repo")
args+=(--charts-dir "${INPUT_CHARTS_DIR?Input 'charts_dir' is required}")
if [[ -n "${INPUT_VERSION:-}" ]]; then
args+=(--version "${INPUT_VERSION}")
fi
if [[ -n "${INPUT_CONFIG:-}" ]]; then
args+=(--config "${INPUT_CONFIG}")
fi
if [[ -n "${INPUT_CHARTS_REPO_URL:-}" ]]; then
args+=(--charts-repo-url "${INPUT_CHARTS_REPO_URL}")
fi
"$SCRIPT_DIR/cr.sh" "${args[@]}"
}
main