Skip to content

Commit

Permalink
Merge pull request #2 from Updater/update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
acobaugh authored Feb 8, 2024
2 parents 67e7ccb + bc5b23c commit 41c8f8c
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 44 deletions.
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 10
groups:
actions:
update-types:
- "minor"
- "patch"
17 changes: 9 additions & 8 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
name: test-chart-testing-action

on: [pull_request]
on:
pull_request:

jobs:
test_ct_action:
runs-on: ubuntu-latest

name: Install chart-testing and test presence in path
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install chart-testing
uses: ./
- name: Check install!
run: |
ct version
CT_VERSION_OUTPUT=$(ct version 2>&1 /dev/null)
ACTUAL_VERSION=$(echo "$CT_VERSION_OUTPUT" | grep Version | rev | cut -d ' ' -f1 | rev)
if [[ $ACTUAL_VERSION != 'v3.7.1' ]]; then
echo 'should be v3.7.1'
if [[ $ACTUAL_VERSION != 'v3.10.1' ]]; then
echo 'should be v3.10.1'
exit 1
else
exit 0
Expand All @@ -37,20 +38,20 @@ jobs:

name: Install Custom chart-testing and test presence in path
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install chart-testing
uses: ./
with:
version: 'v3.5.1'
version: 'v3.8.0'
yamllint_version: '1.27.1'
yamale_version: '3.0.4'
- name: Check install!
run: |
ct version
CT_VERSION_OUTPUT=$(ct version 2>&1 /dev/null)
ACTUAL_VERSION=$(echo "$CT_VERSION_OUTPUT" | grep Version | rev | cut -d ' ' -f1 | rev)
if [[ $ACTUAL_VERSION != 'v3.5.1' ]]; then
echo 'should be v3.5.1'
if [[ $ACTUAL_VERSION != 'v3.8.0' ]]; then
echo 'should be v3.8.0'
exit 1
else
exit 0
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A GitHub Action for installing the [helm/chart-testing](https://github.com/helm/

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

- `version`: The chart-testing version to install (default: `v3.7.1`)
- `version`: The chart-testing version to install (default: `3.9.0`)
- `yamllint_version`: The chart-testing version to install (default: `1.27.1`)
- `yamale_version`: The chart-testing version to install (default: `3.0.4`)

Expand All @@ -37,40 +37,42 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.10.0
version: v3.12.1

- uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: '3.10'
check-latest: true

- name: Set up chart-testing
uses: helm/chart-testing-action@v2.3.1
uses: helm/chart-testing-action@v2.6.0

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }})
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Run chart-testing (lint)
if: steps.list-changed.outputs.changed == 'true'
run: ct lint --target-branch ${{ github.event.repository.default_branch }}

- name: Create kind cluster
uses: helm/kind-action@v1.4.0
if: steps.list-changed.outputs.changed == 'true'
uses: helm/kind-action@v1.8.0

