-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from cgalibern/feature-release
feature-release
- Loading branch information
Showing
8 changed files
with
318 additions
and
10 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
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,17 @@ | ||
from runner.release import Runner as ReleaseRunner | ||
|
||
|
||
class Runner(ReleaseRunner): | ||
def extra_action(self, job): | ||
return " current link updated:..." | ||
|
||
def release_dir(self, job): | ||
""" | ||
define release dir from event tag name value | ||
examples: | ||
v1.9.5 -> <release_base_dir>/1/1.9.5/ | ||
v2.0.0 -> <release_base_dir>/2/2.0.0/ | ||
""" | ||
tag_name = job.context.tag_name.lstrip("v") | ||
api_version = tag_name.split(".")[0] | ||
return "%s/%s/%s" % (job.release_base_dir, api_version, tag_name) |
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,63 @@ | ||
from context.github_abstract import GitHubAbstract | ||
|
||
|
||
class Context(GitHubAbstract): | ||
""" | ||
Context class for github release events | ||
""" | ||
|
||
@property | ||
def event(self): | ||
return 'release' | ||
|
||
@property | ||
def action(self): | ||
return self.payload['action'] | ||
|
||
@property | ||
def release(self): | ||
return self.payload['release'] | ||
|
||
@property | ||
def download_url(self): | ||
return "%s/releases/download/%s" % (self.html_url, self.tag_name) | ||
|
||
@property | ||
def release_name(self): | ||
return self.release['name'] | ||
|
||
@property | ||
def tag_name(self): | ||
return self.release['tag_name'] | ||
|
||
@property | ||
def draft(self): | ||
return self.release['draft'] | ||
|
||
@property | ||
def prerelease(self): | ||
return self.release['prerelease'] | ||
|
||
@property | ||
def target_commitish(self): | ||
return self.release['target_commitish'] | ||
|
||
@property | ||
def repository(self): | ||
return self.payload['repository'] | ||
|
||
@property | ||
def html_url(self): | ||
return self.repository['html_url'] | ||
|
||
@property | ||
def description(self): | ||
return { | ||
'action': self.action, | ||
'name': self.name, | ||
'tag_name': self.tag_name, | ||
'draft': self.draft, | ||
'prerelease': self.prerelease, | ||
'target_commitish': self.target_commitish, | ||
'html_url': self.html_url, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import logging | ||
import os | ||
|
||
import requests | ||
|
||
from runner.runner_abstract import RunnerAbstract | ||
|
||
|
||
def download_to(url, dest): | ||
logging.info("download %s ...", url) | ||
r = requests.get(url, allow_redirects=True) | ||
open(dest, 'wb').write(r.content) | ||
logging.info("installed %s", dest) | ||
|
||
|
||
class Runner(RunnerAbstract): | ||
def download_url(self, job, name): | ||
return "%s/%s" % (job.context.download_url, name) | ||
|
||
def extra_action(self, job): | ||
""" | ||
extra actions to be run after asset files installed | ||
return message | ||
""" | ||
return "" | ||
|
||
def release_dir(self, job): | ||
""" | ||
default destination dir for release files (<release_base_dir>/<event release tag_name>/) | ||
""" | ||
return "%s/%s" % (job.release_base_dir, job.context.tag_name) | ||
|
||
def execute(self, job): | ||
""" | ||
runner example: | ||
- download assets files from DEPLOY_FILES list | ||
- install files to release_dir/ | ||
""" | ||
if job.context.action != "published": | ||
self._data = { | ||
"message": f'release action {job.context.action} {job.context.name} nothing to do' | ||
} | ||
return | ||
if not job.release_base_dir: | ||
self._data = { | ||
"message": f'release action {job.context.action} {job.context.name} skipped (undefined release_base_dir)' | ||
} | ||
return | ||
dest_dir = self.release_dir(job) | ||
os.makedirs(dest_dir, exist_ok=True) | ||
deployed_files = set() | ||
for file in job.release_files: | ||
dest = f"{dest_dir}/{file}" | ||
download_to(self.download_url(job, file), dest) | ||
deployed_files.add(dest) | ||
extra_action_message = self.extra_action(job) | ||
message = f'release {job.context.release_name} {job.context.name}, '\ | ||
f'event: {job.context.event}, '\ | ||
f'deployed file: {deployed_files}' | ||
if extra_action_message: | ||
message = f'{message}, {extra_action_message}' | ||
self._data = {'message': message} |
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
Oops, something went wrong.