From e7353b8e2c11ff42952a573a8a41bca308ee80c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20N=C3=A4gele?= Date: Wed, 4 Nov 2020 18:58:55 +0100 Subject: [PATCH] Convert to composite action and use cache dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switch to composite action so we can get rid of Javascript and install cr to the cache location. Signed-off-by: Reinhard Nägele --- README.md | 9 +++++++-- action.yml | 28 ++++++++++++++++++++++++---- cr.sh | 27 +++++++++++++++++++++------ main.js | 19 ------------------- main.sh | 45 --------------------------------------------- 5 files changed, 52 insertions(+), 76 deletions(-) delete mode 100644 main.js delete mode 100755 main.sh diff --git a/README.md b/README.md index 10a2706..b1be4a1 100644 --- a/README.md +++ b/README.md @@ -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://.github.io/`) @@ -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 }}" ``` diff --git a/action.yml b/action.yml index d9b0c20..28064e7 100644 --- a/action.yml +++ b/action.yml @@ -6,7 +6,7 @@ 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: @@ -14,7 +14,27 @@ inputs: default: charts charts_repo_url: description: "The GitHub Pages URL to the charts repo (default: https://.github.io/)" - 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 diff --git a/cr.sh b/cr.sh index 23efb3b..4506624 100755 --- a/cr.sh +++ b/cr.sh @@ -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 @@ -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() { @@ -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 diff --git a/main.js b/main.js deleted file mode 100644 index d4bef59..0000000 --- a/main.js +++ /dev/null @@ -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) diff --git a/main.sh b/main.sh deleted file mode 100755 index 5ce9c2c..0000000 --- a/main.sh +++ /dev/null @@ -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