Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/0.0.21'
Browse files Browse the repository at this point in the history
  • Loading branch information
arthursz committed Nov 7, 2017
2 parents d28924f + b44734b commit 1cf1169
Show file tree
Hide file tree
Showing 23 changed files with 376 additions and 28 deletions.
60 changes: 60 additions & 0 deletions cd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Clappr-Android automated release Step-by-Step

This document describes how to proceed with
the required steps to make a release using the automation
resources available for the Clappr-Android source code. Before doing any action
described in this document, ensure you already proceeded with the release branch
creation, configuration and integration to the master branch.

## Release using scripts-only
All release scripts are written in Python, to make sure
your computer environment is ready verify if Python 3 is available
in your CLI of choice. For further configuration help,
enter the Python 3 [website](https://www.python.org/download/releases/3.0/).

### 1. Run Tests:
Since your local master branch is now up to date,
it' time to build the project and run all automated
tests from the project, to make it possible, run:

```shellscript
python3 release.py run_tests
```
### 2. Bintray Upload:
Once everything is builded and tested, now we can upload
the generated artifact to the Bintray repository in order
to make it public and widely available, so now run:

```shellscript
python3 release.py bintray_upload
```
### 3. Send Release Notes:
Anytime we upload a new Clappr-Android artifact to
the release Bintray repository, we need to describe
what was changes or added on this new version, ensure then
that an `release_notes.md` file is available at the `../player` folder.
When those requirements are met, run:

```shellscript
python3 release.py send_release_notes
```
after that, the release file will be uploaded to the [Clappr-Android Github
release notes](https://github.com/clappr/clappr-android/releases) notifying everyone watching it.


## Release using a Go.CD pipeline
The Go.CD pipeline is an almost-full automated release process, all commands will
be executed by itself and the pipeline will handle every step, including the additional capability
to notify via e-mail and Slack channel that a new Clappr-Android release is available. The Go.CD pipeline
will be triggered everytime a change is done to the master branch, so all you need is ensure that the release branch
process was applied and a `release_notes.md` file was added.
Empty file added cd/__init__.py
Empty file.
50 changes: 50 additions & 0 deletions cd/command_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import sys

from subprocess import call

def execute_command(command, attributes):
task_executed_with_success = 0
attributes.insert(0, command)
return call(attributes) == task_executed_with_success


class bcolors:
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'


def print_error(message):
print(bcolors.FAIL + "Error: " + message + bcolors.ENDC)


def print_success():
print(bcolors.BOLD + "Uhuuuuu! zo/ Success" + bcolors.ENDC)


def execute_stage(version, stages, stage_key):
try:
for task in stages[stage_key]:
print("task: %s , Clappr: vrs %s on branch" % (task.__name__, version))
if not task(version):
sys.exit(1)

except IndexError:
print("Can not Moisés! The options are: ")
for stage_key in stages.keys():
print(stage_key)


def execute_gradle(tasks):
return execute_command(command='../gradlew', attributes=tasks)


def run_tests(new_release_version):
response = execute_gradle(tasks=['clean', 'build', 'test', '--continue'])

if not response:
print_error("Tests failed")

return response
20 changes: 20 additions & 0 deletions cd/git_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from command_manager import execute_command, print_error
import subprocess

def execute_git(commands):
for task in commands:
if not execute_command(command='git', attributes=task):
print_error("Can not execute git command!")
return False
return True


def get_current_branch():
output = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode('utf8').replace('\n','')
print("branch=%s" % output)
return output


def get_tag_branch(tag_name):
output = subprocess.check_output(['git', 'branch', '--contains', tag_name]).decode('utf8')
return output
45 changes: 45 additions & 0 deletions cd/release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import sys

from repository_manager import release_note_file_path, bintray_upload, send_release_notes, get_gradle_version, from_release_to_clappr_dir, from_clappr_to_release_dir, read_release_notes
from command_manager import print_error, execute_stage, print_success, run_tests

release_version_regex = r'version = \'((\d+)\.(\d+)\.(\d+))\''


def verify_release_pre_requisites(version):
if version == "":
print_error("Wrong version format")
sys.exit(1)

release_notes = read_release_notes(release_note_file_path)
if release_notes is None or release_notes == "":
print_error("Release notes is not consistent with version '%s'" % version)
sys.exit(1)


if __name__ == '__main__':
print('Starting release process')

stages = {
'run_tests': [run_tests],
'bintray_upload': [bintray_upload],
'send_release_notes': [send_release_notes]
}

if len(sys.argv) != 2:
print_error("Wrong number of arguments")
sys.exit(1)

print('Changing to clappr dir')
from_release_to_clappr_dir()

stage = sys.argv[1]
version = get_gradle_version(release_version_regex)
verify_release_pre_requisites(version)

execute_stage(version, stages, stage)

print('Changing back to release dir')
from_clappr_to_release_dir()

print_success()
98 changes: 98 additions & 0 deletions cd/repository_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import os
import requests
import re

from command_manager import print_error, execute_gradle
from git_manager import get_current_branch, get_tag_branch

release_dir_path = '../cd/'
clappr_dir_path = '../clappr/'
gradle_file_path = 'build.gradle'
release_note_file_path = '../release_notes.md'


def get_gradle_version(version_regex):
file_content = open(gradle_file_path, 'r').read()
full_version = re.search(pattern=version_regex, string=file_content)

return full_version.group(1) if full_version is not None else ""


def update_gradle_version(old_version, new_version):
with open(gradle_file_path) as f:
s = f.read()

with open(gradle_file_path, 'w') as f:
print("Changing %s to %s in %s" % (old_version, new_version, gradle_file_path))
s = s.replace(old_version, new_version)
f.write(s)


def from_clappr_to_release_dir():
os.chdir(path=release_dir_path)


def from_release_to_clappr_dir():
os.chdir(path=clappr_dir_path)


def send_release_notes(new_release_version):
branch_name = get_current_branch()
return publish_release_notes(branch_name, new_release_version, release_note_file_path)


def bintray_upload(new_release_version):
bintray_user = "BINTRAY_USER"
bintray_api_key = "BINTRAY_API_KEY"

if not bintray_user in os.environ:
print_error("Env variable '%s' is not defined" % bintray_user)
return False

if not bintray_api_key in os.environ:
print_error("Env variable '%s' is not defined" % bintray_api_key)
return False

return execute_gradle(tasks=['bintrayUpload'])


def read_release_notes(release_note_file_path):
with open(release_note_file_path) as file:
return file.read()


def publish_release_notes(branch_name, new_release_version, release_note_file_path):
repository_path = "REPOSITORY_PATH"
repository_token = "REPOSITORY_TOKEN"

if not repository_path in os.environ:
print_error("Env variable '%s' is not defined" % repository_path)
return False

if not repository_token in os.environ:
print_error("Env variable '%s' is not defined" % repository_token)
return False

tag_branch = get_tag_branch(new_release_version)
if tag_branch is None or tag_branch.strip(" ") != branch_name:
print_error("Tag '%s' not exist" % new_release_version)
return False

release_notes = read_release_notes(release_note_file_path)
body = {
'tag_name': new_release_version,
'target_commitish': branch_name,
'name': 'Alpha Release',
'body': release_notes,
'draft': True,
'prerelease': False
}
response = requests.post(url=os.environ[repository_path],
auth=('token', os.environ[repository_token]),
json=body)

if response.status_code >= 300:
print_error(response.text)
return False

return True
48 changes: 48 additions & 0 deletions cd/snapshot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import sys
import time
from repository_manager import bintray_upload, get_gradle_version, from_release_to_clappr_dir, from_clappr_to_release_dir, update_gradle_version
from command_manager import print_error, execute_stage, print_success, run_tests

release_version_regex = r'version = \'((\d+)\.(\d+)\.(\d+))\''
snapshot_version_regex = r'version = \'((\d+)\.(\d+)\.(\d+)-dev-(\d+))\''


def verify_snapshot_pre_requisites(version):
if version == "":
print_error("Wrong version format")
sys.exit(1)


if __name__ == '__main__':
print('Starting snapshot process')

stages = {
'update_gradle_version': [],
'run_tests': [run_tests],
'bintray_upload': [bintray_upload]
}

if len(sys.argv) != 2:
print_error("Wrong number of arguments")
sys.exit(1)

print('Changing to clappr dir')
from_release_to_clappr_dir()

stage = sys.argv[1]
version = ""
if stage == 'update_gradle_version':
version = get_gradle_version(release_version_regex)
verify_snapshot_pre_requisites(version)
new_version = version + '-dev-' + str(round(time.time() * 1000))
update_gradle_version(version, new_version)

version = get_gradle_version(snapshot_version_regex)
verify_snapshot_pre_requisites(version)

execute_stage(version, stages, stage)

print('Changing back to release dir')
from_clappr_to_release_dir()

print_success()
13 changes: 11 additions & 2 deletions clappr/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ apply plugin: 'org.jetbrains.dokka-android'
apply from: 'versioning.gradle'

group = 'io.clappr.player'
version = '0.0.20'
version = '0.0.21'

def publishAttrs = buildPublishAttrs(version)

Expand All @@ -29,6 +29,7 @@ bintray {
key = System.getenv('BINTRAY_API_KEY')
configurations = ['archives']
pkg {
publish = true
repo = 'clappr'
name = publishAttrs['bintrayRepoName']
userOrg = 'clappr-android'
Expand All @@ -44,7 +45,7 @@ bintray {
}

android {
publishNonDefault true
publishNonDefault publishAttrs['bintrayPublishNonDefault']
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
Expand All @@ -70,6 +71,10 @@ android {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
}
// ignore lint temporarily until gocd can handle the report correctly
lintOptions {
abortOnError false
}

testOptions {
unitTests.all {
Expand Down Expand Up @@ -100,6 +105,10 @@ dependencies {
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
}

tasks.matching {it instanceof Test}.all {
testLogging.events = ["failed", "passed", "skipped"]
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
Expand Down
1 change: 1 addition & 0 deletions clappr/doc/clappr/alltypes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
| [io.clappr.player.base.ClapprOption](../io.clappr.player.base/-clappr-option/index.md) | |
| [io.clappr.player.components.Container](../io.clappr.player.components/-container/index.md) | |
| [io.clappr.player.plugin.container.ContainerPlugin](../io.clappr.player.plugin.container/-container-plugin/index.md) | |
| [android.content.Context](../io.clappr.player.extensions.context/android.content.-context/index.md) (extensions in package io.clappr.player.extensions.context) | |
| [io.clappr.player.components.Core](../io.clappr.player.components/-core/index.md) | |
| [io.clappr.player.plugin.core.CorePlugin](../io.clappr.player.plugin.core/-core-plugin/index.md) | |
| [io.clappr.player.base.ErrorCode](../io.clappr.player.base/-error-code/index.md) | |
Expand Down
1 change: 1 addition & 0 deletions clappr/doc/clappr/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
| [io.clappr.player](io.clappr.player/index.md) | |
| [io.clappr.player.base](io.clappr.player.base/index.md) | |
| [io.clappr.player.components](io.clappr.player.components/index.md) | |
| [io.clappr.player.extensions.context](io.clappr.player.extensions.context/index.md) | |
| [io.clappr.player.log](io.clappr.player.log/index.md) | |
| [io.clappr.player.periodicTimer](io.clappr.player.periodic-timer/index.md) | |
| [io.clappr.player.playback](io.clappr.player.playback/index.md) | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[clappr](../../index.md) / [io.clappr.player.extensions.context](../index.md) / [android.content.Context](.)

### Extensions for android.content.Context

| Name | Summary |
|---|---|
| [isRunningInAndroidTvDevice](is-running-in-android-tv-device.md) | `fun `[`Context`](https://developer.android.com/reference/android/content/Context.html)`.isRunningInAndroidTvDevice(): `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) |
Loading

0 comments on commit 1cf1169

Please sign in to comment.