This repository has been archived by the owner on Jan 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
376 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...oc/clappr/io.clappr.player.extensions.context/android.content.-context/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
Oops, something went wrong.