- name: Run chart-testing (install)
run: ct install
if: steps.list-changed.outputs.changed == 'true'
run: ct install --target-branch ${{ github.event.repository.default_branch }}
```
This uses [`helm/kind-action`](https://www.github.com/helm/kind-action) GitHub Action to spin up a [kind](https://kind.sigs.k8s.io/) Kubernetes cluster,
Expand Down
7 changes: 4 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ branding:
icon: anchor
inputs:
version:
description: "The chart-testing version to install (default: v3.7.1)"
description: "The chart-testing version to install (default: 3.10.1)"
required: false
default: v3.7.1
default: '3.10.1'
yamllint_version:
description: "The yamllint version to install (default: 1.27.1)"
required: false
default: '1.27.1'
yamale_version:
description: "The yamale version to install (default: 3.0.4)"
description: "The yamale version to install (default: 3.0.4)"
required: false
default: '3.0.4'
runs:
using: composite
steps:
- uses: sigstore/cosign-installer@9614fae9e5c5eddabb09f90a270fcb487c9f7149 # v3.3.0
- run: |
cd $GITHUB_ACTION_PATH \
&& ./ct.sh \
Expand Down
66 changes: 41 additions & 25 deletions ct.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -o errexit
set -o nounset
set -o pipefail

DEFAULT_CHART_TESTING_VERSION=v3.7.1
DEFAULT_CHART_TESTING_VERSION=3.10.1
DEFAULT_YAMLLINT_VERSION=1.27.1
DEFAULT_YAMALE_VERSION=3.0.4

Expand All @@ -13,14 +13,14 @@ cat << EOF
Usage: $(basename "$0") <options>
-h, --help Display help
-v, --version The chart-testing version to use (default: $DEFAULT_CHART_TESTING_VERSION)"
-v, --version The chart-testing version to use (default: ${DEFAULT_CHART_TESTING_VERSION})"
EOF
}

main() {
local version="$DEFAULT_CHART_TESTING_VERSION"
local yamllint_version="$DEFAULT_YAMLLINT_VERSION"
local yamale_version="$DEFAULT_YAMALE_VERSION"
local version="${DEFAULT_CHART_TESTING_VERSION}"
local yamllint_version="${DEFAULT_YAMLLINT_VERSION}"
local yamale_version="${DEFAULT_YAMALE_VERSION}"

parse_command_line "$@"

Expand All @@ -36,7 +36,7 @@ parse_command_line() {
;;
-v|--version)
if [[ -n "${2:-}" ]]; then
version="$2"
version="${2#v}"
shift
else
echo "ERROR: '-v|--version' cannot be empty." >&2
Expand Down Expand Up @@ -74,30 +74,46 @@ parse_command_line() {
}

install_chart_testing() {
if [[ ! -d "$RUNNER_TOOL_CACHE" ]]; then
echo "Cache directory '$RUNNER_TOOL_CACHE' does not exist" >&2
if [[ ! -d "${RUNNER_TOOL_CACHE}" ]]; then
echo "Cache directory '${RUNNER_TOOL_CACHE}' does not exist" >&2
exit 1
fi

local arch
arch=$(uname -m)
local cache_dir="$RUNNER_TOOL_CACHE/ct/$version/$arch"
local venv_dir="$cache_dir/venv"

if [[ ! -d "$cache_dir" ]]; then
mkdir -p "$cache_dir"

echo "Installing chart-testing..."
curl -sSLo ct.tar.gz "https://github.com/helm/chart-testing/releases/download/$version/chart-testing_${version#v}_linux_amd64.tar.gz"
tar -xzf ct.tar.gz -C "$cache_dir"
if [[ $(uname -m) == "aarch64" ]]; then
arch=arm64
else
arch=amd64
fi
local cache_dir="${RUNNER_TOOL_CACHE}/ct/${version}/${arch}"
local venv_dir="${cache_dir}/venv"

if [[ ! -d "${cache_dir}" ]]; then
mkdir -p "${cache_dir}"

echo "Installing chart-testing v${version}..."
CT_CERT=https://github.com/helm/chart-testing/releases/download/v$version/chart-testing_${version#v}_linux_$arch.tar.gz.pem
CT_SIG=https://github.com/helm/chart-testing/releases/download/v$version/chart-testing_${version#v}_linux_$arch.tar.gz.sig

curl --retry 5 --retry-delay 1 -sSLo ct.tar.gz "https://github.com/helm/chart-testing/releases/download/v$version/chart-testing_${version#v}_linux_$arch.tar.gz"
cosign verify-blob --certificate $CT_CERT --signature $CT_SIG \
--certificate-identity "https://github.com/helm/chart-testing/.github/workflows/release.yaml@refs/heads/main" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" ct.tar.gz
retVal=$?
if [[ "${retVal}" -ne 0 ]]; then
log_error "Unable to validate chart-testing version: v${version}"
exit 1
fi

tar -xzf ct.tar.gz -C "${cache_dir}"
rm -f ct.tar.gz

echo 'Creating virtual Python environment...'
python3 -m venv "$venv_dir"
python3 -m venv "${venv_dir}"

echo 'Activating virtual environment...'
# shellcheck disable=SC1090
source "$venv_dir/bin/activate"
source "${venv_dir}/bin/activate"

echo 'Installing yamllint...'
pip3 install "yamllint==${yamllint_version}"
Expand All @@ -108,16 +124,16 @@ install_chart_testing() {

# https://github.com/helm/chart-testing-action/issues/62
echo 'Adding ct directory to PATH...'
echo "$cache_dir" >> "$GITHUB_PATH"
echo "${cache_dir}" >> "${GITHUB_PATH}"

echo 'Setting CT_CONFIG_DIR...'
echo "CT_CONFIG_DIR=$cache_dir/etc" >> "$GITHUB_ENV"
echo "CT_CONFIG_DIR=${cache_dir}/etc" >> "${GITHUB_ENV}"

echo 'Configuring environment variables for virtual environment for subsequent workflow steps...'
echo "VIRTUAL_ENV=$venv_dir" >> "$GITHUB_ENV"
echo "$venv_dir/bin" >> "$GITHUB_PATH"
echo "VIRTUAL_ENV=${venv_dir}" >> "${GITHUB_ENV}"
echo "${venv_dir}/bin" >> "${GITHUB_PATH}"

"$cache_dir/ct" version
"${cache_dir}/ct" version
}

main "$@"

0 comments on commit 41c8f8c

Please sign in to comment.