-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
87 lines (78 loc) · 2.98 KB
/
action.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: 'generate-license-report'
author: 'Dafnik'
description: 'Generates a license report'
branding:
icon: 'grid'
color: 'purple'
inputs:
custom-license-report-command:
description: 'Indicates if the action should use the `license-report` command from `package.json` or not'
required: false
default: 'false'
prettier:
description: 'Indicates if the license report should be formatted with prettier'
required: false
default: 'true'
package-json-path:
description: 'package.json path'
required: false
default: 'package.json'
license-report-path:
description: 'file path'
required: false
default: 'licenses.json'
output-format:
description: 'output format'
required: false
default: 'json'
runs:
using: 'composite'
steps:
- name: generate new report
if: "${{ inputs.custom-license-report-command == 'false' }}"
shell: bash
run: npm exec -- license-report --only=prod,peer --fields=name --fields=licenseType --fields=link --fields=installedVersion --fields=author --package=${{ inputs.package-json-path }} --output=${{ inputs.output-format }} > "${{ inputs.license-report-path }}.new"
- name: generate new report (custom command)
if: "${{ inputs.custom-license-report-command == 'true' }}"
shell: bash
run: npm run license-report > "${{ inputs.license-report-path }}.new"
- name: format with prettier
if: "${{ inputs.prettier == 'true' }}"
shell: bash
run: npm exec -- prettier --parser=${{ inputs.output-format}} --write "${{ inputs.license-report-path }}.new"
- uses: LouisBrunner/[email protected]
name: check for differences
id: diff-check # required for steps.diff-check to function
continue-on-error: true
with:
old: ${{ inputs.license-report-path }}
new: ${{ inputs.license-report-path }}.new
mode: addition
tolerance: same
- name: Move files in place
if: steps.diff-check.outputs.passed != 'true'
shell: bash
run: mv -f ${{ inputs.license-report-path }}.new ${{ inputs.license-report-path }}
- name: Delete new file if not needed
if: steps.diff-check.outputs.passed == 'true'
shell: bash
run: |
rm ${{ inputs.license-report-path }}.new
- name: output licenses
id: output
shell: bash
run: |
delimiter=$(openssl rand -hex 8)
echo "licenses<<$delimiter" >> "${GITHUB_OUTPUT}"
echo -e "$(cat ${{ inputs.license-report-path }})" >> "${GITHUB_OUTPUT}"
echo "$delimiter" >> "${GITHUB_OUTPUT}"
outputs:
has-no-changes:
description: Flag to indicate if there are changes in the licenses file.
value: ${{ steps.diff-check.outputs.passed }}
diff:
description: Differences between old and new license report in markdown.
value: ${{ steps.diff-check.outputs.output }}
licenses:
description: License report as string in your chosen output-format. Is always returned
value: ${{ steps.output.outputs.licenses }}