Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for 0.1.0 release #345

Merged
merged 7 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 46 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,57 @@ script:
#- make vet
- make it
after_success:
- if [ "$TRAVIS_BRANCH" = "develop" ]; then export TAG_SUFFIX="_dev"; elif [ "$TRAVIS_BRANCH" != "master" ]; then export TAG_SUFFIX="_$TRAVIS_BRANCH"; fi
- export STASH_VERSION="v0.0.0-alpha${TAG_SUFFIX}"
- docker pull stashapp/compiler:develop
- sh ./scripts/cross-compile.sh ${STASH_VERSION}
- sh ./scripts/cross-compile.sh
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then sh ./scripts/upload-pull-request.sh; fi'
before_deploy:
- if [ "$TRAVIS_BRANCH" = "develop" ]; then export TAG_SUFFIX="_dev"; fi
- git tag -f ${STASH_VERSION}
- git push -f --tags
# push the latest tag when on the develop branch
- if [ "$TRAVIS_BRANCH" = "develop" ]; then git tag -f latest_develop; git push -f --tags; fi
- export RELEASE_DATE=$(date +'%Y-%m-%d %H:%M:%S %Z')
- export STASH_VERSION=$(git describe --tags --exclude latest_develop)
# set TRAVIS_TAG explcitly to the version so that it doesn't pick up latest_develop
- if [ "$TRAVIS_BRANCH" = "master"]; then export TRAVIS_TAG=${STASH_VERSION}; fi
deploy:
provider: releases
api_key:
secure: tGJ2q62CfPdayid2qEtW2aGRhMgCl3lBXYYQqp3eH0vFgIIf6cs7IDX7YC/x3XKMEQ/iMLZmtCXZvSTqNrD6Sk7MSnt30GIs+4uxIZDnnd8mV5X3K4n4gjD+NAORc4DrQBvUGrYMKJsR5gtkH0nu6diWb1o1If7OiJEuCPRhrmQYcza7NUdABnA9Z2wn2RNUV9Ga33WUCqLMEU5GtNBlfQPiP/khCQrqn/ocR6wUjYut3J6YagzqH4wsfJi3glHyWtowcNIw1LZi5zFxHD/bRBT4Tln7yypkjWNq9eQILA6i6kRUGf7ggyTx26/k8n4tnu+QD0vVh4EcjlThpU/LGyUXzKrrxjRwaDZnM0oYxg5AfHcBuAiAdo0eWnV3lEWRfTJMIVb9MPf4qDmzR4RREfB5OXOxwq3ODeCcJE8sTIMD/wBPZrlqS/QrRpND2gn2X4snkVukN9t9F4CMTFMtVSzFV7TDJW5E5Lq6VEExulteQhs6kcK9NRPNAaLgRQAw7X9kVWfDtiGUP+fE2i8F9Bo8bm7sOT5O5VPMPykx3EgeNg1IqIgMTCsMlhMJT4xBJoQUgmd2wWyf3Ryw+P+sFgdb5Sd7+lFgJBjMUUoOxMxAOiEgdFvCXcr+/Udyz2RdtetU1/6VzXzLPcKOw0wubZeBkISqu7o9gpfdMP9Eq00=
file:
- dist/stash-osx
- dist/stash-win.exe
- dist/stash-linux
- dist/stash-pi
skip_cleanup: true
overwrite: true
body: ${RELEASE_DATE}
on:
repo: stashapp/stash
all_branches: true
condition: $TRAVIS_BRANCH =~ ^(master|develop)$
# latest develop release
- provider: releases
api_key:
secure: tGJ2q62CfPdayid2qEtW2aGRhMgCl3lBXYYQqp3eH0vFgIIf6cs7IDX7YC/x3XKMEQ/iMLZmtCXZvSTqNrD6Sk7MSnt30GIs+4uxIZDnnd8mV5X3K4n4gjD+NAORc4DrQBvUGrYMKJsR5gtkH0nu6diWb1o1If7OiJEuCPRhrmQYcza7NUdABnA9Z2wn2RNUV9Ga33WUCqLMEU5GtNBlfQPiP/khCQrqn/ocR6wUjYut3J6YagzqH4wsfJi3glHyWtowcNIw1LZi5zFxHD/bRBT4Tln7yypkjWNq9eQILA6i6kRUGf7ggyTx26/k8n4tnu+QD0vVh4EcjlThpU/LGyUXzKrrxjRwaDZnM0oYxg5AfHcBuAiAdo0eWnV3lEWRfTJMIVb9MPf4qDmzR4RREfB5OXOxwq3ODeCcJE8sTIMD/wBPZrlqS/QrRpND2gn2X4snkVukN9t9F4CMTFMtVSzFV7TDJW5E5Lq6VEExulteQhs6kcK9NRPNAaLgRQAw7X9kVWfDtiGUP+fE2i8F9Bo8bm7sOT5O5VPMPykx3EgeNg1IqIgMTCsMlhMJT4xBJoQUgmd2wWyf3Ryw+P+sFgdb5Sd7+lFgJBjMUUoOxMxAOiEgdFvCXcr+/Udyz2RdtetU1/6VzXzLPcKOw0wubZeBkISqu7o9gpfdMP9Eq00=
file:
- dist/stash-osx
- dist/stash-win.exe
- dist/stash-linux
- dist/stash-pi
skip_cleanup: true
overwrite: true
name: "${STASH_VERSION}: Latest development build"
body: ${RELEASE_DATE}\n This is always the latest committed version on the develop branch. Use as your own risk!
prerelease: true
on:
repo: stashapp/stash
branches: develop
# official master release - only build when tagged
- provider: releases
api_key:
secure: tGJ2q62CfPdayid2qEtW2aGRhMgCl3lBXYYQqp3eH0vFgIIf6cs7IDX7YC/x3XKMEQ/iMLZmtCXZvSTqNrD6Sk7MSnt30GIs+4uxIZDnnd8mV5X3K4n4gjD+NAORc4DrQBvUGrYMKJsR5gtkH0nu6diWb1o1If7OiJEuCPRhrmQYcza7NUdABnA9Z2wn2RNUV9Ga33WUCqLMEU5GtNBlfQPiP/khCQrqn/ocR6wUjYut3J6YagzqH4wsfJi3glHyWtowcNIw1LZi5zFxHD/bRBT4Tln7yypkjWNq9eQILA6i6kRUGf7ggyTx26/k8n4tnu+QD0vVh4EcjlThpU/LGyUXzKrrxjRwaDZnM0oYxg5AfHcBuAiAdo0eWnV3lEWRfTJMIVb9MPf4qDmzR4RREfB5OXOxwq3ODeCcJE8sTIMD/wBPZrlqS/QrRpND2gn2X4snkVukN9t9F4CMTFMtVSzFV7TDJW5E5Lq6VEExulteQhs6kcK9NRPNAaLgRQAw7X9kVWfDtiGUP+fE2i8F9Bo8bm7sOT5O5VPMPykx3EgeNg1IqIgMTCsMlhMJT4xBJoQUgmd2wWyf3Ryw+P+sFgdb5Sd7+lFgJBjMUUoOxMxAOiEgdFvCXcr+/Udyz2RdtetU1/6VzXzLPcKOw0wubZeBkISqu7o9gpfdMP9Eq00=
file:
- dist/stash-osx
- dist/stash-win.exe
- dist/stash-linux
- dist/stash-pi
# make the release a draft so the maintainers can confirm before releasing
draft: true
skip_cleanup: true
overwrite: true
# don't write the body. To be done manually for now. In future we might
# want to generate the changelog or get it from a file
name: ${STASH_VERSION}
on:
repo: stashapp/stash
branches: master
tags: true
# make sure we don't release using the latest_develop tag
condition: $TRAVIS_TAG != latest_develop

