license-headers.yml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Copyright Broadcom, Inc. All Rights Reserved.
  2. # SPDX-License-Identifier: APACHE-2.0
  3. name: '[License] Check license headers'
  4. on:
  5. pull_request_target:
  6. types:
  7. - opened
  8. - synchronize
  9. branches:
  10. - main
  11. - bitnami:main
  12. # Remove all permissions by default
  13. permissions: {}
  14. jobs:
  15. license-headers-linter:
  16. runs-on: ubuntu-latest
  17. permissions:
  18. contents: read
  19. pull-requests: write
  20. steps:
  21. - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
  22. name: Checkout Repository
  23. with:
  24. ref: ${{ github.event.pull_request.head.ref }}
  25. repository: ${{ github.event.pull_request.head.repo.full_name }}
  26. - id: get-modified-files
  27. name: 'Get modified files'
  28. env:
  29. DIFF_URL: "${{github.event.pull_request.diff_url}}"
  30. TEMP_FILE: "${{runner.temp}}/pr-${{github.event.number}}.diff"
  31. run: |
  32. # This request doesn't consume API calls.
  33. curl -Lkso $TEMP_FILE $DIFF_URL
  34. files_changed="$(sed -nr 's/[\-\+]{3} [ab]\/(.*)/\1/p' $TEMP_FILE | sort | uniq)"
  35. templates=()
  36. regular_files=()
  37. is_excluded() {
  38. # Check if a given path contains one of the excluded paths
  39. local -r path="${1:?missing path}"
  40. local -r excluded_paths=("/crds/")
  41. for excluded_path in "${excluded_paths[@]}"; do
  42. if [[ "${path}" =~ ${excluded_path} ]]; then
  43. return 0
  44. fi
  45. done
  46. return 1
  47. }
  48. while read -r file_changed; do
  49. # Avoid removed files and excluded files
  50. if [[ -f "${file_changed}" ]] && ! is_excluded "${file_changed}"; then
  51. if [[ "${file_changed}" =~ \/templates\/ ]]; then
  52. templates+=("${file_changed}")
  53. else
  54. regular_files+=("${file_changed}")
  55. fi
  56. fi
  57. done <<< "$(echo "$files_changed" | grep -oE "^bitnami/.*\.ya?ml$" | sort | uniq || true)"
  58. if [[ ${#templates[@]} -gt 0 ]] || [[ ${#regular_files[@]} -gt 0 ]]; then
  59. if [[ ${#templates[@]} -gt 0 ]]; then
  60. # There are modifications over yaml templates
  61. export templates_json=$(printf "%s\n" "${templates[@]}" | jq -R . | jq -cs .)
  62. # Overwrite configuration file to analyze only changed templates
  63. yq -i '. | .header[0].paths=env(templates_json)' .licenserc.yaml
  64. fi
  65. if [[ ${#regular_files[@]} -gt 0 ]]; then
  66. # There are modifications over yaml files
  67. export regular_files_json=$(printf "%s\n" "${regular_files[@]}" | jq -R . | jq -cs .)
  68. # Overwrite configuration file to analyze only changed files
  69. yq -i '. | .header[1].paths=env(regular_files_json)' .licenserc.yaml
  70. fi
  71. echo "result=success" >> $GITHUB_OUTPUT
  72. else
  73. echo "result=skip" >> $GITHUB_OUTPUT
  74. fi
  75. - name: Check license Headers
  76. uses: apache/skywalking-eyes/header@5c5b974209f0de5d905f37deb69369068ebfc15c
  77. if: ${{ steps.get-modified-files.outputs.result == 'success' }}