forked from MarcoEidinger/swift-package-dependencies-check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·47 lines (43 loc) · 1.55 KB
/
entrypoint.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
#!/usr/bin/env bash
isMutating=$1
failWhenOutdated=$2
echo "Changing current directory..."
cd $3
echo "### Current Package Dependencies (swift package show-dependencies)"
swift package show-dependencies
SPU_RESULT=""
if [ "$isMutating" = true ] || [ "$isMutating" = 'true' ]; then
echo "### Check and Update Packages Dependencies if they are outdated (swift package update)"
echo "#### run swift-release-notes to get details about changes"
NOTES_EXTRACT="$(swift-release-notes . | grep -A 100 "changed.")"
# Multiline outputs need special treatment
NOTES=$(
cat <<-EOF
$NOTES_EXTRACT
EOF
)
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
echo "releaseNotes<<EOF" >>$GITHUB_OUTPUT
echo "$NOTES" >>$GITHUB_OUTPUT
echo "EOF" >>$GITHUB_OUTPUT
echo "### Run swift package update"
SPU_RESULT=$(swift package update 2>&1)
else
echo "### Check Packages Dependencies if they are up-to-date (swift package update --dry-run)"
SPU_RESULT=$(swift package update --dry-run 2>&1)
fi
echo "$SPU_RESULT"
if echo "$SPU_RESULT" | grep -q "0 dependencies have changed.\|Everything is already up-to-date"; then
echo outdatedDependencies=false >>$GITHUB_OUTPUT
exit 0
elif echo "$SPU_RESULT" | grep "error: "; then
echo outdatedDependencies=false >>$GITHUB_OUTPUT
exit 1
else
echo outdatedDependencies=true >>$GITHUB_OUTPUT
if [ "$failWhenOutdated" = true ] || [ "$failWhenOutdated" = 'true' ]; then
exit 1
else
exit 0
fi
fi