From fd71b46b1a9c80edeccc82205a044520daea04f5 Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 20 Oct 2022 04:34:22 +0800 Subject: [PATCH] Replace handmade lint script with official action (#292) * replace homemade release script with official action Signed-off-by: tison * bundle helm/chart-releaser-action Signed-off-by: tison * update .asf.yaml Signed-off-by: tison * fix helm/chart-testing-action is not allowed Signed-off-by: tison * try azure/setup-helm is allowed Signed-off-by: tison * Revert "try azure/setup-helm is allowed" This reverts commit 7ee6fc0b3d4584127568fe607732b9c3aa70f031. * replace handmade lint script with official action Signed-off-by: tison Signed-off-by: tison --- .asf.yaml | 6 - .ci/ct.sh | 166 ------------------ .ci/git.sh | 35 ---- .ci/helm.sh | 8 +- .ci/lint.sh | 26 --- .../actions/chart-testing-action/README.md | 3 + .../actions/chart-testing-action/action.yml | 60 +++++++ .github/actions/chart-testing-action/ct.sh | 153 ++++++++++++++++ .github/workflows/lint.yml | 26 ++- 9 files changed, 239 insertions(+), 244 deletions(-) delete mode 100755 .ci/ct.sh delete mode 100644 .ci/git.sh delete mode 100755 .ci/lint.sh create mode 100644 .github/actions/chart-testing-action/README.md create mode 100644 .github/actions/chart-testing-action/action.yml create mode 100755 .github/actions/chart-testing-action/ct.sh diff --git a/.asf.yaml b/.asf.yaml index f24997c..b778af8 100644 --- a/.asf.yaml +++ b/.asf.yaml @@ -31,18 +31,12 @@ github: - helm - helm-chart features: - # Enable wiki for documentation wiki: true - # Enable issues management issues: true - # Enable projects for project management boards projects: true enabled_merge_buttons: - # enable squash button: squash: true - # disable merge button: merge: false - # disable rebase button: rebase: false notifications: diff --git a/.ci/ct.sh b/.ci/ct.sh deleted file mode 100755 index 51a684f..0000000 --- a/.ci/ct.sh +++ /dev/null @@ -1,166 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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 -# -# http://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 - -DEFAULT_IMAGE=quay.io/helmpack/chart-testing:v3.0.0 - -show_help() { -cat << EOF -Usage: $(basename "$0") - -h, --help Display help - -i, --image The chart-testing Docker image to use (default: quay.io/helmpack/chart-testing:v2.4.0) - -c, --command The chart-testing command to run - --config The path to the chart-testing config file - --kubeconfig The path to the kube config file -EOF -} - -main() { - local image="$DEFAULT_IMAGE" - local config= - local command= - local kubeconfig="$HOME/.kube/config" - - parse_command_line "$@" - - if [[ -z "$command" ]]; then - echo "ERROR: '-c|--command' is required." >&2 - show_help - exit 1 - fi - - run_ct_container - trap cleanup EXIT - - local changed - changed=$(docker_exec ct list-changed) - if [[ -z "$changed" ]]; then - echo 'No chart changes detected.' - echo "::set-output name=changed::false" - return - fi - - # Convenience output for other actions to make use of ct config to check if - # charts changed. - echo "::set-output name=changed::true" - - # All other ct commands require a cluster to be created in a previous step. - if [[ "$command" != "lint" ]] && [[ "$command" != "list-changed" ]]; then - configure_kube - fi - - run_ct -} - -parse_command_line() { - while :; do - case "${1:-}" in - -h|--help) - show_help - exit - ;; - -i|--image) - if [[ -n "${2:-}" ]]; then - image="$2" - shift - else - echo "ERROR: '-i|--image' cannot be empty." >&2 - show_help - exit 1 - fi - ;; - -c|--command) - if [[ -n "${2:-}" ]]; then - command="$2" - shift - else - echo "ERROR: '-c|--command' cannot be empty." >&2 - show_help - exit 1 - fi - ;; - --config) - if [[ -n "${2:-}" ]]; then - config="$2" - shift - else - echo "ERROR: '--config' cannot be empty." >&2 - show_help - exit 1 - fi - ;; - --kubeconfig) - if [[ -n "${2:-}" ]]; then - kubeconfig="$2" - shift - else - echo "ERROR: '--kubeconfig' cannot be empty." >&2 - show_help - exit 1 - fi - ;; - *) - break - ;; - esac - - shift - done -} - -run_ct_container() { - echo 'Running ct container...' - local args=(run --rm --interactive --detach --network host --name ct "--volume=$(pwd):/workdir" "--workdir=/workdir") - - if [[ -n "$config" ]]; then - args+=("--volume=$(pwd)/$config:/etc/ct/ct.yaml" ) - fi - - args+=("$image" cat) - - docker "${args[@]}" - echo -} - -configure_kube() { - docker_exec sh -c 'mkdir -p /root/.kube' - docker cp "$kubeconfig" ct:/root/.kube/config -} - -run_ct() { - echo "Running 'ct $command'..." - docker_exec ct "$command" - echo -} - -cleanup() { - echo 'Removing ct container...' - docker kill ct > /dev/null 2>&1 - echo 'Done!' -} - -docker_exec() { - docker exec --interactive ct "$@" -} - -main "$@" diff --git a/.ci/git.sh b/.ci/git.sh deleted file mode 100644 index f888b7a..0000000 --- a/.ci/git.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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 -# -# http://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. -# - -function git::fetch_tags() { - echo "Fetching tags ..." - git fetch --tags -} - -function git::find_latest_tag() { - if ! git describe --tags --abbrev=0 2> /dev/null; then - git rev-list --max-parents=0 --first-parent HEAD - fi -} - -function git::get_revision() { - local tag=$1 - echo "$(git rev-parse --verify ${tag})" -} diff --git a/.ci/helm.sh b/.ci/helm.sh index a59ded8..79fb8e7 100644 --- a/.ci/helm.sh +++ b/.ci/helm.sh @@ -177,23 +177,23 @@ function ci::test_pulsar_producer() { } function ci::wait_function_running() { - num_running=$(${KUBECTL} exec -n ${NAMESPACE} ${CLUSTER}-toolset-0 -- bash -c 'bin/pulsar-admin functions status --tenant pulsar-ci --namespace test --name test-function | bin/jq .numRunning') + num_running=$(${KUBECTL} exec -n ${NAMESPACE} ${CLUSTER}-toolset-0 -- bash -c 'bin/pulsar-admin functions status --tenant pulsar-ci --namespace test --name test-function | bin/jq .numRunning') while [[ ${num_running} -lt 1 ]]; do echo ${num_running} sleep 15 ${KUBECTL} get pods -n ${NAMESPACE} --field-selector=status.phase=Running ${KUBECTL} get events --sort-by=.lastTimestamp -A | tail -n 30 || true - num_running=$(${KUBECTL} exec -n ${NAMESPACE} ${CLUSTER}-toolset-0 -- bash -c 'bin/pulsar-admin functions status --tenant pulsar-ci --namespace test --name test-function | bin/jq .numRunning') + num_running=$(${KUBECTL} exec -n ${NAMESPACE} ${CLUSTER}-toolset-0 -- bash -c 'bin/pulsar-admin functions status --tenant pulsar-ci --namespace test --name test-function | bin/jq .numRunning') done } function ci::wait_message_processed() { - num_processed=$(${KUBECTL} exec -n ${NAMESPACE} ${CLUSTER}-toolset-0 -- bash -c 'bin/pulsar-admin functions stats --tenant pulsar-ci --namespace test --name test-function | bin/jq .processedSuccessfullyTotal') + num_processed=$(${KUBECTL} exec -n ${NAMESPACE} ${CLUSTER}-toolset-0 -- bash -c 'bin/pulsar-admin functions stats --tenant pulsar-ci --namespace test --name test-function | bin/jq .processedSuccessfullyTotal') while [[ ${num_processed} -lt 1 ]]; do echo ${num_processed} sleep 15 ${KUBECTL} exec -n ${NAMESPACE} ${CLUSTER}-toolset-0 -- bin/pulsar-admin functions stats --tenant pulsar-ci --namespace test --name test-function - num_processed=$(${KUBECTL} exec -n ${NAMESPACE} ${CLUSTER}-toolset-0 -- bash -c 'bin/pulsar-admin functions stats --tenant pulsar-ci --namespace test --name test-function | bin/jq .processedSuccessfullyTotal') + num_processed=$(${KUBECTL} exec -n ${NAMESPACE} ${CLUSTER}-toolset-0 -- bash -c 'bin/pulsar-admin functions stats --tenant pulsar-ci --namespace test --name test-function | bin/jq .processedSuccessfullyTotal') done } diff --git a/.ci/lint.sh b/.ci/lint.sh deleted file mode 100755 index c4390fc..0000000 --- a/.ci/lint.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you 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 -# -# http://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 -e - -BINDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" -CI_HOME="${BINDIR}" - -${CI_HOME}/ct.sh -c lint diff --git a/.github/actions/chart-testing-action/README.md b/.github/actions/chart-testing-action/README.md new file mode 100644 index 0000000..4bf2d40 --- /dev/null +++ b/.github/actions/chart-testing-action/README.md @@ -0,0 +1,3 @@ +# chart-testing Action + +This action is an identical fork of [helm/chart-testing-action@v3.7.1](https://github.com/helm/chart-testing-action). diff --git a/.github/actions/chart-testing-action/action.yml b/.github/actions/chart-testing-action/action.yml new file mode 100644 index 0000000..6310dcd --- /dev/null +++ b/.github/actions/chart-testing-action/action.yml @@ -0,0 +1,60 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. + +# 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. + +name: "Helm Chart Testing" +description: "Install the Helm chart-testing tool" +author: "The Helm authors" +branding: + color: blue + icon: anchor +inputs: + version: + description: "The chart-testing version to install (default: v3.7.1)" + required: false + default: v3.7.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)" + required: false + default: '3.0.4' +runs: + using: composite + steps: + - run: | + cd $GITHUB_ACTION_PATH \ + && ./ct.sh \ + --version ${{ inputs.version }} \ + --yamllint-version ${{ inputs.yamllint_version }} \ + --yamale-version ${{ inputs.yamale_version }} + shell: bash diff --git a/.github/actions/chart-testing-action/ct.sh b/.github/actions/chart-testing-action/ct.sh new file mode 100755 index 0000000..e07b1be --- /dev/null +++ b/.github/actions/chart-testing-action/ct.sh @@ -0,0 +1,153 @@ +#!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. + +# 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 + +DEFAULT_CHART_TESTING_VERSION=v3.7.1 +DEFAULT_YAMLLINT_VERSION=1.27.1 +DEFAULT_YAMALE_VERSION=3.0.4 + +show_help() { +cat << EOF +Usage: $(basename "$0") + -h, --help Display help + -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" + + parse_command_line "$@" + + install_chart_testing +} + +parse_command_line() { + while :; do + case "${1:-}" in + -h|--help) + show_help + exit + ;; + -v|--version) + if [[ -n "${2:-}" ]]; then + version="$2" + shift + else + echo "ERROR: '-v|--version' cannot be empty." >&2 + show_help + exit 1 + fi + ;; + --yamllint-version) + if [[ -n "${2:-}" ]]; then + yamllint_version="$2" + shift + else + echo "ERROR: '--yamllint-version' cannot be empty." >&2 + show_help + exit 1 + fi + ;; + --yamale-version) + if [[ -n "${2:-}" ]]; then + yamale_version="$2" + shift + else + echo "ERROR: '--yamale-version' cannot be empty." >&2 + show_help + exit 1 + fi + ;; + *) + break + ;; + esac + + shift + done +} + +install_chart_testing() { + 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" + rm -f ct.tar.gz + + echo 'Creating virtual Python environment...' + python3 -m venv "$venv_dir" + + echo 'Activating virtual environment...' + # shellcheck disable=SC1090 + source "$venv_dir/bin/activate" + + echo 'Installing yamllint...' + pip3 install "yamllint==${yamllint_version}" + + echo 'Installing Yamale...' + pip3 install "yamale==${yamale_version}" + fi + + # https://github.com/helm/chart-testing-action/issues/62 + echo 'Adding ct directory to PATH...' + echo "$cache_dir" >> "$GITHUB_PATH" + + echo 'Setting CT_CONFIG_DIR...' + 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" + + "$cache_dir/ct" version +} + +main "$@" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b3f56fe..b5020bb 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -29,9 +29,8 @@ jobs: steps: - name: checkout uses: actions/checkout@v2 - - - name: Tune Runner VM - uses: ./.github/actions/tune-runner-vm + with: + fetch-depth: 0 - name: Detect changed files id: changes @@ -43,9 +42,22 @@ jobs: id: check_changes run: echo "::set-output name=docs_only::${{ fromJSON(steps.changes.outputs.all_count) == fromJSON(steps.changes.outputs.docs_count) && fromJSON(steps.changes.outputs.docs_count) > 0 }}" - - name: Lint chart + - name: Set up Helm if: ${{ steps.check_changes.outputs.docs_only != 'true' }} - id: lint - uses: helm/chart-testing-action@v2.0.0 + uses: azure/setup-helm@v3 with: - command: lint + version: v3.10.0 + + - name: Set up Python + if: ${{ steps.check_changes.outputs.docs_only != 'true' }} + uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Set up chart-testing + if: ${{ steps.check_changes.outputs.docs_only != 'true' }} + uses: ./.github/actions/chart-testing-action + + - name: Run chart-testing (lint) + if: ${{ steps.check_changes.outputs.docs_only != 'true' }} + run: ct lint --target-branch ${{ github.event.repository.default_branch }}