Optimize things, don't keep settings menu always loaded.
This commit is contained in:
parent
8fa662ec38
commit
0d8e27ce7b
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -34,4 +34,7 @@ CTestTestfile.cmake
|
|||
_deps
|
||||
*_autogen
|
||||
*.core
|
||||
.core
|
||||
.core
|
||||
*qmlcache*
|
||||
cmake_install.cmake
|
||||
spdlog
|
|
@ -59,6 +59,7 @@ set(SOURCES
|
|||
src/ThumbnailCache.cpp
|
||||
src/logger.cpp
|
||||
src/qmldebugger.cpp
|
||||
src/registerTypes.cpp
|
||||
src/Backends/MPVCommon/MPVCommon.cpp
|
||||
src/Backends/MPVNoFBO/MPVNoFBOBackend.cpp
|
||||
${SOURCES}
|
||||
|
@ -74,11 +75,13 @@ set(CMAKE_BUILD_TYPE DEBUG)
|
|||
|
||||
option(DEBUG "debugging out" OFF)
|
||||
if(DEBUG)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS} -ggdb -g3 -O3")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS} -ggdb -g3 -Og")
|
||||
else()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS} -O3 -s")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS} -s")
|
||||
endif()
|
||||
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-command-line-argument")
|
||||
|
||||
|
||||
if(DEFINED ENV{TRAVIS})
|
||||
execute_process(
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
# Install script for directory: /home/kitteh/kittehplayer
|
||||
|
||||
# Set the install prefix
|
||||
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
|
||||
set(CMAKE_INSTALL_PREFIX "/usr/local")
|
||||
endif()
|
||||
string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
||||
|
||||
# Set the install configuration name.
|
||||
if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
|
||||
if(BUILD_TYPE)
|
||||
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
|
||||
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
|
||||
else()
|
||||
set(CMAKE_INSTALL_CONFIG_NAME "DEBUG")
|
||||
endif()
|
||||
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
|
||||
endif()
|
||||
|
||||
# Set the component getting installed.
|
||||
if(NOT CMAKE_INSTALL_COMPONENT)
|
||||
if(COMPONENT)
|
||||
message(STATUS "Install component: \"${COMPONENT}\"")
|
||||
set(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
|
||||
else()
|
||||
set(CMAKE_INSTALL_COMPONENT)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Is this installation the result of a crosscompile?
|
||||
if(NOT DEFINED CMAKE_CROSSCOMPILING)
|
||||
set(CMAKE_CROSSCOMPILING "FALSE")
|
||||
endif()
|
||||
|
||||
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xUnspecifiedx" OR NOT CMAKE_INSTALL_COMPONENT)
|
||||
if(EXISTS "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/KittehPlayer" AND
|
||||
NOT IS_SYMLINK "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/KittehPlayer")
|
||||
file(RPATH_CHECK
|
||||
FILE "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/KittehPlayer"
|
||||
RPATH "")
|
||||
endif()
|
||||
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" TYPE EXECUTABLE FILES "/usr/home/kitteh/kittehplayer/KittehPlayer")
|
||||
if(EXISTS "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/KittehPlayer" AND
|
||||
NOT IS_SYMLINK "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/KittehPlayer")
|
||||
file(RPATH_CHANGE
|
||||
FILE "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/KittehPlayer"
|
||||
OLD_RPATH "/usr/local/lib:/usr/local/lib/qt5:"
|
||||
NEW_RPATH "")
|
||||
if(CMAKE_INSTALL_DO_STRIP)
|
||||
execute_process(COMMAND "/usr/bin/strip" "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/KittehPlayer")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xUnspecifiedx" OR NOT CMAKE_INSTALL_COMPONENT)
|
||||
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/share/applications" TYPE FILE FILES "/home/kitteh/kittehplayer/KittehPlayer.desktop")
|
||||
endif()
|
||||
|
||||
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xUnspecifiedx" OR NOT CMAKE_INSTALL_COMPONENT)
|
||||
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/256x256/apps" TYPE FILE FILES "/home/kitteh/kittehplayer/KittehPlayer.png")
|
||||
endif()
|
||||
|
||||
if(CMAKE_INSTALL_COMPONENT)
|
||||
set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt")
|
||||
else()
|
||||
set(CMAKE_INSTALL_MANIFEST "install_manifest.txt")
|
||||
endif()
|
||||
|
||||
string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT
|
||||
"${CMAKE_INSTALL_MANIFEST_FILES}")
|
||||
file(WRITE "/usr/home/kitteh/kittehplayer/${CMAKE_INSTALL_MANIFEST}"
|
||||
"${CMAKE_INSTALL_MANIFEST_CONTENT}")
|
0
scripts/makeappimage.sh
Normal file → Executable file
0
scripts/makeappimage.sh
Normal file → Executable file
|
@ -22,7 +22,7 @@ auto mpvLogger = initLogger("mpv");
|
|||
|
||||
QString humanSize(uint64_t bytes)
|
||||
{
|
||||
char *suffix[] = {"B", "KB", "MB", "GB", "TB"};
|
||||
const char *suffix[5] = {"B", "KB", "MB", "GB", "TB"};
|
||||
char length = sizeof(suffix) / sizeof(suffix[0]);
|
||||
|
||||
int i = 0;
|
||||
|
|
68
src/main.cpp
68
src/main.cpp
|
@ -5,6 +5,7 @@
|
|||
#include <QtQml>
|
||||
#include <QQmlApplicationEngine>
|
||||
#ifdef QT_QML_DEBUG
|
||||
#warning "QML Debugging Enabled!!!"
|
||||
#include <QQmlDebug>
|
||||
#endif
|
||||
#include <QSettings>
|
||||
|
@ -16,44 +17,14 @@
|
|||
#include <exception>
|
||||
#include <iosfwd>
|
||||
#include <memory>
|
||||
#ifndef DISABLE_MPV_RENDER_API
|
||||
#include "Backends/MPV/MPVBackend.hpp"
|
||||
#endif
|
||||
#include "Backends/MPVNoFBO/MPVNoFBOBackend.hpp"
|
||||
#include "Process.h"
|
||||
#include "ThumbnailCache.h"
|
||||
#include "enums.hpp"
|
||||
#include "logger.h"
|
||||
#include "qmldebugger.h"
|
||||
#include "spdlog/logger.h"
|
||||
#include "utils.hpp"
|
||||
|
||||
extern void registerTypes();
|
||||
|
||||
#ifdef WIN32
|
||||
#include "setenv_mingw.hpp"
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
#include <initializer_list>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
void
|
||||
catchUnixSignals(std::initializer_list<int> quitSignals)
|
||||
{
|
||||
auto handler = [](int sig) -> void { QCoreApplication::quit(); };
|
||||
|
||||
sigset_t blocking_mask;
|
||||
sigemptyset(&blocking_mask);
|
||||
for (auto sig : quitSignals)
|
||||
sigaddset(&blocking_mask, sig);
|
||||
|
||||
struct sigaction sa;
|
||||
sa.sa_handler = handler;
|
||||
sa.sa_mask = blocking_mask;
|
||||
sa.sa_flags = 0;
|
||||
|
||||
for (auto sig : quitSignals)
|
||||
sigaction(sig, &sa, nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto qmlLogger = initLogger("qml");
|
||||
auto miscLogger = initLogger("misc");
|
||||
|
@ -109,21 +80,19 @@ main(int argc, char* argv[])
|
|||
#endif
|
||||
|
||||
QSettings settings;
|
||||
Utils::SetDPMS(false);
|
||||
|
||||
bool ranFirstTimeSetup = settings.value("Setup/ranSetup", false).toBool();
|
||||
|
||||
#ifdef __linux__
|
||||
catchUnixSignals({ SIGQUIT, SIGINT, SIGTERM, SIGHUP });
|
||||
|
||||
// WARNING, THIS IS A BIG HACK
|
||||
// this is only to make it so KittehPlayer works first try on pinephone.
|
||||
// TODO: launch a opengl window or use offscreen to see if GL_ARB_framebuffer_object
|
||||
// can be found
|
||||
if (! settings.value("Backend/disableSunxiCheck", false).toBool()) {
|
||||
if (! (settings.value("Backend/disableSunxiCheck", false).toBool() || ranFirstTimeSetup)) {
|
||||
FILE *fd = popen("grep sun[x8]i /proc/modules", "r");
|
||||
char buf[16];
|
||||
if (fread(buf, 1, sizeof (buf), fd) > 0) {
|
||||
launcherLogger->info("Running on sunxi, switching to NoFBO.");
|
||||
settings.setValue("Backend/fbo", false);
|
||||
settings.setValue("Appearance/clickToPause", false);
|
||||
settings.setValue("Appearance/doubleTapToSeek", true);
|
||||
settings.setValue("Appearance/scaleFactor", 2.2);
|
||||
|
@ -131,37 +100,18 @@ main(int argc, char* argv[])
|
|||
settings.setValue("Appearance/uiFadeTimer", 0);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
settings.setValue("Setup/ranSetup", true);
|
||||
|
||||
QString newpath =
|
||||
QProcessEnvironment::systemEnvironment().value("APPDIR", "") +
|
||||
"/usr/bin:" + QProcessEnvironment::systemEnvironment().value("PATH", "");
|
||||
setenv("PATH", newpath.toUtf8().constData(), 1);
|
||||
|
||||
qmlRegisterUncreatableMetaObject(
|
||||
Enums::staticMetaObject, "player", 1, 0, "Enums", "Error: only enums");
|
||||
qRegisterMetaType<Enums::PlayStatus>("Enums.PlayStatus");
|
||||
qRegisterMetaType<Enums::VolumeStatus>("Enums.VolumeStatus");
|
||||
qRegisterMetaType<Enums::Backends>("Enums.Backends");
|
||||
qRegisterMetaType<Enums::Commands>("Enums.Commands");
|
||||
qmlRegisterType<Process>("player", 1, 0, "Process");
|
||||
registerTypes();
|
||||
|
||||
qmlRegisterType<QMLDebugger>("player", 1, 0, "QMLDebugger");
|
||||
qmlRegisterType<ThumbnailCache>("player", 1, 0, "ThumbnailCache");
|
||||
|
||||
qmlRegisterType<UtilsClass>("player", 1, 0, "Utils");
|
||||
|
||||
#ifndef DISABLE_MPV_RENDER_API
|
||||
if (settings.value("Backend/fbo", true).toBool()) {
|
||||
qmlRegisterType<MPVBackend>("player", 1, 0, "PlayerBackend");
|
||||
} else {
|
||||
qmlRegisterType<MPVNoFBOBackend>("player", 1, 0, "PlayerBackend");
|
||||
}
|
||||
#else
|
||||
qmlRegisterType<MPVNoFBOBackend>("player", 1, 0, "PlayerBackend");
|
||||
#endif
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
launcherLogger->info("Loading player...");
|
||||
|
||||
|
|
|
@ -8,9 +8,12 @@ import player 1.0
|
|||
Dialog {
|
||||
id: settingsDialog
|
||||
title: translate.getTranslation("SETTINGS", i18n.language)
|
||||
height: Math.max(480, childrenRect.height)
|
||||
height: 100
|
||||
width: 720
|
||||
modality: Qt.NonModal
|
||||
|
||||
signal done;
|
||||
|
||||
ScrollView {
|
||||
id: content
|
||||
height: parent.height
|
||||
|
@ -147,6 +150,10 @@ Dialog {
|
|||
fontInput.setFont()
|
||||
subtitlesFontSizeInput.setSubtitlesFontSize()
|
||||
uiFadeTimeInput.setUIFadeTime()
|
||||
settingsDialog.done()
|
||||
}
|
||||
}
|
||||
Component.onCompleted: {
|
||||
settingsDialog.open()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,8 +117,16 @@ MenuBar {
|
|||
id: playlistDialog
|
||||
}
|
||||
|
||||
SettingsDialog {
|
||||
id: settingsDialog
|
||||
Loader {
|
||||
id: settingsDialogLoader
|
||||
active: false
|
||||
source: "SettingsDialog.qml"
|
||||
}
|
||||
Connections {
|
||||
target: settingsDialogLoader.item
|
||||
onDone: {
|
||||
settingsDialogLoader.active = false
|
||||
}
|
||||
}
|
||||
|
||||
delegate: MenuBarItem {
|
||||
|
@ -475,7 +483,7 @@ MenuBar {
|
|||
Action {
|
||||
text: translate.getTranslation("SETTINGS", i18n.language)
|
||||
onTriggered: {
|
||||
settingsDialog.open()
|
||||
settingsDialogLoader.active = true
|
||||
}
|
||||
}
|
||||
Action {
|
||||
|
|
38
src/registerTypes.cpp
Normal file
38
src/registerTypes.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#ifndef DISABLE_MPV_RENDER_API
|
||||
#include "Backends/MPV/MPVBackend.hpp"
|
||||
#endif
|
||||
#include "Backends/MPVNoFBO/MPVNoFBOBackend.hpp"
|
||||
#include "Process.h"
|
||||
#include "ThumbnailCache.h"
|
||||
#include "enums.hpp"
|
||||
#include "qmldebugger.h"
|
||||
#include "utils.hpp"
|
||||
#include <QSettings>
|
||||
|
||||
void registerTypes() {
|
||||
QSettings settings;
|
||||
|
||||
|
||||
qmlRegisterUncreatableMetaObject(
|
||||
Enums::staticMetaObject, "player", 1, 0, "Enums", "Error: only enums");
|
||||
qRegisterMetaType<Enums::PlayStatus>("Enums.PlayStatus");
|
||||
qRegisterMetaType<Enums::VolumeStatus>("Enums.VolumeStatus");
|
||||
qRegisterMetaType<Enums::Backends>("Enums.Backends");
|
||||
qRegisterMetaType<Enums::Commands>("Enums.Commands");
|
||||
qmlRegisterType<Process>("player", 1, 0, "Process");
|
||||
|
||||
qmlRegisterType<QMLDebugger>("player", 1, 0, "QMLDebugger");
|
||||
qmlRegisterType<ThumbnailCache>("player", 1, 0, "ThumbnailCache");
|
||||
|
||||
qmlRegisterType<UtilsClass>("player", 1, 0, "Utils");
|
||||
|
||||
#ifndef DISABLE_MPV_RENDER_API
|
||||
if (settings.value("Backend/fbo", true).toBool()) {
|
||||
qmlRegisterType<MPVBackend>("player", 1, 0, "PlayerBackend");
|
||||
} else {
|
||||
qmlRegisterType<MPVNoFBOBackend>("player", 1, 0, "PlayerBackend");
|
||||
}
|
||||
#else
|
||||
qmlRegisterType<MPVNoFBOBackend>("player", 1, 0, "PlayerBackend");
|
||||
#endif
|
||||
}
|
|
@ -37,7 +37,7 @@ launchAboutQt()
|
|||
}
|
||||
|
||||
// https://www.youtube.com/watch?v=nXaxk27zwlk&feature=youtu.be&t=56m34s
|
||||
inline const int
|
||||
inline int
|
||||
fast_mod(const int input, const int ceil)
|
||||
{
|
||||
return input >= ceil ? input % ceil : input;
|
||||
|
|
258
upload.sh
258
upload.sh
|
@ -1,258 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set +x # Do not leak information
|
||||
|
||||
# Exit immediately if one of the files given as arguments is not there
|
||||
# because we don't want to delete the existing release if we don't have
|
||||
# the new files that should be uploaded
|
||||
for file in "$@"
|
||||
do
|
||||
if [ ! -e "$file" ]
|
||||
then echo "$file is missing, giving up." >&2; exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "No artifacts to use for release, giving up."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if command -v sha256sum >/dev/null 2>&1 ; then
|
||||
shatool="sha256sum"
|
||||
elif command -v shasum >/dev/null 2>&1 ; then
|
||||
shatool="shasum -a 256" # macOS fallback
|
||||
else
|
||||
echo "Neither sha256sum nor shasum is available, cannot check hashes"
|
||||
fi
|
||||
|
||||
# The calling script (usually .travis.yml) can set a suffix to be used for
|
||||
# the tag and release name. This way it is possible to have a release for
|
||||
# the output of the CI/CD pipeline (marked as 'continuous') and also test
|
||||
# builds for other branches.
|
||||
# If this build was triggered by a tag, call the result a Release
|
||||
if [ ! -z "$UPLOADTOOL_SUFFIX" ] ; then
|
||||
if [ "$UPLOADTOOL_SUFFIX" = "$TRAVIS_TAG" ] ; then
|
||||
RELEASE_NAME="$TRAVIS_TAG"
|
||||
RELEASE_TITLE="Release build ($TRAVIS_TAG)"
|
||||
is_prerelease="false"
|
||||
else
|
||||
RELEASE_NAME="continuous-$UPLOADTOOL_SUFFIX"
|
||||
RELEASE_TITLE="Continuous build ($UPLOADTOOL_SUFFIX)"
|
||||
is_prerelease="true"
|
||||
fi
|
||||
else
|
||||
if [ "$TRAVIS_TAG" != "" ]; then
|
||||
RELEASE_NAME="$TRAVIS_TAG"
|
||||
RELEASE_TITLE="Release build ($TRAVIS_TAG)"
|
||||
is_prerelease="false"
|
||||
else
|
||||
RELEASE_NAME="continuous" # Do not use "latest" as it is reserved by GitHub
|
||||
RELEASE_TITLE="Continuous build"
|
||||
is_prerelease="true"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$ARTIFACTORY_BASE_URL" != "" ]; then
|
||||
echo "ARTIFACTORY_BASE_URL set, trying to upload to artifactory"
|
||||
|
||||
if [ "$ARTIFACTORY_API_KEY" == "" ]; then
|
||||
echo "Please set ARTIFACTORY_API_KEY"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
files="$@"
|
||||
|
||||
# artifactory doesn't support any kind of "artifact description", so we're uploading a text file containing the
|
||||
# relevant details along with the other artifacts
|
||||
tempdir=$(mktemp -d)
|
||||
info_file="$tempdir"/build-info.txt
|
||||
echo "Travis CI build log: https://travis-ci.org/$TRAVIS_REPO_SLUG/builds/$TRAVIS_BUILD_ID/" > "$info_file"
|
||||
files+=("$info_file")
|
||||
|
||||
set +x
|
||||
|
||||
for file in ${files[@]}; do
|
||||
url="${ARTIFACTORY_BASE_URL}/travis-${TRAVIS_BUILD_NUMBER}/"$(basename "$file")
|
||||
md5sum=$(md5sum "$file" | cut -d' ' -f1)
|
||||
sha1sum=$(sha1sum "$file" | cut -d' ' -f1)
|
||||
sha256sum=$(sha256sum "$file" | cut -d' ' -f1)
|
||||
echo "Uploading $file to $url"
|
||||
hashsums=(-H "X-Checksum-Md5:$md5sum")
|
||||
hashsums+=(-H "X-Checksum-Sha1:$sha1sum")
|
||||
hashsums+=(-H "X-Checksum-Sha256:$sha256sum")
|
||||
if ! curl -H 'X-JFrog-Art-Api:'"$ARTIFACTORY_API_KEY" "${hashsums[@]}" -T "$file" "$url"; then
|
||||
echo "Failed to upload file, exiting"
|
||||
rm -r "$tempdir"
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
echo "MD5 checksum: $md5sum"
|
||||
echo "SHA1 checksum: $sha1sum"
|
||||
echo "SHA256 checksum: $sha256sum"
|
||||
done
|
||||
rm -r "$tempdir"
|
||||
fi
|
||||
|
||||
if [ "$TRAVIS_EVENT_TYPE" == "pull_request" ] ; then
|
||||
echo "Release uploading disabled for pull requests"
|
||||
if [ "$ARTIFACTORY_BASE_URL" != "" ]; then
|
||||
echo "Releases have already been uploaded to Artifactory, exiting"
|
||||
exit 0
|
||||
else
|
||||
echo "Release uploading disabled for pull requests, uploading to transfer.sh instead"
|
||||
rm -f ./uploaded-to
|
||||
for FILE in "$@" ; do
|
||||
BASENAME="$(basename "${FILE}")"
|
||||
curl --upload-file $FILE "https://transfer.sh/$BASENAME" > ./one-upload
|
||||
echo "$(cat ./one-upload)" # this way we get a newline
|
||||
echo -n "$(cat ./one-upload)\\n" >> ./uploaded-to # this way we get a \n but no newline
|
||||
done
|
||||
fi
|
||||
# review_url="https://api.github.com/repos/${TRAVIS_REPO_SLUG}/pulls/${TRAVIS_PULL_REQUEST}/reviews"
|
||||
# if [ -z $UPLOADTOOL_PR_BODY ] ; then
|
||||
# body="Travis CI has created build artifacts for this PR here:"
|
||||
# else
|
||||
# body="$UPLOADTOOL_PR_BODY"
|
||||
# fi
|
||||
# body="$body\n$(cat ./uploaded-to)\nThe link(s) will expire 14 days from now."
|
||||
# review_comment=$(curl -X POST \
|
||||
# --header "Authorization: token ${GITHUB_TOKEN}" \
|
||||
# --data '{"commit_id": "'"$TRAVIS_COMMIT"'","body": "'"$body"'","event": "COMMENT"}' \
|
||||
# $review_url)
|
||||
# if echo $review_comment | grep -q "Bad credentials" 2>/dev/null ; then
|
||||
# echo '"Bad credentials" response for --data {"commit_id": "'"$TRAVIS_COMMIT"'","body": "'"$body"'","event": "COMMENT"}'
|
||||
# fi
|
||||
$shatool "$@"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -z "$TRAVIS_REPO_SLUG" ] ; then
|
||||
# We are running on Travis CI
|
||||
echo "Running on Travis CI"
|
||||
echo "TRAVIS_COMMIT: $TRAVIS_COMMIT"
|
||||
REPO_SLUG="$TRAVIS_REPO_SLUG"
|
||||
if [ -z "$GITHUB_TOKEN" ] ; then
|
||||
echo "\$GITHUB_TOKEN missing, please set it in the Travis CI settings of this project"
|
||||
echo "You can get one from https://github.com/settings/tokens"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# We are not running on Travis CI
|
||||
echo "Not running on Travis CI"
|
||||
if [ -z "$REPO_SLUG" ] ; then
|
||||
read -r -p "Repo Slug (GitHub and Travis CI username/reponame): " REPO_SLUG
|
||||
fi
|
||||
if [ -z "$GITHUB_TOKEN" ] ; then
|
||||
read -r -s -p "Token (https://github.com/settings/tokens): " GITHUB_TOKEN
|
||||
fi
|
||||
fi
|
||||
|
||||
tag_url="https://api.github.com/repos/$REPO_SLUG/git/refs/tags/$RELEASE_NAME"
|
||||
tag_infos=$(curl -XGET --header "Authorization: token ${GITHUB_TOKEN}" "${tag_url}")
|
||||
echo "tag_infos: $tag_infos"
|
||||
tag_sha=$(echo "$tag_infos" | grep '"sha":' | head -n 1 | cut -d '"' -f 4 | cut -d '{' -f 1)
|
||||
echo "tag_sha: $tag_sha"
|
||||
|
||||
release_url="https://api.github.com/repos/$REPO_SLUG/releases/tags/$RELEASE_NAME"
|
||||
echo "Getting the release ID..."
|
||||
echo "release_url: $release_url"
|
||||
release_infos=$(curl -XGET --header "Authorization: token ${GITHUB_TOKEN}" "${release_url}")
|
||||
echo "release_infos: $release_infos"
|
||||
release_id=$(echo "$release_infos" | grep "\"id\":" | head -n 1 | tr -s " " | cut -f 3 -d" " | cut -f 1 -d ",")
|
||||
echo "release ID: $release_id"
|
||||
upload_url=$(echo "$release_infos" | grep '"upload_url":' | head -n 1 | cut -d '"' -f 4 | cut -d '{' -f 1)
|
||||
echo "upload_url: $upload_url"
|
||||
release_url=$(echo "$release_infos" | grep '"url":' | head -n 1 | cut -d '"' -f 4 | cut -d '{' -f 1)
|
||||
echo "release_url: $release_url"
|
||||
target_commit_sha=$(echo "$release_infos" | grep '"target_commitish":' | head -n 1 | cut -d '"' -f 4 | cut -d '{' -f 1)
|
||||
echo "target_commit_sha: $target_commit_sha"
|
||||
|
||||
if [ "$TRAVIS_COMMIT" != "$target_commit_sha" ] ; then
|
||||
|
||||
echo "TRAVIS_COMMIT != target_commit_sha, hence deleting $RELEASE_NAME..."
|
||||
|
||||
if [ ! -z "$release_id" ]; then
|
||||
delete_url="https://api.github.com/repos/$REPO_SLUG/releases/$release_id"
|
||||
echo "Delete the release..."
|
||||
echo "delete_url: $delete_url"
|
||||
curl -XDELETE \
|
||||
--header "Authorization: token ${GITHUB_TOKEN}" \
|
||||
"${delete_url}"
|
||||
fi
|
||||
|
||||
# echo "Checking if release with the same name is still there..."
|
||||
# echo "release_url: $release_url"
|
||||
# curl -XGET --header "Authorization: token ${GITHUB_TOKEN}" \
|
||||
# "$release_url"
|
||||
|
||||
if [ "$is_prerelease" = "true" ] ; then
|
||||
# if this is a continuous build tag, then delete the old tag
|
||||
# in preparation for the new release
|
||||
echo "Delete the tag..."
|
||||
delete_url="https://api.github.com/repos/$REPO_SLUG/git/refs/tags/$RELEASE_NAME"
|
||||
echo "delete_url: $delete_url"
|
||||
curl -XDELETE \
|
||||
--header "Authorization: token ${GITHUB_TOKEN}" \
|
||||
"${delete_url}"
|
||||
fi
|
||||
|
||||
echo "Create release..."
|
||||
|
||||
if [ -z "$TRAVIS_BRANCH" ] ; then
|
||||
TRAVIS_BRANCH="master"
|
||||
fi
|
||||
|
||||
if [ ! -z "$TRAVIS_JOB_ID" ] ; then
|
||||
if [ -z "${UPLOADTOOL_BODY+x}" ] ; then
|
||||
# TODO: The host could be travis-ci.org (legacy open source) or travis-ci.com (subscription or latest open source).
|
||||
BODY="Travis CI build log: https://travis-ci.org/$REPO_SLUG/builds/$TRAVIS_BUILD_ID/"
|
||||
else
|
||||
BODY="$UPLOADTOOL_BODY"
|
||||
fi
|
||||
else
|
||||
BODY="$UPLOADTOOL_BODY"
|
||||
fi
|
||||
|
||||
release_infos=$(curl -H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
--data '{"tag_name": "'"$RELEASE_NAME"'","target_commitish": "'"$TRAVIS_COMMIT"'","name": "'"$RELEASE_TITLE"'","body": "'"$BODY"'","draft": false,"prerelease": '$is_prerelease'}' "https://api.github.com/repos/$REPO_SLUG/releases")
|
||||
|
||||
echo "$release_infos"
|
||||
|
||||
unset upload_url
|
||||
upload_url=$(echo "$release_infos" | grep '"upload_url":' | head -n 1 | cut -d '"' -f 4 | cut -d '{' -f 1)
|
||||
echo "upload_url: $upload_url"
|
||||
|
||||
unset release_url
|
||||
release_url=$(echo "$release_infos" | grep '"url":' | head -n 1 | cut -d '"' -f 4 | cut -d '{' -f 1)
|
||||
echo "release_url: $release_url"
|
||||
|
||||
fi # if [ "$TRAVIS_COMMIT" != "$tag_sha" ]
|
||||
|
||||
if [ -z "$release_url" ] ; then
|
||||
echo "Cannot figure out the release URL for $RELEASE_NAME"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Upload binaries to the release..."
|
||||
|
||||
for FILE in "$@" ; do
|
||||
FULLNAME="${FILE}"
|
||||
BASENAME="$(basename "${FILE}")"
|
||||
curl -H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
-H "Accept: application/vnd.github.manifold-preview" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary @$FULLNAME \
|
||||
"$upload_url?name=$BASENAME"
|
||||
echo ""
|
||||
done
|
||||
|
||||
$shatool "$@"
|
||||
|
||||
if [ "$TRAVIS_COMMIT" != "$tag_sha" ] ; then
|
||||
echo "Publish the release..."
|
||||
|
||||
release_infos=$(curl -H "Authorization: token ${GITHUB_TOKEN}" \
|
||||
--data '{"draft": false}' "$release_url")
|
||||
|
||||
echo "$release_infos"
|
||||
fi # if [ "$TRAVIS_COMMIT" != "$tag_sha" ]
|
Loading…
Reference in a new issue