-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathpatch.yaml
More file actions
98 lines (86 loc) · 2.99 KB
/
Copy pathpatch.yaml
File metadata and controls
98 lines (86 loc) · 2.99 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
name: Apply patches
needs:
packages:
- patch
inputs:
strip-components:
description: |
The number of path components to strip while extracting.
default: 1
fuzz:
description: |
Sets the maximum fuzz factor. This option only applies to context diffs, and causes patch to ignore up to that many lines in looking for places to install a hunk.
default: 2
patches:
description: |
A list of patches to apply, as a whitespace delimited string.
series:
description: |
A quilt-style patch series file to apply.
pipeline:
- runs: |
strip_components=$(cat <<'MELANGE_STRIP_EOF'
${{inputs.strip-components}}
MELANGE_STRIP_EOF
)
strip_components=$(printf '%s' "$strip_components" | sed 's/^[[:space:]]*//' | tr -d '\n')
fuzz=$(cat <<'MELANGE_FUZZ_EOF'
${{inputs.fuzz}}
MELANGE_FUZZ_EOF
)
fuzz=$(printf '%s' "$fuzz" | sed 's/^[[:space:]]*//' | tr -d '\n')
case "$strip_components" in
''|*[!0-9]*)
printf 'ERROR: strip-components must be a non-negative integer, got: %s\n' "$strip_components" >&2
exit 1
;;
esac
case "$fuzz" in
''|*[!0-9]*)
printf 'ERROR: fuzz must be a non-negative integer, got: %s\n' "$fuzz" >&2
exit 1
;;
esac
series=$(cat <<'MELANGE_SERIES_EOF'
${{inputs.series}}
MELANGE_SERIES_EOF
)
series=$(printf '%s' "$series" | sed 's/^[[:space:]]*//' | tr -d '\n')
# Ensure that the series path doesn't contain shell metacharacters
case "$series" in
*"'"*|*'`'*|*'$('*|*'${'*|*';'*|*'|'*|*'&'*|*'>'*|*'<'*)
printf 'ERROR: series path contains invalid characters\n' >&2
exit 1
;;
esac
if [ -z "$series" ]; then
patches_input=$(cat <<'MELANGE_PATCHES_EOF'
${{inputs.patches}}
MELANGE_PATCHES_EOF
)
patches_input=$(printf '%s' "$patches_input" | sed 's/^[[:space:]]*//')
if [ -n "$patches_input" ]; then
series=$(mktemp)
printf '%s\n' "$patches_input" | awk '{ for(i = 1; i <= NF; i++) { print $i; } }' > "$series"
else
printf 'ERROR: Neither patches or series was set.\n' >&2
exit 1
fi
else
# Verify the series file exists
if [ ! -f "$series" ]; then
printf 'ERROR: series file does not exist: %s\n' "$series" >&2
exit 1
fi
fi
grep -v -E '^(#|$)' "$series" | while IFS= read -r patchfile || [ -n "$patchfile" ]; do
# Ensure that the patchfile path doesn't contain shell metacharacters
case "$patchfile" in
*"'"*|*'`'*|*'$('*|*'${'*|*';'*|*'|'*|*'&'*|*'>'*|*'<'*)
printf 'ERROR: patch file path contains invalid characters: %s\n' "$patchfile" >&2
exit 1
;;
esac
printf 'applying patch file %s\n' "$patchfile"
patch "-p${strip_components}" "--fuzz=${fuzz}" --verbose < "$patchfile"
done