forked from bitnami/charts
-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (67 loc) · 2.6 KB
/
license-headers.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright VMware, Inc.
# SPDX-License-Identifier: APACHE-2.0
---
name: '[License] Check license headers'
on:
pull_request_target:
types:
- opened
- synchronize
branches:
- main
- bitnami:main
# Remove all permissions by default
permissions: {}
jobs:
license-headers-linter:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v3
name: Checkout Repository
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- id: get-modified-files
name: 'Get modified files'
env:
DIFF_URL: "${{github.event.pull_request.diff_url}}"
TEMP_FILE: "${{runner.temp}}/pr-${{github.event.number}}.diff"
run: |
# This request doesn't consume API calls.
curl -Lkso $TEMP_FILE $DIFF_URL
files_changed="$(sed -nr 's/[\-\+]{3} [ab]\/(.*)/\1/p' $TEMP_FILE | sort | uniq)"
templates=()
regular_files=()
while read -r file_changed; do
# Avoid removed files
if [[ -f "${file_changed}" ]]; then
if [[ "${file_changed}" =~ \/templates\/ ]]; then
templates+=("${file_changed}")
else
regular_files+=("${file_changed}")
fi
fi
done <<< "$(echo "$files_changed" | grep -oE "^bitnami/.*\.ya?ml$" | sort | uniq || true)"
if [[ ${#templates[@]} -gt 0 ]] || [[ ${#regular_files[@]} -gt 0 ]]; then
if [[ ${#templates[@]} -gt 0 ]]; then
# There are modifications over yaml tamplates
export tamplates_json=$(printf "%s\n" "${templates[@]}" | jq -R . | jq -cs .)
# Overwrite configuration file to analyze only changed templates
yq -i '. | .header[0].paths=env(tamplates_json)' .licenserc.yaml
fi
if [[ ${#regular_files[@]} -gt 0 ]]; then
# There are modifications over yaml files
export regular_files_json=$(printf "%s\n" "${regular_files[@]}" | jq -R . | jq -cs .)
# Overwrite configuration file to analyze only changed files
yq -i '. | .header[1].paths=env(regular_files_json)' .licenserc.yaml
fi
echo "result=success" >> $GITHUB_OUTPUT
else
echo "result=skip" >> $GITHUB_OUTPUT
fi
- name: Check license Headers
uses: apache/skywalking-eyes/[email protected]
if: ${{ steps.get-modified-files.outputs.result == 'success' }}