-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.sh
executable file
·72 lines (56 loc) · 1.96 KB
/
package.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
#!/bin/bash -e
# Brew package script
export APP="dockerfix"
REPO_NAME="homebrew-dockerfix"
git config user.name "$USER"
git config user.email "$USER_EMAIL"
export RELEASE_COUNT="$GITHUB_RUN_NUMBER"
GIT_REVISION=$(git rev-parse HEAD)
BRANCH="master"
# Compress new version and place in tars archive
mkdir tars
tar cvf tars/"${APP}-0.1.${RELEASE_COUNT}.tar.gz" "$APP"
# Generate Ruby file for Brew using template
erb "${APP}.erb" > "${APP}.rb"
## Git Tasks
git add "${APP}.rb"
# Commit and push files to repo
git commit -m "Push $APP Release 0.1.${RELEASE_COUNT}" &&
git push https://"${USER}:${USER_PASSWORD}@github.com/${ORG}/${REPO_NAME}".git "$BRANCH"
# Publish go cli binaries
post_release_json()
{
cat <<EOF
{
"tag_name": "0.1.${RELEASE_COUNT}",
"target_commitish": "${GIT_REVISION}",
"name": "0.1.${RELEASE_COUNT}"
}
EOF
}
echo "Creating release.."
NEW_RELEASE_RESPONSE=$(curl --silent \
--write-out "\n%{http_code}" \
-u "$USER:$USER_PASSWORD" \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X POST "https://api.github.com/repos/${ORG}/${REPO_NAME}/releases" \
--data "$(post_release_json)")
STATUS_CODE=$(echo "$NEW_RELEASE_RESPONSE" | tail -n 1)
NEW_RELEASE=$(echo "$NEW_RELEASE_RESPONSE" | sed '$d')
if [[ $STATUS_CODE -ge 400 ]]; then
echo 'ERROR: Failed to create release'
echo "$STATUS_CODE"
echo "$NEW_RELEASE"
exit 1
fi
echo "Release created"
UPLOAD_URL=$(echo "$NEW_RELEASE" | jq -r .upload_url | cut -f1 -d"{")
echo "Uploading binaries"
curl --fail \
-u "${USER}:${USER_PASSWORD}" \
-H "Content-Type:application/octet-stream" \
-X POST "${UPLOAD_URL}?name=${APP}-0.1.${RELEASE_COUNT}.tar.gz" \
--data-binary "@tars/${APP}-0.1.${RELEASE_COUNT}.tar.gz" \
| jq -rc '.name + " - " + .url + " - " + .state'
echo "$0 Done."