-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
124 lines (109 loc) · 4 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: 'Checkout the x (or latest) upstream version and apply a patch'
description: Checkout the x (or latest) upstream version and apply a patch
outputs:
latest:
description: "True/False if we used the last tag from upstream or not"
value: ${{ (steps.check_last_tag.outputs.tag == '') }}
tag:
description: "Upstream tag ref checked out and patched"
value: ${{ steps.check_last_tag.outputs.tag }}
tag_major:
description: "Upstream tag major semver"
value: ${{ steps.major_minor.outputs.major }}
tag_minor:
description: "Upstream tag major minor"
value: ${{ steps.major_minor.outputs.minor }}
tag_patch:
description: "Upstream tag major patch"
value: ${{ steps.major_minor.outputs.patch }}
inputs:
upstream_repo:
description: "The upstream repo that we want to checkout and patch"
required: true
upstream_ref:
description: "The upstream ref, can be: branch, tag, sha, if not provided last semver tag will be grabbed"
required: false
upstream_tag_regex:
description: "Regex to use while checking the last upstream versions"
required: false
local_patch_dir:
description: "Directory of the patch files, must end with .patch"
required: true
upstream_remove_files:
description: "Line separated list of files to remove from upstream repository"
required: false
upstream_copy:
description: "Line separated pair of source directory from upstream and destinations. The fields are passed as is to the cp command"
required: false
runs:
using: "composite"
steps:
# Only run when upstream_ref was not provided
- name: Check last tag in upstream repo
id: check_last_tag
uses: oprypin/[email protected]
if: ${{ inputs.upstream_ref == '' }}
with:
repository: ${{ inputs.upstream_repo }}
regex: ${{ inputs.upstream_tag_regex }}
- name: Extract Major and minor version
id: major_minor
if: steps.check_last_tag.outcome == 'success'
shell: bash
env:
TAG: ${{ steps.check_last_tag.outputs.tag }}
run: |
# Little bash-ism to avoid use an external
# action only for semver parsing
VERSION="${TAG//v}"
v=( ${VERSION//./ } )
printf "Major is %s \n" ${v[0]}
printf "Minor is %s \n" ${v[1]}
printf "Patch is %s \n" ${v[2]}
echo "major=${v[0]}" >> $GITHUB_OUTPUT
echo "minor=${v[1]}" >> $GITHUB_OUTPUT
echo "patch=${v[2]}" >> $GITHUB_OUTPUT
- uses: actions/[email protected]
name: Checkout latest version
if: ${{ inputs.upstream_ref == '' }}
with:
repository: ${{inputs.upstream_repo }}
ref: ${{ steps.check_last_tag.outputs.tag }}
path: 'upstream'
- uses: actions/[email protected]
name: Checkout the fixed version
if: ${{ inputs.upstream_ref != '' }}
with:
repository: ${{inputs.upstream_repo }}
ref: ${{ inputs.upstream_ref }}
path: 'upstream'
- uses: actions/[email protected]
name: Checkout local repo
with:
path: 'patch'
- name: Apply Patch files
shell: bash
env:
PATCHDIR: ${{ inputs.local_patch_dir }}
run: for p in patch/${PATCHDIR}/*.patch; do patch -d upstream/ -p1 < $p; done
- name: Remove from upstream
id: upstream_remove_files
if: ${{ inputs.upstream_remove_files != '' }}
shell: bash
run: |
FILES=$(echo "${{ inputs.upstream_remove_files }}" | tr '\n' ' ')
for file in ${FILES}; do
[[ -f "upstream/${file}" ]] && rm -v "upstream/${file}" || true
done
- name: Copy from upstream to chart
id: upstream_copy
if: ${{ inputs.upstream_copy != '' }}
shell: bash
run: |
MAPPINGS=$(echo "${{ inputs.upstream_copy }}")
echo "${MAPPINGS}" | while read mapping; do
SRC=$(echo "$mapping" | awk '{print $1}')
DST=$(echo "$mapping" | awk '{print $2}')
echo Copying from ${SRC} to ${DST}
cp -Rv upstream/${SRC} "${DST}"
done