-
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
23 changed files
with
489 additions
and
112 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,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), | ||
config_file=dict(type='str', required=False), | ||
) | ||
) | ||
|
||
user = module.params['user'] | ||
project = module.params['project'] | ||
srpm = module.params['srpm'] | ||
wait = module.params['wait'] | ||
chroots = module.params['chroots'] | ||
config_file = module.params['config_file'] | ||
|
||
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, config_file=config_file) | ||
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+(.+)\s*', output, re.MULTILINE) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
Retrieve a particular build for a package 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(): | ||
""" | ||
Retrieve a particular build for a package in Copr | ||
""" | ||
module = AnsibleModule( | ||
argument_spec=dict( | ||
user=dict(type='str', required=True), | ||
project=dict(type='str', required=True), | ||
nevr=dict(type='str', required=True), | ||
package=dict(type='str', required=True), | ||
config_file=dict(type='str', required=False), | ||
) | ||
) | ||
|
||
user = module.params['user'] | ||
project = module.params['project'] | ||
nevr = module.params['nevr'] | ||
package = module.params['package'] | ||
config_file = module.params['config_file'] | ||
|
||
command = [ | ||
'get-package', | ||
full_name(user, project), | ||
'--name', | ||
package, | ||
'--with-all-builds' | ||
] | ||
|
||
try: | ||
package_info = json.loads(copr_cli(command, config_file=config_file)) | ||
except CoprCliCommandError as error: | ||
if "Error: No package with name {} in copr {}".format(package, project) in error.message: | ||
module.exit_json(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) | ||
|
||
successful_builds = (build for build in package_info['builds'] if build['state'] == 'succeeded') | ||
successful_nevrs = ("{}-{}".format(package, build['source_package']['version']) for build in successful_builds) | ||
exists = nevr in successful_nevrs | ||
|
||
module.exit_json(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
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 @@ | ||
""" | ||
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), | ||
config_file=dict(type='str', required=False), | ||
) | ||
) | ||
|
||
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'] | ||
config_file = module.params['config_file'] | ||
|
||
command = [ | ||
'fork', | ||
full_name(src_user, src_project), | ||
full_name(dest_user, dest_project) | ||
] | ||
|
||
try: | ||
fork_output = copr_cli(command, config_file=config_file) | ||
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, config_file=config_file) | ||
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
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 |
---|---|---|
@@ -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.