Skip to content

fix: upgrade workspace status condition correctly #1555

fix: upgrade workspace status condition correctly

fix: upgrade workspace status condition correctly #1555

Workflow file for this run

name: License Header
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
on:
pull_request:
branches:
- main
permissions:
contents: read
jobs:
check:
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- language: Go
extension: '*.go'
boilerplate_file: 'hack/boilerplate.go.txt'
ignore_pattern: '*/*.deepcopy.go'
- language: Python
extension: '*.py'
boilerplate_file: 'hack/boilerplate.python.txt'
steps:
- name: Harden Runner
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
with:
egress-policy: audit
disable-sudo: true
disable-telemetry: true
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
submodules: true
fetch-depth: 0
- name: Check ${{ matrix.language }} file headers
run: |
boilerplate_file="${{ matrix.boilerplate_file }}"
extension="${{ matrix.extension }}"
ignore_pattern="${{ matrix.ignore_pattern }}"
boilerplate_content=$(cat "$boilerplate_file")
boilerplate_lines=$(awk 'END{print NR}' "$boilerplate_file")
boilerplate_content=$(cat "$boilerplate_file")
boilerplate_lines=$(grep -c '^' "$boilerplate_file")
find_cmd="find . -type f -name '$extension'"
if [ -n "$ignore_pattern" ]; then
find_cmd="$find_cmd -not -path '$ignore_pattern'"
fi
# Find all relevant files
mapfile -t files < <(eval $find_cmd)
exit_code=0
for file in "${files[@]}"; do
# Get the header of the current file
header=$(head -n "$boilerplate_lines" "$file")
# Compare header with boilerplate
if [ "$header" != "$boilerplate_content" ]; then
echo "::error file=$file::File '$file' is missing or has an incorrect boilerplate header."
exit_code=1
fi
done
if [ $exit_code -ne 0 ]; then
echo "Please add the content of '$boilerplate_file' to the beginning of the listed files."
else
echo "Boilerplate check passed for all ${{ matrix.language }} files."
fi
exit $exit_code