-
Notifications
You must be signed in to change notification settings - Fork 653
/
ci-find-smithy-go.sh
executable file
·61 lines (51 loc) · 1.64 KB
/
ci-find-smithy-go.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
#!/bin/bash
# looks for (and modreplaces if existing) a smithy-go branch matching the
# current branch name
#
# the loop will unfurl -*s off of the branch, e.g. sdk branch
# 'feat-foo-bar-baz' will match any of the following (in order):
# - feat-foo-bar-baz
# - feat-foo-bar
# - feat-foo
if [ -z "$SMITHY_GO_REPOSITORY" ]; then
SMITHY_GO_REPOSITORY=aws/smithy-go
fi
if [ -z "$RUNNER_TMPDIR" ]; then
echo env RUNNER_TMPDIR is required
exit 1
fi
if [ -n "$GIT_PAT" ]; then
repository=https://[email protected]/$SMITHY_GO_REPOSITORY
else
repository=https://github.com/$SMITHY_GO_REPOSITORY
fi
branch=$(git branch --show-current)
if [ "$branch" == main ]; then
echo aws-sdk-go-v2 is on branch main
git clone "$repository" "$RUNNER_TMPDIR"/smithy-go
exit 0
fi
# For PR workflows, only the triggering ref is checked out, which in isolation
# is not recognized as a branch by git. Use the specific workflow env instead.
if [ -z "$branch" ]; then
branch=$GITHUB_HEAD_REF
fi
echo on branch \"$branch\"
while [ -n "$branch" ] && [[ "$branch" == *-* ]]; do
echo looking for "$branch"...
git ls-remote --exit-code --heads "$repository" refs/heads/"$branch"
if [ "$?" == 0 ]; then
echo found "$branch"
matched_branch=$branch
break
fi
branch=${branch%-*}
done
if [ -z "$matched_branch" ]; then
# default to main but don't modreplace so we can use release but codegen ci
# still works
git clone "$repository" "$RUNNER_TMPDIR"/smithy-go
exit 0
fi
git clone -b "$matched_branch" "$repository" "$RUNNER_TMPDIR"/smithy-go
SMITHY_GO_SRC=$RUNNER_TMPDIR/smithy-go make gen-mod-replace-smithy-.