-
Notifications
You must be signed in to change notification settings - Fork 13
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
16 changed files
with
411 additions
and
119 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,52 @@ | ||
""" | ||
Check if a build already exists in Copr | ||
""" | ||
|
||
import json | ||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.copr import copr_cli, CoprCliCommandError, full_name # pylint:disable=import-error,no-name-in-module | ||
|
||
|
||
def main(): | ||
""" | ||
Check if a build already exists in Copr | ||
""" | ||
module = AnsibleModule( | ||
argument_spec=dict( | ||
user=dict(type='str', required=True), | ||
project=dict(type='str', required=True), | ||
nvr=dict(type='str', required=True), | ||
package=dict(type='str', required=True), | ||
) | ||
) | ||
|
||
user = module.params['user'] | ||
project = module.params['project'] | ||
nvr = module.params['nvr'] | ||
package = module.params['package'] | ||
|
||
command = [ | ||
'get-package', | ||
full_name(user, project), | ||
'--name', | ||
package, | ||
'--with-all-builds' | ||
] | ||
|
||
try: | ||
package_info = json.loads(copr_cli(command)) | ||
except CoprCliCommandError as error: | ||
if "Error: No package with name {} in copr {}".format(package, project): | ||
module.exit_json(changed=True, exists=False) | ||
else: | ||
module.fail_json(msg='Retrieval of package from Copr failed', command=command, output=error.message, | ||
repo_name=full_name(user, project), package=package) | ||
|
||
builds = (build for build in package_info['builds'] if build['state'] == 'succeeded') | ||
exists = any("{}-{}".format(package, build['source_package']['version']) == nvr for build in builds) | ||
|
||
module.exit_json(changed=not exists, exists=exists) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,59 @@ | ||
""" | ||
Release a package to Copr | ||
""" | ||
|
||
import re | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.copr import copr_cli, CoprCliCommandError, full_name # pylint:disable=import-error,no-name-in-module | ||
|
||
|
||
def main(): | ||
""" | ||
Release a package to Copr | ||
""" | ||
module = AnsibleModule( | ||
argument_spec=dict( | ||
user=dict(type='str', required=True), | ||
project=dict(type='str', required=True), | ||
srpm=dict(type='path', required=True), | ||
wait=dict(type='bool', required=False, default=False), | ||
chroots=dict(type='list', required=False), | ||
) | ||
) | ||
|
||
user = module.params['user'] | ||
project = module.params['project'] | ||
srpm = module.params['srpm'] | ||
wait = module.params['wait'] | ||
chroots = module.params['chroots'] | ||
|
||
command = [ | ||
'build', | ||
full_name(user, project), | ||
srpm | ||
] | ||
|
||
if not wait: | ||
command.append('--nowait') | ||
|
||
if chroots: | ||
for chroot in chroots: | ||
command.extend(['--chroot', chroot]) | ||
|
||
try: | ||
output = copr_cli(command) | ||
except CoprCliCommandError as error: | ||
module.fail_json(msg='Copr build failed', command=error.command, output=error.message, | ||
repo_name=full_name(user, project), srpm=srpm) | ||
|
||
build_urls = re.findall(r'^Build was added to.+:\n^\s(.+)', output, re.MULTILINE) | ||
build_urls = [url.strip() for url in build_urls] | ||
|
||
builds = re.findall(r'^Created builds:\s(\d+)', output, re.MULTILINE) | ||
|
||
module.exit_json(changed=True, output=output, builds=builds, build_urls=build_urls) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,57 @@ | ||
""" | ||
Fork a Copr project | ||
""" | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.copr import copr_cli, CoprCliCommandError, full_name # pylint:disable=import-error,no-name-in-module | ||
|
||
|
||
def main(): | ||
""" | ||
Fork a Copr project | ||
""" | ||
module = AnsibleModule( | ||
argument_spec=dict( | ||
src_user=dict(type='str', required=True), | ||
src_project=dict(type='str', required=True), | ||
dest_user=dict(type='str', required=True), | ||
dest_project=dict(type='str', required=True), | ||
delete_after_days=dict(type='str', required=False, default=None), | ||
) | ||
) | ||
|
||
src_user = module.params['src_user'] | ||
src_project = module.params['src_project'] | ||
dest_user = module.params['dest_user'] | ||
dest_project = module.params['dest_project'] | ||
delete_after_days = module.params['delete_after_days'] | ||
|
||
command = [ | ||
'fork', | ||
full_name(src_user, src_project), | ||
full_name(dest_user, dest_project) | ||
] | ||
|
||
try: | ||
fork_output = copr_cli(command) | ||
except CoprCliCommandError as error: | ||
module.fail_json(msg='Copr project forking failed', command=' '.join(error.command), output=error.message) | ||
|
||
if delete_after_days: | ||
modify_command = [ | ||
'modify', | ||
full_name(dest_user, dest_project), | ||
'--delete-after-days', | ||
delete_after_days | ||
] | ||
|
||
try: | ||
copr_cli(modify_command) | ||
except CoprCliCommandError as error: | ||
module.fail_json(msg='Copr project forking failed', command=' '.join(error.command), output=error.message) | ||
|
||
module.exit_json(changed=True, output=fork_output) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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
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 |
---|---|---|
@@ -1,53 +1,5 @@ | ||
--- | ||
- when: not build_package_scratch | ||
block: | ||
- name: 'Release to copr' | ||
tito_release: | ||
directory: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}" | ||
arguments: "{{ build_package_tito_args }}" | ||
test: "{{ build_package_test }}" | ||
scratch: "{{ build_package_scratch }}" | ||
releasers: "{{ releasers }}" | ||
releaser_arguments: "{{ build_package_tito_releaser_args }}" | ||
register: build_package_tito_release | ||
|
||
- name: 'Wait for tasks to finish' | ||
include_tasks: wait.yml | ||
when: build_package_wait|bool | ||
|
||
- when: build_package_scratch | ||
block: | ||
- name: Define copr repo name | ||
set_fact: | ||
copr_repo_name: "{{ copr_user }}/{{ build_package_scratch_repo }}-{{ 999999999 | random | to_uuid }}" | ||
run_once: true | ||
when: copr_repo_name is not defined | ||
|
||
- name: 'Write copr repo name to vars file' | ||
copy: | ||
content: "{{ 'copr_repo: ' + copr_repo_name | to_yaml }}" | ||
dest: "{{ obal_tmp_dir }}/copr_repo" | ||
mode: '0640' | ||
run_once: true | ||
|
||
- include_role: | ||
name: copr_repo | ||
run_once: true | ||
|
||
- name: 'Build SRPM' | ||
tito_build: | ||
directory: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}" | ||
srpm: true | ||
scl: "{{ scl }}" | ||
register: srpm_build | ||
|
||
- name: 'Run build' | ||
command: >- | ||
copr-cli build | ||
{% if not build_package_wait | bool %}--nowait{% endif %} | ||
{{ copr_repo_name }} | ||
{{ srpm_build.path }} | ||
register: build_status | ||
|
||
- debug: | ||
msg: "{{ build_status.stdout_lines | join('\n') }}" | ||
- include_tasks: copr_build.yml | ||
loop: "{{ copr_projects }}" | ||
loop_control: | ||
loop_var: copr_project |
Oops, something went wrong.