forked from eclipse-dash/quevee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanifest-toml.sh
executable file
·107 lines (90 loc) · 2.67 KB
/
manifest-toml.sh
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
#!/bin/bash
# Copyright (C) 2024 ETAS
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# SPDX-License-Identifier: Apache-2.0
time=$(date)
owner=$(echo "$GITHUB_REPOSITORY" | cut -d '/' -f 1)
repo=$(echo "$GITHUB_REPOSITORY" | cut -d '/' -f 2)
if [ -n "$INPUT_RELEASE_URL" ]; then
release_url="$INPUT_RELEASE_URL"
else
release_url="unavailable"
fi
generate_toml_header() {
cat <<EOF
[metadata]
repo-url = "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
created = "$time"
by-action = "$GITHUB_ACTION"
project = "$owner"
repository = "$repo"
ref-tag = "$GITHUB_REF_NAME"
git-hash = "$GITHUB_WORKFLOW_SHA"
release-url = "$release_url"
EOF
}
# Generate artifact-list toml section
generate_toml_section() {
local section="$1"
local entries="$2"
local temp_output=""
IFS=',' read -r -a array <<<"$entries"
if [ ${#array[@]} -gt 0 ]; then
for element in "${array[@]}"; do
validate_url $element
temp_output+=$'\n'" \"$element\","
done
cat <<EOF
$section = [$temp_output
]
EOF
fi
}
# Validate URL using regex
validate_url() {
local url="$1"
local regex="^(http|https)://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}(:[0-9]+)?(/[a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~]*)?$"
if [[ ! $url =~ $regex ]]; then
echo "Invalid URL: $url" >&2
fi
}
### Main script section
OUTPUT="manifest.toml"
# Write header section
generate_toml_header >>"$OUTPUT"
# Write artifact sections
for var in $(env | grep "^INPUT_" | cut -d= -f1); do
value="${!var}"
case "$var" in
"INPUT_ARTIFACTS_DOCUMENTATION")
generate_toml_section "documentation" "$value" >>"$OUTPUT"
;;
"INPUT_ARTIFACTS_LICENSE")
generate_toml_section "licensing" "$value" >>"$OUTPUT"
;;
"INPUT_ARTIFACTS_README")
generate_toml_section "readme" "$value" >>"$OUTPUT"
;;
"INPUT_ARTIFACTS_REQUIREMENTS")
generate_toml_section "requirements" "$value" >>"$OUTPUT"
;;
"INPUT_ARTIFACTS_TESTING")
generate_toml_section "testing" "$value" >>"$OUTPUT"
;;
*)
echo "Unknown artifact type ${var#INPUT_ARTIFACTS_}"
;;
esac
done
# Pass name of generated file as output
echo "manifest_file=$OUTPUT" >>$GITHUB_OUTPUT