This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
generated from actions/container-action
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentrypoint.sh
executable file
·138 lines (106 loc) · 3.15 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/sh -le
export GITHUB_TOKEN="${1}"
readonly GIT_USER_NAME="${2}"
readonly GIT_USER_EMAIL="${3}"
readonly BASE="${4}"
readonly REVIEWER="${5}"
readonly ASSIGN="${6}"
readonly MILESTONE="${7}"
readonly LABELS="${8}"
readonly DRAFT="${9}"
readonly GO_MOD_DIRCTORY="${10}"
readonly GO_VERSION="${11}"
readonly DEBUG="${12}"
readonly DUPLICATE="${13}"
readonly TIMEZONE="${14}"
readonly PR_TITLE_PREFIX="go mod tidy at "
install_go() {
if [ -z "$GO_VERSION" ]; then
go_version=$(curl -s https://api.github.com/repos/golang/go/git/refs/tags \
| jq --raw-output '.[].ref | select(test("^refs/tags/go[0-9.]+$"))' \
| tail -n 1 \
| sed 's!refs/tags/go!!')
else
go_version=$GO_VERSION
fi
echo "installing Go $go_version"
# from https://golang.org/doc/install#tarball
go_tar=go$go_version.linux-amd64.tar.gz
wget https://dl.google.com/go/"$go_tar"
tar -C /usr/local -xzf "$go_tar"
rm "$go_tar"
}
install_git_lfs() {
git_lfs_url=$(curl -s https://api.github.com/repos/git-lfs/git-lfs/releases/latest \
| jq --raw-output '.assets[] | select( .name | contains("linux-amd64") ) | .browser_download_url')
echo "installing Git LFS (latest release)"
wget "$git_lfs_url"
git_lfs_tar="${git_lfs_url##*/}"
mkdir -pv ./git-lfs
tar -C ./git-lfs -zxvf "$git_lfs_tar"
cd git-lfs
./install.sh
cd ..
rm "$git_lfs_tar"
rm -rf git-lfs
}
if [ -n "$DEBUG" ]; then
set -x
export HUB_VERBOSE="true"
fi
if [ -n "$TIMEZONE" ]; then
export TZ="$TIMEZONE"
fi
cd "$GO_MOD_DIRCTORY"
install_go
export PATH="$PATH":/usr/local/go/bin
install_git_lfs
git config --global url."https://$GITHUB_TOKEN:[email protected]".insteadOf "https://github.com"
go mod tidy
if [ -d vendor/ ]; then
go mod vendor
fi
if [ "$(git status | grep -c "nothing to commit, working tree clean")" = "1" ]; then
echo "go.sum is not updated"
exit 0
fi
if [ -z "$DUPLICATE" ]; then
if [ "$(hub pr list | grep -c "$PR_TITLE_PREFIX")" != "0" ]; then
echo "Skip creating PullRequest because it has already existed"
exit 0
fi
fi
git config --global user.email "$GIT_USER_EMAIL"
git config --global user.name "$GIT_USER_NAME"
readonly BRANCH_NAME=go-mod-tidy-$(date +"%Y%m%d%H%M%S")
GITHUB_USER="$(echo "${GITHUB_REPOSITORY:?}" | cut -d "/" -f 1)"
export GITHUB_USER
readonly REMOTE_URL="https://$GITHUB_USER:[email protected]/$GITHUB_REPOSITORY.git"
git remote add push_via_ci "$REMOTE_URL"
git checkout -b "$BRANCH_NAME"
if [ -d vendor/ ]; then
git add vendor/
git commit -am ":put_litter_in_its_place: go mod tidy && go mod vendor"
else
git commit -am ":put_litter_in_its_place: go mod tidy"
fi
git push push_via_ci "$BRANCH_NAME"
if [ -n "$BASE" ]; then
hub_args="$hub_args --base=$BASE"
fi
if [ -n "$REVIEWER" ]; then
hub_args="$hub_args --reviewer=$REVIEWER"
fi
if [ -n "$ASSIGN" ]; then
hub_args="$hub_args --assign=$ASSIGN"
fi
if [ -n "$MILESTONE" ]; then
hub_args="$hub_args --milestone=$MILESTONE"
fi
if [ -n "$LABELS" ]; then
hub_args="$hub_args --labels=$LABELS"
fi
if [ -n "$DRAFT" ]; then
hub_args="$hub_args --draft"
fi
GITHUB_TOKEN=${GITHUB_TOKEN} hub pull-request --no-edit --message="$PR_TITLE_PREFIX$(date)" "$hub_args"