diff --git a/.github/actions/check-go-license-boilerplate/action.yaml b/.github/actions/check-go-license-boilerplate/action.yaml new file mode 100644 index 0000000..8b16f92 --- /dev/null +++ b/.github/actions/check-go-license-boilerplate/action.yaml @@ -0,0 +1,42 @@ +name: Check Go license boilerplate +description: Check license boilerplate used in Go files +inputs: + boilerplate-path: + description: License boilerplate file path + required: true + boilerplate-content: + description: License boilerplate content + default: |- + /* + SPDX-FileCopyrightText: ${YEAR} SAP SE or an SAP affiliate company and ${REPOSITORY} contributors + SPDX-License-Identifier: Apache-2.0 + */ +runs: + using: composite + steps: + - name: Check boilerplate file + shell: bash + env: + INPUT_BOILERPLATE_PATH: ${{ inputs.boilerplate-path }} + INPUT_BOILERPLATE_CONTENT: ${{ inputs.boilerplate-content }} + run: | + this_year=$(date +%Y) + last_year=$((this_year-1)) + repository=$(echo $GITHUB_REPOSITORY | cut -d/ -f2) + + tempdir=$(mktemp -d) + trap 'rm -rf $tempdir' EXIT + + printenv INPUT_BOILERPLATE_CONTENT | YEAR=$this_year REPOSITORY=$repository envsubst > $tempdir/boilerplate-this-year + printenv INPUT_BOILERPLATE_CONTENT | YEAR=$last_year REPOSITORY=$repository envsubst > $tempdir/boilerplate-last-year + + if diff -q $INPUT_BOILERPLATE_PATH $tempdir/boilerplate-this-year >/dev/null; then + exit 0 + fi + if diff -q $INPUT_BOILERPLATE_PATH $tempdir/boilerplate-last-year >/dev/null; then + >&1 echo "Warning: license boilerplate outdated ($last_year); next year, this will result in an error." + exit 0 + fi + + >&1 echo "Error: incorrect license boilerplate." + exit 1 diff --git a/.github/actions/check-go-license-headers/action.yaml b/.github/actions/check-go-license-headers/action.yaml new file mode 100644 index 0000000..6d8db51 --- /dev/null +++ b/.github/actions/check-go-license-headers/action.yaml @@ -0,0 +1,45 @@ +name: Check Go license headers +description: Check license headers of Go files +inputs: + base-path: + description: Base directory + default: . + boilerplate-path: + description: License header file path + required: true +runs: + using: composite + steps: + - name: Check files + shell: ruby {0} + env: + INPUT_BASE_PATH: ${{ inputs.base-path }} + INPUT_BOILERPLATE_PATH: ${{ inputs.boilerplate-path }} + run: | + base_path = ENV["INPUT_BASE_PATH"] + raise "Input parameter base-path must not start with slash" if base_path.start_with?("/") + raise "Input parameter base-path must not be empty" if base_path.empty? + raise "Specified base-path does not exist: #{base_path}" if !Dir.exists?(base_path) + + boilerplate_path = ENV["INPUT_BOILERPLATE_PATH"] + raise "Input parameter boilerplate-path must not start with slash" if boilerplate_path.start_with?("/") + raise "Input parameter boilerplate-path must not be empty" if boilerplate_path.empty? + + boilerplate = File.readlines(boilerplate_path) + errors = 0 + + Dir.glob("**/*.go").each do |p| + file = File.readlines(p) + file.each_with_index do |line,i| + next if line =~ /^\/\/go:build/ + next if line =~ /^\/\/\s*\+build/ + next if line =~ /^\s*$/ + if file[i,boilerplate.size] != boilerplate then + STDERR.puts "#{p}: bad or missing license header" + errors += 1 + end + break + end + end + + exit 1 if errors > 0 \ No newline at end of file diff --git a/.github/actions/get-highest-tag/action.yaml b/.github/actions/get-highest-tag/action.yaml index 20147c4..bc526ad 100644 --- a/.github/actions/get-highest-tag/action.yaml +++ b/.github/actions/get-highest-tag/action.yaml @@ -3,6 +3,7 @@ description: Get highest semver tag in current repository inputs: prefix: description: Tag prefix (only tags with that prefix are considered) + default: '' outputs: tag: description: Highest tag (according to semver ordering) diff --git a/.github/actions/setup-helm-docs/action.yaml b/.github/actions/setup-helm-docs/action.yaml index 1c00296..1d17601 100644 --- a/.github/actions/setup-helm-docs/action.yaml +++ b/.github/actions/setup-helm-docs/action.yaml @@ -3,55 +3,53 @@ description: Setup helm-docs inputs: version: description: Version - required: true default: latest install-directory: description: Target installation directory - required: false default: '$HOME/.helm-docs/bin' outputs: path: description: Path to the installed helm-docs executable value: ${{ steps.install.outputs.path }} runs: - using: "composite" + using: composite steps: - - name: Install helm-docs - id: install - shell: bash - run: | - version=${{ inputs.version}} - install_directory=${{ inputs.install-directory }} - if [ "$version" == latest ]; then - version=$(curl -sSf https://api.github.com/repos/norwoodj/helm-docs/releases/latest | jq -r .tag_name) - fi - version=${version/#v/} - case $(uname -s) in - Linux) - os=Linux - ;; - *) - >&1 echo "Unsupported OS: $(uname -s)" - exit 1 - ;; - esac - case $(uname -m) in - arm64|aarch64) - arch=arm64 - ;; - x86_64|amd64) - arch=x86_64 - ;; - *) - >&1 echo "§Unsupported architecture: $(uname -m)" - exit 1 - ;; - esac - mkdir -p "$install_directory" - temp_directory=$(mktemp -d) - trap 'rm -rf $temp_directory' EXIT - curl -sSfL https://github.com/norwoodj/helm-docs/releases/download/v${version}/helm-docs_${version}_${os}_${arch}.tar.gz | tar xz -C $temp_directory - cp -f $temp_directory/helm-docs $install_directory - chmod a+x "$install_directory/helm-docs" - echo "$install_directory" >> $GITHUB_PATH - echo "path=$install_directory/helm-docs" >> $GITHUB_OUTPUT \ No newline at end of file + - name: Install helm-docs + id: install + shell: bash + run: | + version=${{ inputs.version}} + install_directory=${{ inputs.install-directory }} + if [ "$version" == latest ]; then + version=$(curl -sSf https://api.github.com/repos/norwoodj/helm-docs/releases/latest | jq -r .tag_name) + fi + version=${version/#v/} + case $(uname -s) in + Linux) + os=Linux + ;; + *) + >&1 echo "Unsupported OS: $(uname -s)" + exit 1 + ;; + esac + case $(uname -m) in + arm64|aarch64) + arch=arm64 + ;; + x86_64|amd64) + arch=x86_64 + ;; + *) + >&1 echo "§Unsupported architecture: $(uname -m)" + exit 1 + ;; + esac + mkdir -p "$install_directory" + temp_directory=$(mktemp -d) + trap 'rm -rf $temp_directory' EXIT + curl -sSfL https://github.com/norwoodj/helm-docs/releases/download/v${version}/helm-docs_${version}_${os}_${arch}.tar.gz | tar xz -C $temp_directory + cp -f $temp_directory/helm-docs $install_directory + chmod a+x "$install_directory/helm-docs" + echo "$install_directory" >> $GITHUB_PATH + echo "path=$install_directory/helm-docs" >> $GITHUB_OUTPUT \ No newline at end of file diff --git a/.github/actions/setup-semver/action.yaml b/.github/actions/setup-semver/action.yaml index 129d769..8daae9a 100644 --- a/.github/actions/setup-semver/action.yaml +++ b/.github/actions/setup-semver/action.yaml @@ -3,30 +3,28 @@ description: Setup semver inputs: version: description: Version - required: true default: latest install-directory: description: Target installation directory - required: false default: '$HOME/.semver/bin' outputs: path: description: Path to the installed semver executable value: ${{ steps.install.outputs.path }} runs: - using: "composite" + using: composite steps: - - name: Install semver - id: install - shell: bash - run: | - version=${{ inputs.version}} - install_directory=${{ inputs.install-directory }} - if [ "$version" == latest ]; then - version=master - fi - mkdir -p "$install_directory" - curl -sSf -L -o "$install_directory/semver" https://raw.githubusercontent.com/fsaintjacques/semver-tool/$version/src/semver - chmod a+x "$install_directory/semver" - echo "$install_directory" >> $GITHUB_PATH - echo "path=$install_directory/semver" >> $GITHUB_OUTPUT \ No newline at end of file + - name: Install semver + id: install + shell: bash + run: | + version=${{ inputs.version}} + install_directory=${{ inputs.install-directory }} + if [ "$version" == latest ]; then + version=master + fi + mkdir -p "$install_directory" + curl -sSf -L -o "$install_directory/semver" https://raw.githubusercontent.com/fsaintjacques/semver-tool/$version/src/semver + chmod a+x "$install_directory/semver" + echo "$install_directory" >> $GITHUB_PATH + echo "path=$install_directory/semver" >> $GITHUB_OUTPUT \ No newline at end of file