forked from nnichols/clojure-dependency-update-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdependency-check.sh
executable file
·105 lines (85 loc) · 3.28 KB
/
dependency-check.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
#!/bin/bash
git config --global user.email $EMAIL
git config --global user.name $NAME
export GITHUB_TOKEN=$TOKEN
echo "check out $BRANCH"
git checkout $BRANCH
echo "Devise --exclude from $EXCLUDE"
EXCLUDES=""
for artifact in $EXCLUDE; do
EXCLUDES="${EXCLUDES} --exclude=${artifact}"
done
echo "Devise --directory from $DIRECTORY"
if [ -z "${DIRECTORY}" ]; then
echo "No directory specified, defaulting to ."
DIRECTORY="."
fi
DIRECTORIES=""
for directory in $DIRECTORY; do
DIRECTORIES="${DIRECTORIES} --directory=${directory}"
done
echo "Devise --skip from $SKIP"
SKIPS=""
for skip in $SKIP; do
SKIPS="${SKIPS} --skip=${skip}"
done
PREFETCH=$(clojure -Stree -Sdeps '{:deps {antq/antq {:mvn/version "RELEASE"}}}')
FORMATTER="--reporter=format --error-format=\"{{name}},{{version}},{{latest-version}},{{diff-url}}\""
UPGRADE_CMD="clojure -Sdeps '{:deps {antq/antq {:mvn/version \"RELEASE\"}}}' -m antq.core ${FORMATTER} ${EXCLUDES} ${DIRECTORIES} ${SKIPS}"
echo "Running upgrade command"
echo $UPGRADE_CMD
echo
UPGRADE_LIST=$(eval ${UPGRADE_CMD})
UPGRADES=$(echo ${UPGRADE_LIST} | sed '/Failed to fetch/d' | sed '/Unable to fetch/d' | sed '/Logging initialized/d' | sort -u)
UPDATE_TIME=$(date +"%Y-%m-%d-%H-%M-%S")
if [ "$UPGRADES" == "" ] then
echo "NO UPGRADES FOUND"
echo "full upgrade list printed below:"
echo $UPGRADE_LIST
exit
fi
echo "Processing upgrades... $UPGRADES"
for upgrade in $UPGRADES; do
# Parse each upgrade into its constituent parts
IFS=',' temp=($upgrade)
DEP_NAME=${temp[0]}
OLD_VERSION=${temp[1]}
NEW_VERSION=${temp[2]}
DIFF_URL=${temp[3]}
MODIFIED_FILE=${temp[4]}
echo "Work out branch name based on batch value: $BATCH"
# If we're performing a batch update, reuse the branch name
# Otherwise, create branch names for each unique update
if [ "$BATCH" == "true" ]; then
BRANCH_NAME="dependencies/clojure/${UPDATE_TIME}"
else
BRANCH_NAME="dependencies/clojure/$DEP_NAME-$NEW_VERSION"
fi
echo "branch name = $BRANCH_NAME"
# Checkout the branch if it exists, otherwise create it
echo "Checking out" $BRANCH_NAME
git checkout $BRANCH_NAME || git checkout -b $BRANCH_NAME
echo "last command exit status = $?"
if [[ $? == 0 ]]; then
# Use antq to update the dependency
echo "Updating" $DEP_NAME "version" $OLD_VERSION "to" $NEW_VERSION
UPDATE_CMD="clojure -Sdeps '{:deps {antq/antq {:mvn/version \"RELEASE\"}}}' -m antq.core --upgrade --force ${DIRECTORIES} --focus=${DEP_NAME}"
eval ${UPDATE_CMD} || $(echo "Cannot update ${DEP_NAME}. Continuing" && git checkout ${BRANCH} && continue)
# Commit the dependency update, and link to the diff
git add .
git commit -m "Bumped $DEP_NAME from $OLD_VERSION to $NEW_VERSION." -m "Inspect dependency changes here: $DIFF_URL"
git push -u "https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY.git" $BRANCH_NAME
# We only create pull requests per dependency in non-batch mode
if [ "$BATCH" != "true" ]; then
gh pr create --fill --head $BRANCH_NAME --base $BRANCH
fi
# Print a blank line, and reset the branch
echo
git checkout $BRANCH
fi
done
# Once all updates have been made, open the pull request for batch mode
if [ "$BATCH" == "true" ]; then
git checkout $BRANCH_NAME
gh pr create --fill --head $BRANCH_NAME --base $BRANCH
fi