forked from peace-maker/smrpg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.sh
executable file
·45 lines (34 loc) · 1.98 KB
/
upload.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
#!/bin/bash
echo "Starting the upload script..."
if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then
echo "We are on the master branch and it's not a pull request."
# Git-Konfiguration
echo "Configuring git with provided user email and name."
git config --global user.email "$GIT_USER_EMAIL"
git config --global user.name "$GIT_USER_NAME"
git remote set-url origin https://[email protected]/$GIT_USER_NAME/smrpg.git
# Erzeugen eines Tags
export GIT_TAG="build-${TRAVIS_BUILD_NUMBER}-SM${SMVERSION}"
echo "Creating and pushing tag: $GIT_TAG"
git tag $GIT_TAG -a -m "Generated tag from TravisCI for build $TRAVIS_BUILD_NUMBER with SMVERSION $SMVERSION"
git push origin $GIT_TAG || { echo "Failed to push git tag to repository."; exit 1; }
# Erzeugen der Release-Beschreibung
CURRENT_DATE=$(date "+%Y-%m-%d")
BODY="New Release on $CURRENT_DATE"
RESPONSE=$(curl -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/json" --data "{\"tag_name\": \"$GIT_TAG\", \"target_commitish\": \"master\", \"name\": \"$GIT_TAG\", \"body\": \"$BODY\", \"draft\": false, \"prerelease\": false}" https://api.github.com/repos/$GIT_USER_NAME/smrpg/releases)
echo "GitHub API Response: $RESPONSE"
GITREVCOUNT=$(git rev-list --count HEAD)
# Stelle sicher, dass der Pfad zum Archiv korrekt ist
ARCHIVE_PATH="smrpg-rev$GITREVCOUNT.tar.gz"
UPLOAD_URL=$(echo $RESPONSE | jq -r .upload_url | sed -e "s/{?name,label}//")
UPLOAD_URL="${UPLOAD_URL}?name=${ARCHIVE_PATH}&label=Release%20file"
if [ -f "$ARCHIVE_PATH" ]; then
echo "Uploading artifact from $ARCHIVE_PATH..."
curl -v -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/octet-stream" --data-binary @"$ARCHIVE_PATH" "$UPLOAD_URL"
else
echo "File does not exist: $ARCHIVE_PATH"
exit 1
fi
else
echo "This script only runs on master branch and when it's not a pull request."
fi