Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Once the PR is merged, the container will be build and push to the repository
* `password`: The password for the username
* `repository`: the repository to push the container, for example `quay.io/myakove/github-webhook-server`
* `tag`: The container tag to use when pushing the container
* `release`: if `true` a new container will be pushed with the release version as the tag


```yaml
Expand Down
1 change: 1 addition & 0 deletions example.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ repositories:
password: <registry_password>
repository: <registry_repository_full_path>
tag: <image_tag>
release: true # Push image to registry on new release with release as the tag
build-args: # build args to send to podman build command
- build-arg1=1
- build-arg2=2
Expand Down
18 changes: 11 additions & 7 deletions webhook_server_container/libs/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def _repo_data_from_config(self):
self.container_tag = self.build_and_push_container.get("tag", "latest")
self.container_build_args = self.build_and_push_container.get("build-args")
self.container_command_args = self.build_and_push_container.get("args")
self.container_release = self.build_and_push_container.get("release")

self.auto_verified_and_merged_users = config_data.get(
"auto-verified-and-merged-users", repo_data.get("auto-verified-and-merged-users", [])
Expand Down Expand Up @@ -762,10 +763,13 @@ def process_pull_request_webhook_data(self):

def process_push_webhook_data(self):
tag = re.search(r"refs/tags/?(.*)", self.hook_data["ref"])
if tag and self.pypi:
if tag:
tag_name = tag.group(1)
self.app.logger.info(f"{self.log_prefix} Processing push for tag: {tag_name}")
self.upload_to_pypi(tag_name=tag_name)
if self.pypi:
self.app.logger.info(f"{self.log_prefix} Processing push for tag: {tag_name}")
self.upload_to_pypi(tag_name=tag_name)
if self.container_release:
self._run_build_container(push=True, set_check=False, tag=tag_name)

def process_pull_request_review_webhook_data(self):
if not self.pull_request:
Expand Down Expand Up @@ -1208,11 +1212,11 @@ def _comment_with_details(title, body):
</details>
"""

def _container_repository_and_tag(self):
tag = self.container_tag if self.pull_request.is_merged() else f"pr-{self.pull_request.number}"
def _container_repository_and_tag(self, tag=None):
tag = tag or self.container_tag if self.pull_request.is_merged() else f"pr-{self.pull_request.number}"
return f"{self.container_repository}:{tag}"

def _run_build_container(self, set_check=True, push=False, is_merged=None):
def _run_build_container(self, set_check=True, push=False, is_merged=None, tag=None):
if not self.build_and_push_container:
return False

Expand All @@ -1223,7 +1227,7 @@ def _run_build_container(self, set_check=True, push=False, is_merged=None):

self.set_container_build_in_progress()

_container_repository_and_tag = self._container_repository_and_tag()
_container_repository_and_tag = self._container_repository_and_tag(tag=tag)
build_cmd = f"--network=host -f {self.container_repo_dir}/{self.dockerfile} -t {_container_repository_and_tag}"
if self.container_build_args:
build_args = [f"--build-arg {b_arg}" for b_arg in self.container_build_args][0]
Expand Down