-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
101 lines (88 loc) · 2.82 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Weeder
description: Annotate unused functions in a Haskell project
inputs:
ghc-version:
description: Full version of GHC your project uses (required)
required: true
weeder-arguments:
description: |
Arguments to pass when invoking weeder (default --require-hs-files)
required: true
default: --require-hs-files
working-directory:
description: Change to this directory before operating
required: true
default: .
fail:
description: Fail the build if unused functions found? (default true)
required: true
default: true
outputs:
log:
description: Path to file containing the output from weeder
value: ${{ steps.weeder.outputs.log }}
runs:
using: composite
steps:
- name: Install weeder
uses: pbrisbin/setup-tool-action@v2
with:
name: weeder
version: ${{ inputs.ghc-version }}
url: "https://github.com/freckle/weeder-action/releases/download/Binaries/{name}-{version}-{os}-{arch}.{ext}"
- id: weeder-version
name: Record weeder version
shell: bash
run: |
{
printf 'result='
weeder --version | sed '/^weeder version \(.*\)$/!d; s//\1/'
} >>"$GITHUB_OUTPUT"
- id: weeder-check
name: Compare weeder version with v2.7
uses: pbrisbin/semver-compare-action@master
with:
left-semver: ${{ steps.weeder-version.outputs.result }}
right-semver: 2.7.0
- id: weeder
name: Run weeder
shell: bash
env:
WEEDER_VERCMP: ${{ steps.weeder-check.outputs.compare-value }}
run: |
echo "::add-matcher::${{ github.action_path }}/matcher.json"
trap 'echo "::remove-matcher owner=freckle-weeder::"' EXIT
tmp=$(mktemp)
echo "log=$tmp" >>"$GITHUB_OUTPUT"
cd '${{ inputs.working-directory }}'
prefix=$(echo '${{ inputs.working-directory }}' | sed 's|/$||')/
ret=0
if ! weeder ${{ inputs.weeder-arguments }} |
sed "s|^|$prefix|; "'s/$/ is not used by any defined root/' |
tee "$tmp"; then
ret=${PIPESTATUS[0]} # can't trust $? here, apparently
fi
unused_functions_found=0
if ((WEEDER_VERCMP >= 0)); then
if ((ret == 228)); then
unused_functions_found=1
fi
else
if [[ -s "$tmp" ]]; then
unused_functions_found=1
fi
fi
if ((!ret)); then
echo "No unused functions found"
exit 0
fi
if ((unused_functions_found)); then
if ${{ inputs.fail }}; then
echo "Configured to fail and unused functions found"
exit 1
fi
echo "Unused functions found, but not configured to fail"
exit 0
fi
echo "Weeder encountered some other error" >&2
exit $ret