...
1#!/bin/bash
2
3# looks for (and modreplaces if existing) a smithy-go branch matching the
4# current branch name
5#
6# the loop will unfurl -*s off of the branch, e.g. sdk branch
7# 'feat-foo-bar-baz' will match any of the following (in order):
8# - feat-foo-bar-baz
9# - feat-foo-bar
10# - feat-foo
11
12if [ -z "$SMITHY_GO_REPOSITORY" ]; then
13 SMITHY_GO_REPOSITORY=aws/smithy-go
14fi
15
16if [ -z "$RUNNER_TMPDIR" ]; then
17 echo env RUNNER_TMPDIR is required
18 exit 1
19fi
20
21if [ -n "$GIT_PAT" ]; then
22 repository=https://$GIT_PAT@github.com/$SMITHY_GO_REPOSITORY
23else
24 repository=https://github.com/$SMITHY_GO_REPOSITORY
25fi
26
27branch=$(git branch --show-current)
28if [ "$branch" == main ]; then
29 echo aws-sdk-go-v2 is on branch main
30 git clone "$repository" "$RUNNER_TMPDIR"/smithy-go
31 exit 0
32fi
33
34# For PR workflows, only the triggering ref is checked out, which in isolation
35# is not recognized as a branch by git. Use the specific workflow env instead.
36if [ -z "$branch" ]; then
37 branch=$GITHUB_HEAD_REF
38fi
39
40echo on branch \"$branch\"
41while [ -n "$branch" ] && [[ "$branch" == *-* ]]; do
42 echo looking for "$branch"...
43 git ls-remote --exit-code --heads "$repository" refs/heads/"$branch"
44 if [ "$?" == 0 ]; then
45 echo found "$branch"
46 matched_branch=$branch
47 break
48 fi
49
50 branch=${branch%-*}
51done
52
53if [ -z "$matched_branch" ]; then
54 # default to main but don't modreplace so we can use release but codegen ci
55 # still works
56 git clone "$repository" "$RUNNER_TMPDIR"/smithy-go
57 exit 0
58fi
59
60git clone -b "$matched_branch" "$repository" "$RUNNER_TMPDIR"/smithy-go
61SMITHY_GO_SRC=$RUNNER_TMPDIR/smithy-go make gen-mod-replace-smithy-.
View as plain text