-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (100 loc) · 3.64 KB
/
Copy pathlicensesearch.yml
File metadata and controls
121 lines (100 loc) · 3.64 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: LicenseSearch
on:
workflow_call:
inputs:
commits:
required: true
type: string
outputs:
results:
description: "all results"
value: ${{ jobs.combine_results.outputs.results }}
filtered_results:
description: "actual found licenses"
value: ${{ jobs.combine_results.outputs.filtered_results }}
jobs:
check_commits:
if: ${{ inputs.commits != '' }}
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
value: ${{ fromJSON(inputs.commits) }}
outputs:
license_lines: ${{ steps.process-files.outputs.license_lines }}
steps:
- name: Store commit
id: store_commit
run: |
COMMIT=${{ matrix.value.id }}
echo "commit=$COMMIT" >> $GITHUB_OUTPUT
- name: Checkout commit and parent commit
uses: actions/checkout@v4
with:
fetch-depth: 2
ref: "${{ steps.store_commit.outputs.commit }}"
- name: Get changed files
id: changed-files
run: |
echo "Getting changed files"
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD | xargs)
for file in $CHANGED_FILES; do
echo "'$file' was changed"
done
echo "changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT
- name: Process changed files
id: process-files
run: |
LICENSE_LINES=''
for file in ${{ steps.changed-files.outputs.changed_files }}; do
echo "Processing '$file'..."
LICENSE_MATCH=$(cat $file | grep -Pzo '(<|")licensee("| )(\n|.)*?(("|<)key("|>)|("|<)signature("|>))(\n|.)*?(("|<)key("|>)|("|<)signature("|>))(\n|.)*?(}|</licensee>)' | xargs)
if [ -z "$LICENSE_MATCH" ]; then
echo "...no licenses found"
else
echo "license found!"
LICENSE_LINENO=$(cat $file | grep -Pno '(<|")licensee("| )')
LICENSE_LINE="<$file>
$LICENSE_LINENO
"
LICENSE_LINES="$LICENSE_LINES
$LICENSE_LINE"
fi
done
{
echo 'license_lines<<EOF'
echo "${LICENSE_LINES}"
echo EOF
} >> $GITHUB_OUTPUT
- name: Create json with result
run: |
jq -cn --arg commit ${{ steps.store_commit.outputs.commit }} --arg licenselines "${{ steps.process-files.outputs.license_lines }}" '$ARGS.named' > result
- name: Random Number Generator
id: random-number-generator
run: echo "random-number=$(echo $RANDOM)" >> $GITHUB_OUTPUT
shell: bash
- name: Upload result
uses: actions/upload-artifact@v4
with:
name: "result-${{ steps.random-number-generator.outputs.random-number }}"
path: result
combine_results:
needs: check_commits
runs-on: ubuntu-latest
continue-on-error: true
outputs:
results: ${{ steps.read_results.outputs.results }}
filtered_results: ${{ steps.filter_results.outputs.filtered_results }}
steps:
- name: Download results
uses: actions/download-artifact@v4
- name: Read results file
id: read_results
run: |
results="$(cat */result | jq -c --slurp .)"
echo results=$results >> $GITHUB_OUTPUT
- name: Filter results
id: filter_results
run: |
filtered_results="$(jq -n --argjson data '${{ steps.read_results.outputs.results }}' '$data[] | select(.licenselines != "")')"
echo filtered_results=$filtered_results >> $GITHUB_OUTPUT