-
Notifications
You must be signed in to change notification settings - Fork 4
/
upload.sh
executable file
·73 lines (59 loc) · 2.25 KB
/
upload.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
#!/bin/bash
IFS=';' read -ra DIRECTORIES <<<"$(echo -e "${COMPONENTS_DIRECTORIES:-.}" | tr -d '[:space:]')"
NAMESPACE=${COMPONENTS_NAMESPACE:-espressif}
UPLOAD_ARGUMENTS=("--allow-existing" "--namespace=${NAMESPACE}" )
if [[ "${SKIP_PRE_RELEASE,,}" =~ ^(true|t|yes|1)$ ]]; then
UPLOAD_ARGUMENTS+=("--skip-pre-release")
fi
if [[ "${DRY_RUN,,}" =~ ^(true|t|yes|1)$ ]]; then
UPLOAD_ARGUMENTS+=("--dry-run")
fi
if [ -n "$COMPONENT_VERSION" ]; then
if [ "$COMPONENT_VERSION" == "git" ]; then
git fetch --force --tags
if ! git describe --exact-match; then
echo "Version is set to 'git', but the current commit is not tagged. Skipping the upload."
exit 0
fi
fi
UPLOAD_ARGUMENTS+=("--version=${COMPONENT_VERSION//v/}")
fi
NUMBER_OF_DIRECTORIES="${#DIRECTORIES[@]}"
echo "Processing $NUMBER_OF_DIRECTORIES components"
FAILED_COMPONENTS=()
for ITEM in "${DIRECTORIES[@]}"; do
FULL_PATH="${GITHUB_WORKSPACE?}/${ITEM}"
if [ "$NUMBER_OF_DIRECTORIES" -eq "1" ] && [ "${ITEM}" == "." ] && [ -z "${COMPONENT_NAME}" ]; then
echo "To upload a single component, either specify the component name or directory, which will be used as the component name"
exit 1
fi
if [ "${ITEM}" == "." ]; then
NAME=${COMPONENT_NAME?"Name is required to upload a component from the root of the repository."}
else
NAME=$(basename "$(realpath "${FULL_PATH}")")
fi
echo "Processing component \"$NAME\" at $ITEM"
PARAMS=("${UPLOAD_ARGUMENTS[@]}")
PARAMS+=("--project-dir=${FULL_PATH}" "--name=${NAME}" )
if [ -n "$REPOSITORY_URL" ]; then
PARAMS+=("--repository=${REPOSITORY_URL}")
fi
if [ -n "$REPOSITORY_COMMIT_SHA" ]; then
PARAMS+=("--commit-sha=${REPOSITORY_COMMIT_SHA}")
fi
if [ -n "$REPOSITORY_URL" ] && [ -n "$REPOSITORY_COMMIT_SHA" ]; then
PARAMS+=("--repository-path=${ITEM}")
fi
compote component upload "${PARAMS[@]}"
EXIT_CODE=$?
if [ "$EXIT_CODE" -ne "0" ]; then
FAILED_COMPONENTS+=("${NAMESPACE}/${NAME}")
fi
done
if [ ${#FAILED_COMPONENTS[@]} -ne 0 ]; then
echo "Failed to upload the following components:"
for COMPONENT in "${FAILED_COMPONENTS[@]}"; do
echo "- ${COMPONENT}"
done
exit 1
fi