-
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
15 changed files
with
375 additions
and
115 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,56 @@ | ||
""" | ||
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=True), | ||
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) | ||
|
||
builds = re.findall(r'^Build was added to.+:\n^\s(.+)', output, re.MULTILINE) | ||
|
||
module.exit_json(changed=True, output=output, builds=builds) | ||
|
||
|
||
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_project_names }}" | ||
loop_control: | ||
loop_var: project_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,84 @@ | ||
--- | ||
- when: | ||
- not build_package_scratch | ||
- not build_package_copr_rebuild | ||
block: | ||
- name: "Package name" | ||
rpm_nvr: | ||
spec_file: "{{ spec_file_path }}" | ||
scl: "{{ tag.scl | default(omit) }}" | ||
dist: "{{ tag.dist | default(omit) }}" | ||
macros: "{{ tag.macros | default(omit) }}" | ||
register: package_nvr | ||
|
||
- name: Check build status | ||
check_copr_build: | ||
user: "{{ copr_project_user }}" | ||
project: "{{ project_name }}" | ||
nvr: "{{ package_nvr.nvr }}" | ||
package: "{{ package_nvr.name }}" | ||
register: build_exists | ||
|
||
- debug: | ||
msg: "{{ build_exists.skipped is defined }}" | ||
|
||
- name: Create temporary build directory | ||
tempfile: | ||
state: directory | ||
suffix: srpms | ||
register: srpm_directory | ||
when: (srpm_directory is not defined and (build_exists.exists is defined and not build_exists.exists)) or build_package_copr_rebuild | ||
|
||
- name: 'Build SRPM' | ||
srpm: | ||
package: "{{ inventory_dir }}/{{ package_base_dir }}/{{ inventory_hostname }}" | ||
output: "{{ srpm_directory.path if 'path' in srpm_directory else srpm_directory }}" | ||
source_location: "{{ source_location | default(omit) }}" | ||
source_system: "{{ source_system | default(omit) }}" | ||
register: srpm_build | ||
when: (srpm_directory is defined and (build_exists.exists is defined and not build_exists.exists)) or build_package_copr_rebuild or build_package_scratch | ||
|
||
- when: not build_package_scratch and not build_exists.exists | ||
block: | ||
- name: 'Run build' | ||
copr_build: | ||
user: "{{ copr_project_user }}" | ||
project: "{{ project_name }}" | ||
srpm: "{{ srpm_build.path }}" | ||
wait: "{{ build_package_wait }}" | ||
chroots: "{{ build_package_copr_chroots | default(omit) }}" | ||
register: copr_builds | ||
ignore_errors: "{{ build_package_skip_failed_build | default(false) }}" | ||
|
||
- when: build_package_scratch | ||
block: | ||
- name: Define Copr scratch project name | ||
set_fact: | ||
copr_scratch_project: "{{ project_name }}-scratch-{{ 999999999 | random | to_uuid }}" | ||
when: copr_scratch_project is not defined | ||
|
||
- name: Define Copr scatch user name | ||
set_fact: | ||
copr_scratch_user: "{{ copr_project_user }}" | ||
when: copr_scratch_user is not defined | ||
|
||
- name: Create a Copr fork for scratch builds | ||
copr_fork: | ||
src_user: "{{ copr_project_user }}" | ||
src_project: "{{ project_name }}" | ||
dest_user: "{{ copr_scratch_user }}" | ||
dest_project: "{{ copr_scratch_project }}" | ||
delete_after_days: 4 | ||
|
||
- name: 'Run build' | ||
copr_build: | ||
user: "{{ copr_scratch_user }}" | ||
project: "{{ copr_scratch_project }}" | ||
srpm: "{{ srpm_build.path }}" | ||
wait: "{{ build_package_wait }}" | ||
chroots: "{{ build_package_copr_chroots | default(omit) }}" | ||
register: copr_builds | ||
|
||
- debug: | ||
msg: "{{ copr_builds }}" | ||
when: copr_builds is defined |
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 +1,2 @@ | ||
--- | ||
copr_project_chroots: [] |
Oops, something went wrong.