zuul-jobs/playbooks/buildproject.yaml
Saul Wold 057693fe37 Add Ansible Playbook to build specfiles via Zuul
This initial playbook and roles builds both CentOS and openSUSE
specfiles. The build occurs on OBS and is currently done in a
sandbox area in my home project [0]. The job currently just
starts the OBS job, it does not currently check the build
results, this will come later.

This has been tested with fault so far. The zuul template will
be added to each repo as specfiles are updated.

Added support to automagically build _service files.

[0] https://build.opensuse.org/project/subprojects/home:saulwold

zuul.d/projects needs to use the stx-zuul-jobs-linters to set
ANSIBLE_ROLES_PATH correctly

Change-Id: I6490030894b5887f33a55b1e66e374bcd50960d5
Signed-off-by: Saul Wold <sgw@linux.intel.com>
2019-09-03 15:35:39 -07:00

235 lines
6.2 KiB
YAML

- hosts: all
vars:
project_ver: 1.0
src_project: "Cloud:StarlingX:2.0"
target_project: "home:saulwold:sandbox-{{ target_distro }}"
test_project: "{{ target_project }}-{{ project_ver }}"
stx_project_desc: ""
stx_url: ""
osc_user: "saulwold"
osc_register: osc_result
obs_projects: []
spec_dirs: []
sorted_dirs: []
osc_key_key: "@ub@FB7OZxs391wt"
tasks:
- name: Print OS Family
debug:
msg: "OS distribution: {{ ansible_distribution }}"
- name: Setup local distro flag CentOS
set_fact:
target_distro: centos
when: ansible_distribution == "CentOS"
- name: Setup local distro flag openSUSE
set_fact:
target_distro: opensuse
when: ansible_distribution == "openSUSE Leap"
- name: Setup local directories when not using zuul
set_fact:
top_dir: /test
src_dir: /test
when: zuul is not defined
- name: Setup local directories from zuul data
set_fact:
top_dir: "{{ zuul.executor.src_root }}"
src_dir: "{{ zuul.project.src_dir }}"
when: zuul is defined
- name: Print OS Family
debug:
msg: "OS distribution: {{ ansible_distribution }} {{ target_distro }}"
- name: Get OSC Command
import_role:
name: osc
tasks_from: install_osc
- name: Create temporary directory
tempfile:
state: directory
prefix: stx.
register: stx_pkg_tmpdir
- name: Setup oscrc file
import_role:
name: osc
tasks_from: create_oscrc
- name: OSC Version
import_role:
name: osc
vars:
osc_options: "--version"
register: osc_version
- name: Clean OSC Project
import_role:
name: osc
vars:
osc_options: rdelete -r -m 'rpm-packing CI Cleanup' {{ test_project }}
ignore_errors: yes
- name: Create Project
import_role:
name: osc
tasks_from: create_meta
- name: Freeze Project
import_role:
name: osc
tasks_from: freeze
- name: Init Project
import_role:
name: osc
vars:
osc_options: init {{ test_project }}
- name: Add prjconf
import_role:
name: osc
tasks_from: create_prjconf
when: target_distro == "centos"
- name: Find local directories with spec files
find:
paths: "{{ src_dir }}"
hidden: false
file_type: directory
patterns: "{{ target_distro }}"
recurse: yes
register: specfiles
- name: Generate Repo name
set_fact:
repo_name: "{{ specfiles.files.0.path.split('/')[-3] }}"
- name: Generate Repo Dir
set_fact:
repo_dir: "{{ src_dir}}/{{ repo_name }}"
- debug:
msg: "{{ repo_name }}: {{ repo_dir }} "
- meta: end_play
- name: List spec files
debug:
msg: "Specfile List: {{ specfiles }}"
- name: Create Project list
set_fact:
spec_dirs: "{{ spec_dirs }} + [ '{{ item.path.split('/')[-2] }}' ]"
with_items: "{{ specfiles.files }}"
- name: Sort directories
set_fact:
sorted_dirs: "{{ spec_dirs | sort | unique }}"
- name: "list Sorted Directories"
debug:
msg: "Sorted Directories: {{ item }}"
with_items: "{{ sorted_dirs }}"
- name: OSC mkpac
import_role:
name: osc
tasks_from: mkpac
- name: OSC detachbranch
import_role:
name: osc
tasks_from: detachbranch
- name: Create Service file
include_role:
name: osc
tasks_from: create_service
vars:
package_dir_orig: "{{ package_name }}/{{ lookup('ini', 'SRC_DIR type=properties file=/fault/' + package_name + '/centos/build_srpm.data') | regex_replace('\"', '') | regex_replace('\\/\\.', '') }}"
with_items: "{{ sorted_dirs }}"
loop_control:
loop_var: package_name
- name: OSC commit
import_role:
name: osc
tasks_from: commit
# pushd ./out
# sleep 5
# # Check if there is no change, then pretent success
# if [ $($osc_timed ls ${{OBS_TEST_PROJECT}} | wc -l) -lt 1 ]; then
# echo "Apparently there is no change... claiming SUCCESS"
# exit 0
# fi
#
# while true; do
# unset pending
# unset failed
# unset kickscheduler
# unset succeeded
# res=`osc results --csv -r standard`
# if [ $? -ne 0 ]; then
# sleep 5
# continue
# fi
# echo "... $(date): "
# for r in $res; do
# # some failures?
# if [[ $r =~ broken$ ]]; then
# echo "ignoring OBS broken state"
# echo $r
# continue
# fi
# # some failures?
# if [[ $r =~ (failed$|unresolvable$) ]]; then
# echo $r
# failed=1
# fi
# # still pending builds?
# if [[ $r =~ (blocked$|scheduled$|dispatching$|building$|signing$) ]]; then
# pending=1
# fi
# # scheduler stuck?
# if [[ $r =~ (finished$|unknown$|outdated$) ]]; then
# kickscheduler=1
# fi
# # found something?
# if [[ $r =~ succeeded$ ]]; then
# succeeded=1
# fi
# done
#
# if [ -n "$kickscheduler" ]; then
# echo "# $(date)" | osc meta prjconf -F - ${{OBS_TEST_PROJECT}}
# sleep $((RANDOM%60+30))
# echo "kicking scheduler"
# continue
# fi
#
# if [ -n "$pending" ]; then
# sleep $((RANDOM%50+30))
# echo ""
# continue
# fi
#
# if [ -n "$failed" ]; then
# echo "Build failed :-("
# exit 1
# elif [ -n "$succeeded" ];
# break
# fi
# done
#
# - name: Clean-up tmp directory
# file:
# path: "{{ stx_pkg_tmpdir.path }}"
# state: absent
# when: stx_pkg_tmpdir.path is defined