Compare commits

..
Author SHA1 Message Date
jobevers 26f5d08567 non-version tags don't break the build 2017-02-22 14:54:09 -06:00
jobevers d1c308181b add debugging info to curl 2017-02-22 13:33:37 -06:00
jobevers ed053552c8 update submodules 2017-02-22 13:14:47 -06:00
jobevers c03eb3b736 fix template for changelog 2017-02-22 13:12:55 -06:00
jobevers 7d1bfb4c35 update submodules 2017-02-22 13:08:45 -06:00
jobevers 01955c312c add changelog so it can be committed 2017-02-22 13:06:38 -06:00
jobevers be9d99f482 Bump version: 0.9.0rc8 → 0.9.0rc9 2017-02-22 12:51:14 -06:00
jobevers 5c1803aaf8 Misc release imrovements
* force submodule updates
* missing changelog is now only a warning
* allow push to be skipped
2017-02-22 12:31:03 -06:00
jobevers 9504be7146 add more logging 2017-02-22 11:50:39 -06:00
jobevers eda71a50ff sync submodules to head of branch 2017-02-22 11:45:44 -06:00
jobevers 8234d6cc25 Misc improvements to release script 2017-02-22 11:21:21 -06:00
jobevers 605c0eb8ab try parsing changelog 2017-02-21 22:29:23 -06:00
jobevers d19e436d04 update submodules 2017-02-21 21:05:33 -06:00
jobevers c159f214ab logging.basicConfig needs a kwarg 2017-02-21 16:53:44 -06:00
jobevers 48b665a3be update lbry 2017-02-21 15:30:59 -06:00
jobevers 3d46983500 update lbry submodule 2017-02-21 15:16:16 -06:00
jobevers 05f94a95ed move zipping the daemon to separate script 2017-02-21 15:13:41 -06:00
jobevers 135742c87e Bump version: 0.9.0rc7 → 0.9.0rc8 2017-02-21 13:57:19 -06:00
jobevers c7cea9c94f handle case where lbry doesn't have changes 2017-02-21 13:48:29 -06:00
jobevers 77ce04b377 warn if bumpversion isn't installed 2017-02-21 13:33:11 -06:00
jobevers e28fab0696 warn if bumpversion isn't installed 2017-02-21 13:32:21 -06:00
Job Evers‐Meltzer b5fcc126d8 Merge pull request #5 from lbryio/test-electron-release
Add release script
2017-02-21 13:28:00 -06:00
jobevers a9b32bac9f update submodules to master and development branches 2017-02-21 13:24:10 -06:00
jobevers b03f652d5e add check for GH_TOKEN 2017-02-21 12:13:44 -06:00
Jeremy Kauffman 48e9226cac better intro 2017-02-21 13:12:21 -05:00
Jeremy Kauffman 4a68835bba minor readme changes 2017-02-21 13:10:20 -05:00
jobevers 25febd1880 Merge remote-tracking branch 'origin/master' into test-electron-release 2017-02-21 11:25:34 -06:00
jobevers 5d55af0a77 update submodules 2017-02-21 11:07:14 -06:00
jobevers 4e431dc6fd add release script 2017-02-20 21:58:29 -06:00
jobevers 445033f34a have to search for draft releases 2017-02-20 21:55:53 -06:00
jobevers c0b34fe119 fix appveyor.yml 2017-02-20 21:15:16 -06:00
jobevers 47c88a7604 Bump version: 0.9.0rc6 → 0.9.0rc7 2017-02-20 21:12:39 -06:00
jobevers 6a95a37266 add lbrynet-daemon to release process 2017-02-20 21:00:54 -06:00
jobevers de5ecbe4a1 more version stuff 2017-02-20 19:24:08 -06:00
jobevers 7b13e8e65a update version 2017-02-20 19:20:29 -06:00
jobevers 2a94a56765 update lbryum 2017-02-20 18:36:05 -06:00
jobevers abf1e49abe update lbry 2017-02-20 18:22:28 -06:00
jobevers bd1bd96e5e working on a release process 2017-02-20 16:31:17 -06:00
jobevers 980b1f710c update readme 2017-02-20 14:50:06 -06:00
jobevers 4e2e2abe0f update submodules 2017-02-20 13:29:51 -06:00
jobevers f09bf620b2 allow render process to trigger a shutdown 2017-02-20 12:59:03 -06:00
jobevers 0f65170361 change appveyor artifact 2017-02-17 14:13:55 -06:00
jobevers 2af80c69ae try building exe installer on windows 2017-02-17 14:06:57 -06:00
jobevers 7b1dc2c5a0 update submodules 2017-02-17 09:47:08 -06:00
jobevers f6a28df636 better update handling 2017-02-16 21:26:57 -06:00
jobevers 592a48e412 remove system label on release
the label was useful for lbrynet-daemon because there each
file was identical.  Now that the filenames are unique, we can
remove it.
2017-02-16 15:35:31 -06:00
jobevers 5b95a3ab9d update submodules 2017-02-16 14:18:53 -06:00
jobevers 48cfdb1ab8 sync lbrynet and client versions 2017-02-16 12:19:35 -06:00
jobevers 4763d29a4c set the build type 2017-02-15 18:50:38 -06:00
jobevers 9a21135223 another edit for testing 2017-02-15 15:50:16 -06:00
jobevers 3e49fd3758 dummy commit for testing release 2017-02-15 14:38:37 -06:00
19 changed files with 719 additions and 246 deletions

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
[bumpversion]
current_version = 0.9.0rc9
commit = True
tag = True
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)((?P<release>[a-z]+)(?P<candidate>\d+))?
serialize =
{major}.{minor}.{patch}{release}{candidate}
{major}.{minor}.{patch}
[bumpversion:part:release]
optional_value = production
values =
rc
production
[bumpversion:file:app/package.json]
+2 -1
View File
@@ -6,4 +6,5 @@ dist
lbrynet/build
lbrynet/venv
.#*
build_venv
build_venv
*.pyc
+28 -19
View File
@@ -1,33 +1,42 @@
# LBRY Electron
# LBRY App
An electron version of the LBRY application.
This is a graphical browser for the decentralized content marketplace provided by the [LBRY](https://lbry.io) protocol. It is essentially the [lbry daemon](https://github.com/lbryio/lbry) bundled with the [lbry web ui](https://github.com/lbryio/lbry-web-ui) in an [Electron](http://electron.atom.io/) application.
This repo uses submodules, so clone it using --recursive
## Installing
## Setup
Check out the [release page](https://github.com/lbryio/lbry-app/releases/latest) to download a binary.
The lbrynet library needs to be installed along with pyinstaller, and you
need everything to be able to build the lbry-web-ui
To install from source or make changes to the application, continue reading below.
## Build
## Development
run `./build.sh` to create a lbry executable, bundle the front-end and move
everything into the `app` folder
This repo uses submodules, so clone it using `--recursive`.
## Run
### Setup
The
[lbry daemon](https://github.com/lbryio/lbry/blob/master/INSTALL.md) needs
to be installed along with pyinstaller. You also need to be
able to build the lbry-web-ui, so have node, webpack, etc installed.
### Build
run `./build.sh`
This builds the UI assets and puts them into `app/dist`. It also builds `app/dist/lbrynet-daemon`.
### Run
`./node_modules/.bin/electron app`
## Package
### Package
To build a distributable package for OSX, run (on an OSX machine):
We use [electron-builder](https://github.com/electron-userland/electron-builder)
to create distributable packages, which is run by calling:
`electron-packager --electron-version=1.4.14 --overwrite electron LBRY`
`node_modules/.bin/build -p never`
This also probably works for windows and linux, but I haven't tested it
### Development on Windows
## TODO
This app works by launching the lbrynet daemon in a seperate process. Currently the
process management is very poor and the lbrynet process might not be shut-down when the app
is closed. Also, if the lbrynet daemon dies, there is no attempt to restart it.
This project has currently only been worked on in Linux and macOS. If you are on Windows, you can
checkout out the build steps in [appveyor.yml](https://github.com/lbryio/lbry-app/blob/master/appveyor.yml) and probably figure out something from there.
+33 -17
View File
@@ -1,4 +1,5 @@
const {app, BrowserWindow} = require('electron');
const {app, BrowserWindow, ipcMain} = require('electron');
var path = require('path');
var jayson = require('jayson');
@@ -17,6 +18,7 @@ let subpy
// set to true when the quitting sequence has started
let quitting = false;
function createWindow () {
// Create the browser window.
//win = new BrowserWindow({x: 0, y: 0, width: 1440, height: 414, backgroundColor: '#155b4a'})
@@ -43,7 +45,7 @@ function lauchDaemon() {
}
console.log(`${__dirname}`);
executable = path.join(__dirname, 'dist', 'lbrynet-daemon');
subpy = require('child_process').spawn(executable, ['--verbose'])//, {stdio: ['ignore', process.stdout, process.stderr]});
subpy = require('child_process').spawn(executable)
// Need to handle the data event instead of attaching to
// process.stdout because the latter doesn't work. I believe on
// windows it buffers stdout and we don't get any meaningful output
@@ -55,6 +57,7 @@ function lauchDaemon() {
if (quitting) {
app.quit();
} else {
// TODO: maybe it would be better to restart the daemon?
win.loadURL(`file://${__dirname}/dist/warning.html`);
setTimeout(app.quit, 5000)
}
@@ -70,9 +73,8 @@ app.on('ready', function(){
// an error its because its not running
console.log('Checking for lbrynet daemon')
client.request(
'status', [],
function (err, res) {
// Did it all work ?
'status', [],
function (err, res) {
if (err) {
console.log('lbrynet daemon needs to be launched')
lauchDaemon();
@@ -95,19 +97,14 @@ app.on('window-all-closed', () => {
})
app.on('before-quit', (event) => {
if (subpy != null) {
event.preventDefault()
if (win) {
win.loadURL(`file://${__dirname}/dist/quit.html`);
}
quitting = true;
console.log('Killing lbrynet-daemon process');
kill(subpy.pid, undefined, (err) => {
console.log('Killed lbrynet-daemon process');
});
if (subpy == null) {
return
}
event.preventDefault();
shutdownDaemon();
})
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
@@ -116,5 +113,24 @@ app.on('activate', () => {
}
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
function shutdownDaemon() {
console.log('Shutdown triggered');
if (subpy == null) {
// TODO: In this case, we didn't start the process so I'm hesitant
// to shut it down. We might want to send a stop command
// though instead of just letting it run.
console.log('Not killing lbrynet because we did not start it')
return
}
if (win) {
win.loadURL(`file://${__dirname}/dist/quit.html`);
}
quitting = true;
console.log('Killing lbrynet-daemon process');
kill(subpy.pid, undefined, (err) => {
console.log('Killed lbrynet-daemon process');
});
}
ipcMain.on('shutdown', shutdownDaemon);
+2 -1
View File
@@ -1,6 +1,6 @@
{
"name": "LBRY",
"version": "0.0.1",
"version": "0.9.0rc9",
"main": "main.js",
"description": "LBRY is a fully decentralized, open-source protocol facilitating the discovery, access, and (sometimes) purchase of data.",
"author": {
@@ -8,6 +8,7 @@
"name": "Job Evers-Meltzer"
},
"dependencies": {
"electron-dl": "^1.6.0",
"install": "^0.8.7",
"jayson": "^2.0.2",
"npm": "^4.2.0",
+10 -13
View File
@@ -1,6 +1,8 @@
# Test against the latest version of this Node.js version
environment:
nodejs_version: "6"
GH_TOKEN:
secure: LiI5jyuHUw6XbH4kC3gP1HX4P/v4rwD/gCNtaFhQu2AvJz1/1wALkp5ECnIxRySN
skip_branch_with_pr: true
@@ -10,7 +12,8 @@ clone_folder: C:\projects\lbry-electron
install:
# needed to deal with submodules
- git submodule update --init --recursive
- python set-version.py
- python set_version.py
- python set_build.py
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
@@ -35,22 +38,16 @@ build_script:
# build electron app
- node_modules\.bin\build -p never
# for debugging, see what was built
- python zip_daemon.py
- dir dist
- pip install PyGithub uritemplate
- python release_on_tag.py
test: off
artifacts:
- path: dist\*.zip
- path: dist\*.exe
name: LBRY
deploy:
- provider: GitHub
release: $(APPVEYOR_REPO_TAG_NAME)
description: 'Release'
auth_token:
secure: LiI5jyuHUw6XbH4kC3gP1HX4P/v4rwD/gCNtaFhQu2AvJz1/1wALkp5ECnIxRySN
artifact: LBRY
draft: true
prerelease: true
on:
appveyor_repo_tag: true # deploy on tag push only
- path: dist\*.zip
name: lbrynet-daemon
+4 -2
View File
@@ -30,7 +30,8 @@ if [ "$FULL_BUILD" == "true" ]; then
source "$VENV/bin/activate"
set -u
pip install -U pip setuptools pyinstaller
python set-version.py
python set_version.py
python set_build.py
fi
npm install
@@ -71,6 +72,7 @@ if [ "$FULL_BUILD" == "true" ]; then
fi
node_modules/.bin/build -p never
python zip_daemon.py
echo 'Build and packaging complete.'
else
@@ -82,6 +84,6 @@ if [ "$FULL_BUILD" == "true" ]; then
# it to reliably work and it also seemed difficult to configure. Not proud of
# this, but it seemed better to write my own.
pip install PyGithub uritemplate
python release-on-tag.py
python release_on_tag.py
deactivate
fi
+129
View File
@@ -0,0 +1,129 @@
import argparse
import datetime
import re
import sys
CHANGELOG_START_RE = re.compile(r'^\#\# \[Unreleased\]')
CHANGELOG_END_RE = re.compile(r'^\#\# \[.*\] - \d{4}-\d{2}-\d{2}')
# if we come across a section header between two release section headers
# then we probably have an improperly formatted changelog
CHANGELOG_ERROR_RE = re.compile(r'^\#\# ')
SECTION_RE = re.compile(r'^\#\#\# (.*)$')
EMPTY_RE = re.compile(r'^\w*\*\w*$')
ENTRY_RE = re.compile(r'\* (.*)')
VALID_SECTIONS = ['Added', 'Changed', 'Deprecated', 'Removed', 'Fixed', 'Security']
# allocate some entries to cut-down on merge conflicts
TEMPLATE = """### Added
*
*
*
### Changed
*
*
*
### Fixed
*
*
*
"""
def main():
parser = argparse.ArgumentParser()
parser.add_argument('changelog')
parser.add_argument('version')
args = parser.parse_args()
bump(changelog, version)
def bump(changelog, version):
with open(changelog) as fp:
lines = fp.readlines()
start = []
unreleased = []
rest = []
unreleased_start_found = False
unreleased_end_found = False
for line in lines:
if not unreleased_start_found:
start.append(line)
if CHANGELOG_START_RE.search(line):
unreleased_start_found = True
continue
if unreleased_end_found:
rest.append(line)
continue
if CHANGELOG_END_RE.search(line):
rest.append(line)
unreleased_end_found = True
continue
if CHANGELOG_ERROR_RE.search(line):
raise Exception(
'Failed to parse {}: {}'.format(filename, 'unexpected section header found'))
unreleased.append(line)
today = datetime.datetime.today()
header = '## [{}] - {}\n'.format(version, today.strftime('%Y-%m-%d'))
released = normalize(unreleased)
if not released:
# If we don't have anything in the Unreleased section, then leave the
# changelog as it is and return None
return
changelog_data = (
''.join(start) +
TEMPLATE +
header +
'\n'.join(released) + '\n\n'
+ ''.join(rest)
)
with open(changelog, 'w') as fp:
fp.write(changelog_data)
return '\n'.join(released) + '\n\n'
def normalize(lines):
"""Parse a changelog entry and output a normalized form"""
sections = {}
current_section_name = None
current_section_contents = []
for line in lines:
line = line.strip()
if not line or EMPTY_RE.match(line):
continue
match = SECTION_RE.match(line)
if match:
if current_section_contents:
sections[current_section_name] = current_section_contents
current_section_contents = []
current_section_name = match.group(1)
if current_section_name not in VALID_SECTIONS:
raise ValueError("Section '{}' is not valid".format(current_section_name))
continue
match = ENTRY_RE.match(line)
if match:
current_section_contents.append(match.group(1))
continue
raise Exception('Something is wrong with line: {}'.format(line))
if current_section_contents:
sections[current_section_name] = current_section_contents
output = []
for section in VALID_SECTIONS:
if section not in sections:
continue
output.append('### {}'.format(section))
for entry in sections[section]:
output.append(' * {}'.format(entry))
return output
if __name__ == '__main__':
sys.exit(main())
+1 -1
Submodule lbry updated: 0302e3fff2...40d4fb5641.
+1 -1
Submodule lbryum updated: 49253b6614...d3bfb004e2.
+1 -1
View File
@@ -36,7 +36,7 @@
"target": "deb"
},
"win": {
"target": "zip"
"target": "nsis"
}
},
"devDependencies": {
-169
View File
@@ -1,169 +0,0 @@
import argparse
import glob
import json
import logging
import os
import platform
import re
import subprocess
import sys
import zipfile
import github
import requests
import uritemplate
from lbrynet.core import log_support
def main(args=None):
parser = argparse.ArgumentParser()
parser.add_argument('--file', help='artifact to publish')
parser.add_argument('--label', help='text to append to `file`')
parser.add_argument('--zip', action='store_true')
parser.add_argument(
'--force', action='store_true',
help='ignores whether the repo is currently tagged, publishes a draft release')
args = parser.parse_args(args)
gh_token = os.environ['GH_TOKEN']
auth = github.Github(gh_token)
current_repo = auth.get_repo(current_repo_name())
if args.file:
artifact = args.file
else:
artifact = get_artifact()
current_tag = None
if not args.force:
try:
current_tag = subprocess.check_output(
['git', 'describe', '--exact-match', 'HEAD']).strip()
except subprocess.CalledProcessError:
log.info('Stopping as we are not currently on a tag')
return
if not check_repo_has_tag(current_repo, current_tag):
log.info('Tag %s is not in repo %s', current_tag, current_repo)
# TODO: maybe this should be an error
return
release = get_release(current_repo, current_tag, args.force)
asset_to_upload = get_asset(artifact, args.label, args.zip)
upload_asset(release, asset_to_upload, gh_token)
def get_system():
system = platform.system()
if system == 'Darwin':
return 'macOS'
else:
return system
def current_repo_name():
pattern = 'github.com[:/](.*)\.git'
remote = subprocess.check_output('git remote -v'.split())
m = re.search(pattern, remote)
if not m:
raise Exception('Unable to parse repo name from remote: {}'.format(remote))
return m.group(1)
def check_repo_has_tag(repo, target_tag):
tags = repo.get_tags().get_page(0)
for tag in tags:
if tag.name == target_tag:
return True
return False
def get_release(current_repo, current_tag=None, draft=False):
assert current_tag or draft, 'either current_tag or draft must be set'
need_new_release = False
if not draft and current_tag:
try:
release = current_repo.get_release(current_tag)
log.info('Using an existing release for %s', current_tag)
except github.UnknownObjectException:
need_new_release = True
if draft or need_new_release:
log.info('Creating a new release for %s:%s', current_repo, current_tag)
tag = current_tag or 'draft'
release_name = current_tag or 'draft'
msg = 'Release' # TODO: parse changelogs to get a better message
try:
# we have a race condition where its possible that between checking
# for the release and now, another build agent has come along and already
# created a release
release = current_repo.create_git_release(tag, release_name, msg, draft)
except github.GithubException:
log.info('Failed to create a release, maybe somebody already has', exc_info=True)
release = current_repo.get_release(current_tag)
return release
def get_artifact():
system = platform.system()
if system == 'Darwin':
return glob.glob('dist/mac/LBRY*.dmg')[0]
elif system == 'Linux':
return glob.glob('dist/LBRY*.deb')[0]
else:
raise Exception("I don't know about any artifact on {}".format(system))
def get_asset(filename, label=None, use_zip=False):
if label:
label = '-{}'.format(label)
else:
label = ''
base, ext = os.path.splitext(filename)
if use_zip:
# TODO: probably want to clean this up
zipfilename = '{}{}.zip'.format(base, label)
with zipfile.ZipFile(zipfilename, 'w') as myzip:
myzip.write(filename)
asset_to_uplaod = zipfilename
else:
asset_to_upload = '{}{}{}'.format(base, label, ext)
return asset_to_upload
def upload_asset(release, asset_to_upload, token):
basename = os.path.basename(asset_to_upload)
if is_asset_already_uploaded(release, basename):
return
upload_uri = uritemplate.expand(
release.upload_url, {'name': basename, 'label': get_system()})
# using requests.post fails miserably with SSL EPIPE errors. I spent
# half a day trying to debug before deciding to switch to curl.
cmd = [
'curl', '-sS', '-X', 'POST', '-u', ':{}'.format(os.environ['GH_TOKEN']),
'--header', 'Content-Type:application/zip',
'--data-binary', '@{}'.format(asset_to_upload), upload_uri
]
raw_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
output = json.loads(raw_output)
if 'errors' in output:
raise Exception(output)
else:
log.info('Successfully uploaded to %s', output['browser_download_url'])
def is_asset_already_uploaded(release, basename):
for asset in release.raw_data['assets']:
if asset['name'] == basename:
log.info('File %s has already been uploaded to %s', basename, release.tag_name)
return True
return False
if __name__ == '__main__':
log = logging.getLogger('release-on-tag')
log_support.configure_console(level='DEBUG')
sys.exit(main())
else:
log = logging.getLogger(__name__)
+250
View File
@@ -0,0 +1,250 @@
"""Trigger a release.
This script is to be run locally (not on a build server).
"""
import argparse
import contextlib
import logging
import os
import re
import subprocess
import sys
import git
import github
import requests
import changelog
NO_CHANGE = ('No change since the last release. This release is simply a placeholder'
' so that LBRY and LBRY App track the same version')
DEFAULT_BRANCHES = {
'lbry': 'master',
'lbry-app': 'master',
'lbry-web-ui': 'development',
'lbryum': 'master'
}
def main():
parser = argparse.ArgumentParser()
parser.add_argument("lbry_part", help="part of lbry version to bump")
parser.add_argument("--lbryum_part", help="part of lbryum version to bump")
parser.add_argument("--ui-part", help="part of the ui to bump")
parser.add_argument("--branch", help="branch to use for each repo; useful for testing")
parser.add_argument("--last-release")
parser.add_argument("--skip-sanity-checks", action="store_true")
parser.add_argument("--require-changelog", action="store_true")
parser.add_argument("--skip-push", action="store_true",
help="Set to not push changes to remote repo")
args = parser.parse_args()
base = git.Repo(os.getcwd())
branch = get_branch('lbry-app', args.branch)
if not args.skip_sanity_checks:
run_sanity_checks(base, branch)
if args.last_release:
last_release = args.last_release
else:
response = requests.get('https://api.github.com/repos/lbryio/lbry-app/releases/latest')
data = response.json()
last_release = data['tag_name']
logging.info('Last release: %s', last_release)
gh_token = os.environ['GH_TOKEN']
auth = github.Github(gh_token)
github_repo = auth.get_repo('lbryio/lbry-app')
names = ['lbry', 'lbry-web-ui', 'lbryum']
repos = [Repo(name, get_part(args, name)) for name in names]
# in order to see if we've had any change in the submodule, we need to checkout
# our last release, see what commit we were on, and then compare that to
# current
base.git.checkout(last_release)
base.git.submodule('update')
for repo in repos:
repo.save_commit()
base.git.checkout(branch)
base.git.submodule('update')
changelogs = {}
for repo in repos:
logging.info('Processing repo: %s', repo.name)
repo.checkout(args.branch)
if repo.has_changes():
entry = repo.get_changelog_entry()
if entry:
changelogs[repo.name] = entry.strip()
repo.add_changelog()
else:
msg = 'Changelog entry is missing for {}'.format(repo.name)
if args.require_changelog:
raise Exception(msg)
else:
logging.warning(msg)
else:
logging.warning('Submodule %s has no changes.', repo.name)
if repo.name == 'lbryum':
# The other repos have their version track each other so need to bump
# them even if there aren't any changes, but lbryum should only be
# bumped if it has changes
continue
repo.bumpversion()
release_msg = get_release_msg(changelogs, names)
for name in names:
base.git.add(name)
subprocess.check_call(['bumpversion', args.lbry_part, '--allow-dirty'])
current_tag = base.git.describe()
github_repo.create_git_release(current_tag, current_tag, release_msg, draft=True)
lbrynet_daemon_release_msg = changelogs.get('lbry', NO_CHANGE)
auth.get_repo('lbryio/lbrynet-daemon').create_git_release(
current_tag, current_tag, lbrynet_daemon_release_msg, draft=True)
if not args.skip_push:
for repo in repos:
repo.git.push(follow_tags=True)
base.git.push(follow_tags=True, recurse_submodules='check')
else:
logging.info('Skipping push; you will have to reset and delete tags if '
'you want to run this script again')
def get_branch(repo_name, override=None):
if override:
return override
return DEFAULT_BRANCHES[repo_name]
def get_release_msg(changelogs, names):
lines = []
for name in names:
entry = changelogs.get(name)
if not entry:
continue
lines.append('## {}\n'.format(name))
lines.append('{}\n'.format(entry))
return '\n'.join(lines)
def run_sanity_checks(base, branch):
if base.is_dirty():
print 'Cowardly refusing to release a dirty repo'
sys.exit(1)
if base.active_branch.name != branch:
print 'Cowardly refusing to release when not on the {} branch'.format(branch)
sys.exit(1)
if is_behind(base, branch):
print 'Cowardly refusing to release when behind origin'
sys.exit(1)
check_bumpversion()
def is_behind(base, branch):
base.remotes.origin.fetch()
rev_list = '{branch}...origin/{branch}'.format(branch=branch)
commits_behind = base.git.rev_list(rev_list, right_only=True, count=True)
commits_behind = int(commits_behind)
return commits_behind > 0
def check_bumpversion():
def requireNewVersion():
print 'Install bumpversion: pip install -U git+https://github.com/lbryio/bumpversion.git'
sys.exit(1)
try:
output = subprocess.check_output(['bumpversion', '-v'], stderr=subprocess.STDOUT)
output = output.strip()
if output != 'bumpversion 0.5.4-lbry':
requireNewVersion()
except (subprocess.CalledProcessError, OSError) as err:
requireNewVersion()
def get_part(args, name):
if name == 'lbry-web-ui':
part = getattr(args, 'ui_part')
return part or args.lbry_part
else:
return getattr(args, name + '_part')
class Repo(object):
def __init__(self, name, part):
self.name = name
self.part = part
self.directory = os.path.join(os.getcwd(), name)
self.git_repo = git.Repo(self.directory)
self.saved_commit = None
self._bumped = False
def has_changes(self):
logging.info('%s =? %s', self.git_repo.commit(), self.saved_commit)
return self.git_repo.commit() != self.saved_commit
def save_commit(self):
self.saved_commit = self.git_repo.commit()
def checkout(self, override=None):
branch = get_branch(self.name, override)
self.git_repo.git.checkout(branch)
self.git_repo.git.pull(rebase=True)
def get_changelog_entry(self):
filename = os.path.join(self.directory, 'CHANGELOG.md')
return changelog.bump(filename, self.new_version())
def add_changelog(self):
with pushd(self.directory):
self.git_repo.git.add('CHANGELOG.md')
def new_version(self):
if self._bumped:
raise Exception('Cannot calculate a new version on an already bumped repo')
if not self.part:
raise Exception('Cannot calculate a new version without a part')
with pushd(self.directory):
output = subprocess.check_output(
['bumpversion', '--dry-run', '--list', '--allow-dirty', self.part])
return re.search('^new_version=(.*)$', output, re.M).group(1)
def bumpversion(self):
if self._bumped:
raise Exception('Cowardly refusing to bump a repo twice')
if not self.part:
raise Exception('Cannot bump version for {}: no part specified'.format(repo.name))
with pushd(self.directory):
subprocess.check_call(['bumpversion', '--allow-dirty', self.part])
self._bumped = True
@property
def git(self):
return self.git_repo.git
@contextlib.contextmanager
def pushd(new_dir):
previous_dir = os.getcwd()
os.chdir(new_dir)
yield
os.chdir(previous_dir)
if __name__ == '__main__':
logging.basicConfig(
format="%(asctime)s %(levelname)-8s %(name)s:%(lineno)d: %(message)s",
level='INFO'
)
sys.exit(main())
else:
log = logging.getLogger('__name__')
+126
View File
@@ -0,0 +1,126 @@
import argparse
import glob
import json
import logging
import os
import platform
import re
import subprocess
import sys
import github
import requests
import uritemplate
from lbrynet.core import log_support
def main(args=None):
current_tag = None
try:
current_tag = subprocess.check_output(
['git', 'describe', '--exact-match', 'HEAD']).strip()
except subprocess.CalledProcessError:
log.info('Stopping as we are not currently on a tag')
return
if 'GH_TOKEN' not in os.environ:
print 'Must set GH_TOKEN in order to publish assets to a release'
return
gh_token = os.environ['GH_TOKEN']
auth = github.Github(gh_token)
app_repo = auth.get_repo('lbryio/lbry-app')
# TODO: switch lbryio/lbrynet-daemon to lbryio/lbry
daemon_repo = auth.get_repo('lbryio/lbrynet-daemon')
if not check_repo_has_tag(app_repo, current_tag):
log.info('Tag %s is not in repo %s', current_tag, app_repo)
# TODO: maybe this should be an error
return
app = get_app_artifact()
release = get_release(app_repo, current_tag)
upload_asset(release, app, gh_token)
daemon = get_daemon_artifact()
release = get_release(daemon_repo, current_tag)
upload_asset(release, daemon, gh_token)
def check_repo_has_tag(repo, target_tag):
tags = repo.get_tags().get_page(0)
for tag in tags:
if tag.name == target_tag:
return True
return False
def get_release(current_repo, current_tag):
for release in current_repo.get_releases():
if release.tag_name == current_tag:
return release
raise Exception('No release for {} was found'.format(current_tag))
def get_app_artifact():
system = platform.system()
if system == 'Darwin':
return glob.glob('dist/mac/LBRY*.dmg')[0]
elif system == 'Linux':
return glob.glob('dist/LBRY*.deb')[0]
elif system == 'Windows':
return glob.glob('dist/LBRY*.exe')[0]
else:
raise Exception("I don't know about any artifact on {}".format(system))
def get_daemon_artifact():
return glob.glob('dist/*.zip')[0]
def upload_asset(release, asset_to_upload, token):
basename = os.path.basename(asset_to_upload)
if is_asset_already_uploaded(release, basename):
return
upload_uri = uritemplate.expand(
release.upload_url, {'name': basename})
# using requests.post fails miserably with SSL EPIPE errors. I spent
# half a day trying to debug before deciding to switch to curl.
#
# TODO: actually set the content type
cmd = [
'curl', '-sS', '-X', 'POST', '-u', ':{}'.format(os.environ['GH_TOKEN']),
'--header', 'Content-Type:application/octet-stream',
'--data-binary', '@{}'.format(asset_to_upload), upload_uri
]
p = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
stdout, stderr = p.communicate()
print 'curl return code:', p.returncode
if stderr:
print 'stderr output from curl:'
print stderr
output = json.loads(stdout)
print 'stdout from curl:'
print stdout
if 'errors' in output:
raise Exception(output)
else:
log.info('Successfully uploaded to %s', output['browser_download_url'])
def is_asset_already_uploaded(release, basename):
for asset in release.raw_data['assets']:
if asset['name'] == basename:
log.info('File %s has already been uploaded to %s', basename, release.tag_name)
return True
return False
if __name__ == '__main__':
log = logging.getLogger('release-on-tag')
log_support.configure_console(level='INFO')
sys.exit(main())
else:
log = logging.getLogger(__name__)
-20
View File
@@ -1,20 +0,0 @@
"""Set the package version to the output of `git describe`"""
import json
import os.path
import subprocess
import sys
def main():
version = subprocess.check_output(['git', 'describe']).strip()
package_file = os.path.join('app', 'package.json')
with open(package_file) as fp:
package_data = json.load(fp)
package_data['version'] = version
with open(package_file, 'w') as fp:
json.dump(package_data, fp, indent=2, separators=(',', ': '))
if __name__ == '__main__':
sys.exit(main())
+29
View File
@@ -0,0 +1,29 @@
"""Set the build version to be 'dev', 'qa', 'rc', 'release'"""
import json
import os.path
import re
import subprocess
import sys
def main():
build = get_build()
with open(os.path.join('lbry', 'lbrynet', 'build_type.py'), 'w') as f:
f.write('BUILD = "{}"'.format(build))
def get_build():
try:
tag = subprocess.check_output(['git', 'describe', '--exact-match']).strip()
if re.match('v\d+\.\d+\.\d+rc\d+', tag):
return 'rc'
else:
return 'release'
except subprocess.CalledProcessError:
# if the build doesn't have a tag
return 'qa'
if __name__ == '__main__':
sys.exit(main())
+59
View File
@@ -0,0 +1,59 @@
"""Set the package version to the output of `git describe`"""
import argparse
import json
import os.path
import re
import subprocess
import sys
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--version', help="defaults to the output of `git describe`")
args = parser.parse_args()
if args.version:
version = args.version
else:
tag = subprocess.check_output(['git', 'describe']).strip()
try:
version = get_version_from_tag(tag)
except InvalidVersionTag:
# this should be an error but its easier to handle here
# than in the calling scripts.
print 'Tag cannot be converted to a version, Exitting'
return
set_version(version)
class InvalidVersionTag(Exception):
pass
def get_version_from_tag(tag):
match = re.match('v([\d.]+)', tag)
if match:
return match.group(1)
else:
raise InvalidVersionTag('Failed to parse version from tag {}'.format(tag))
def set_version(version):
package_file = os.path.join('app', 'package.json')
with open(package_file) as fp:
package_data = json.load(fp)
package_data['version'] = version
with open(package_file, 'w') as fp:
json.dump(package_data, fp, indent=2, separators=(',', ': '))
with open(os.path.join('lbry', 'lbrynet', '__init__.py'), 'w') as fp:
fp.write(LBRYNET_TEMPLATE.format(version=version))
LBRYNET_TEMPLATE = """
__version__ = "{version}"
version = tuple(__version__.split('.'))
"""
if __name__ == '__main__':
sys.exit(main())
+26
View File
@@ -0,0 +1,26 @@
import os
import platform
import sys
import zipfile
def main():
zipfilename = 'lbrynet-daemon-{}.zip'.format(get_system_label())
full_filename = os.path.join('dist', zipfilename)
executable = 'lbrynet-daemon'
if platform.system() == 'Windows':
executable += '.exe'
with zipfile.ZipFile(full_filename, 'w') as myzip:
myzip.write(os.path.join('app', 'dist', executable), executable)
def get_system_label():
system = platform.system()
if system == 'Darwin':
return 'macOS'
else:
return system
if __name__ == '__main__':
sys.exit(main())