-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yaml
More file actions
66 lines (55 loc) · 1.71 KB
/
action.yaml
File metadata and controls
66 lines (55 loc) · 1.71 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
name: 'Find matching Dockerfile'
inputs:
path:
description: 'the path to search for the dockerfile'
required: true
version:
description: 'The version of the service (e.g., 8.1.2)'
required: true
outputs:
dockerfile:
description: 'Dockerfile name'
value: ${{ steps.find-dockerfile.outputs.dockerfile }}
runs:
using: composite
steps:
- name: Find Dockerfile
id: find-dockerfile
shell: bash
env:
PATH: ${{ inputs.path }}
VERSION: ${{ inputs.version }}
run: |
find_dockerfile() {
local search_path="$1"
local version="$2"
local current="$version"
while [[ -n "$current" ]]; do
local candidate="${search_path}/${current}.Dockerfile"
if [[ -f "$candidate" ]]; then
echo "$(basename "$candidate")"
return 0
fi
# Remove last dot-segment (2.1.3 → 2.1 → 2)
current="${current%.*}"
# If nothing changed, break
[[ "$current" == "$version" ]] && break
version="$current"
done
# Fallback to default Dockerfile
if [[ -f "${search_path}/Dockerfile" ]]; then
echo "Dockerfile"
return 0
fi
return 1
}
if [[ ! -d "$PATH" ]]; then
echo "Error: Directory '$PATH' not found" >&2
exit 1
fi
if DOCKERFILE_NAME=$(find_dockerfile "$PATH" "$VERSION"); then
echo "dockerfile=${DOCKERFILE_NAME}" >> $GITHUB_OUTPUT
else
echo "Error: No matching Dockerfile found" >&2
exit 1
fi