branches:
only:
- master
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ release: generate ui build
build:
$(eval DATE := $(shell go run scripts/getDate.go))
$(eval GITHASH := $(shell git rev-parse --short HEAD))
$(SET) CGO_ENABLED=1 $(SEPARATOR) go build -mod=vendor -v -ldflags "-X 'github.com/stashapp/stash/pkg/api.buildstamp=$(DATE)' -X 'github.com/stashapp/stash/pkg/api.githash=$(GITHASH)'"
$(eval STASH_VERSION := $(shell git describe --tags --exclude latest_develop))
$(SET) CGO_ENABLED=1 $(SEPARATOR) go build -mod=vendor -v -ldflags "-X 'github.com/stashapp/stash/pkg/api.version=$(STASH_VERSION)' -X 'github.com/stashapp/stash/pkg/api.buildstamp=$(DATE)' -X 'github.com/stashapp/stash/pkg/api.githash=$(GITHASH)'"

install:
packr2 install
Expand Down
2 changes: 1 addition & 1 deletion docker/production/x86_64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/*
WORKDIR /
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl -L -o /stash $(curl -s https://api.github.com/repos/stashapp/stash/releases | grep -F 'stash-linux' | grep download | head -n 1 | cut -d'"' -f4) && \
RUN curl -L -o /stash $(curl -s https://api.github.com/repos/stashapp/stash/releases | grep -F 'latest_develop/stash-linux' | grep download | head -n 1 | cut -d'"' -f4) && \
chmod +x /stash && \
curl -o /ffmpeg.tar.xz https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz && \
tar xf /ffmpeg.tar.xz && \
Expand Down
111 changes: 56 additions & 55 deletions pkg/api/check_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ package api
import (
"encoding/json"
"fmt"
"github.com/stashapp/stash/pkg/logger"
"io/ioutil"
"net/http"
"regexp"
"runtime"
"time"

"github.com/stashapp/stash/pkg/logger"
)

//we use the github REST V3 API as no login is required
const apiURL string = "https://api.github.com/repos/stashapp/stash/tags"
const apiReleases string = "https://api.github.com/repos/stashapp/stash/releases"
const apiAcceptHeader string = "application/vnd.github.v3+json"
const developmentTag string = "latest_develop"

var stashReleases = func() map[string]string {
return map[string]string{
Expand All @@ -24,17 +26,6 @@ var stashReleases = func() map[string]string {
}
}

type githubTagResponse struct {
Name string
Zipball_url string
Tarball_url string
Commit struct {
Sha string
Url string
}
Node_id string
}

type githubReleasesResponse struct {
Url string
Assets_url string
Expand Down Expand Up @@ -93,74 +84,85 @@ type githubAsset struct {
Browser_download_url string
}

//gets latest version (git commit hash) from github API
//the repo's tags are used to find the latest version
//of the "master" or "develop" branch
// GetLatestVersion gets latest version (git commit hash) from github API
// If running a build from the "master" branch, then the latest full release
// is used, otherwise it uses the release that is tagged with "latest_develop"
// which is the latest pre-release build.
func GetLatestVersion(shortHash bool) (latestVersion string, latestRelease string, err error) {

platform := fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
wantedRelease := stashReleases()[platform]

branch, _, _ := GetVersion()
if branch == "" {
version, _, _ := GetVersion()
if version == "" {
return "", "", fmt.Errorf("Stash doesn't have a version. Version check not supported.")
}

// if the version is suffixed with -x-xxxx, then we are running a development build
usePreRelease := false
re := regexp.MustCompile(`-\d+-g\w+$`)
if re.MatchString(version) {
usePreRelease = true
}

client := &http.Client{
Timeout: 3 * time.Second,
}

req, _ := http.NewRequest("GET", apiReleases, nil)
url := apiReleases
if !usePreRelease {
// just get the latest full release
url += "/latest"
} else {
// get the release tagged with the development tag
url += "/tags/" + developmentTag
}
req, _ := http.NewRequest("GET", url, nil)

req.Header.Add("Accept", apiAcceptHeader) // gh api recommendation , send header with api version
response, err := client.Do(req)

input := make([]githubReleasesResponse, 0)
release := githubReleasesResponse{}

if response.StatusCode != http.StatusOK {
return "", "", fmt.Errorf("Github API request failed: %s", response.Status)
}

if err != nil {
return "", "", fmt.Errorf("Github API request failed: %s", err)
} else {
}

defer response.Body.Close()
defer response.Body.Close()

data, err := ioutil.ReadAll(response.Body)
if err != nil {
return "", "", fmt.Errorf("Github API read response failed: %s", err)
data, err := ioutil.ReadAll(response.Body)
if err != nil {
return "", "", fmt.Errorf("Github API read response failed: %s", err)
}
err = json.Unmarshal(data, &release)
if err != nil {
return "", "", fmt.Errorf("Unmarshalling Github API response failed: %s", err)
}

if release.Prerelease == usePreRelease {
if shortHash {
latestVersion = release.Target_commitish[0:7] //shorthash is first 7 digits of git commit hash
} else {
err = json.Unmarshal(data, &input)
if err != nil {
return "", "", fmt.Errorf("Unmarshalling Github API response failed: %s", err)
} else {

for _, ghApi := range input {
if ghApi.Tag_name == branch {

if shortHash {
latestVersion = ghApi.Target_commitish[0:7] //shorthash is first 7 digits of git commit hash
} else {
latestVersion = ghApi.Target_commitish
}
if wantedRelease != "" {
for _, asset := range ghApi.Assets {
if asset.Name == wantedRelease {
latestRelease = asset.Browser_download_url
break
}

}
}
break
}
latestVersion = release.Target_commitish
}
if wantedRelease != "" {
for _, asset := range release.Assets {
if asset.Name == wantedRelease {
latestRelease = asset.Browser_download_url
break
}

}
}
if latestVersion == "" {
return "", "", fmt.Errorf("No version found for \"%s\"", branch)
}
}
return latestVersion, latestRelease, nil

if latestVersion == "" {
return "", "", fmt.Errorf("No version found for \"%s\"", version)
}
return latestVersion, latestRelease, nil
}

func printLatestVersion() {
Expand All @@ -175,5 +177,4 @@ func printLatestVersion() {
logger.Infof("New version: (%s) available.", latest)
}
}

}
3 changes: 1 addition & 2 deletions scripts/cross-compile.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/sh

STASH_VERSION="$1"

DATE=`go run -mod=vendor scripts/getDate.go`
GITHASH=`git rev-parse --short HEAD`
STASH_VERSION=`git describe --tags --exclude latest_develop`
VERSION_FLAGS="-X 'github.com/stashapp/stash/pkg/api.version=$STASH_VERSION' -X 'github.com/stashapp/stash/pkg/api.buildstamp=$DATE' -X 'github.com/stashapp/stash/pkg/api.githash=$GITHASH'"
SETUP="export GO111MODULE=on; export CGO_ENABLED=1;"
WINDOWS="GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ packr2 build -o dist/stash-win.exe -ldflags \"-extldflags '-static' $VERSION_FLAGS\" -tags extended -v -mod=vendor;"
Expand Down
5 changes: 3 additions & 2 deletions scripts/upload-pull-request.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ uploadFile()
{
FILE=$1
BASENAME="$(basename "${FILE}")"
uploadedTo=`curl --upload-file $FILE "https://transfer.sh/$BASENAME"`
# abort if it takes more than two minutes to upload
uploadedTo=`curl -m 120 --upload-file $FILE "https://transfer.sh/$BASENAME"`
echo "$BASENAME uploaded to url: $uploadedTo"
}

uploadFile "dist/stash-osx"
uploadFile "dist/stash-win.exe"
uploadFile "dist/stash-linux"
uploadFile "dist/stash-linux"