Apply the generated sources on top of the target repository and create patch file. In addition to that save complete content as job artifacts. post job is pushing changes to the upstream repository (using public SSH key of repository set by Zuul and added as a deployment key). PR is not created, since that requires additionally separate API key. Change-Id: I090b87e05ede95f8542a427207bea711e5cc5df4
82 lines
2.6 KiB
YAML
82 lines
2.6 KiB
YAML
---
|
|
- hosts: all
|
|
roles:
|
|
- "ensure-rust"
|
|
tasks:
|
|
- name: "Generate Rust code"
|
|
ansible.builtin.include_role:
|
|
name: "codegenerator"
|
|
vars:
|
|
codegenerator_target: "{{ zj_item.1 }}"
|
|
codegenerator_metadata: "{{ zj_item.0.metadata }}"
|
|
codegenerator_service_type: "{{ zj_item.0.service }}"
|
|
loop: "{{ codegenerator_service_metadata_target_map | subelements('targets') }}"
|
|
loop_control:
|
|
loop_var: zj_item
|
|
|
|
- name: "Checkout target repository"
|
|
ansible.builtin.git:
|
|
repo: "{{ rust_sdk_git_repo }}"
|
|
dest: "{{ rust_project_dir }}"
|
|
|
|
- name: "Pre-Compile current code to ensure it builds"
|
|
ansible.builtin.command:
|
|
cmd: "cargo build"
|
|
chdir: "{{ rust_project_dir }}"
|
|
|
|
- name: "Overwrite generated files"
|
|
ansible.builtin.copy:
|
|
src: "{{ codegenerator_base_dir }}/wrk/rust/"
|
|
dest: "{{ rust_project_dir }}"
|
|
remote_src: True
|
|
|
|
- name: "Optimize generated code with clippy"
|
|
ansible.builtin.command:
|
|
cmd: "cargo clippy --fix --lib --tests --allow-dirty"
|
|
chdir: "{{ rust_project_dir }}"
|
|
|
|
- name: "Compile new code"
|
|
ansible.builtin.command:
|
|
cmd: "cargo build"
|
|
chdir: "{{ rust_project_dir }}"
|
|
|
|
- name: "Checkout new branch"
|
|
ansible.builtin.command:
|
|
cmd: "git checkout -b codegenerator_{{ zuul.change }}"
|
|
chdir: "{{ rust_project_dir }}"
|
|
|
|
- name: "Configure git username"
|
|
ansible.builtin.command: "git config --global user.name 'OpenStack codegenerator'"
|
|
|
|
- name: "Configure git email"
|
|
ansible.builtin.command: "git config --global user.email 16461884+gtema@users.noreply.github.com"
|
|
|
|
- name: "Stage files for commit"
|
|
ansible.builtin.command:
|
|
cmd: "git add ."
|
|
chdir: "{{ rust_project_dir }}"
|
|
|
|
- name: "Check staged files"
|
|
ansible.builtin.command:
|
|
cmd: "git diff --staged"
|
|
chdir: "{{ rust_project_dir }}"
|
|
register: "staged_changes"
|
|
|
|
- name: "Commit changes"
|
|
ansible.builtin.command:
|
|
cmd: "git commit -m 'feat: New generated content' -m '{{ zuul.change_message }}' -m 'Changes are triggered by {{ zuul.change_url }}'"
|
|
chdir: "{{ rust_project_dir }}"
|
|
register: "commit"
|
|
when:
|
|
# Only commit when there is anything to commit
|
|
- "staged_changes.stdout | length > 0"
|
|
|
|
- name: "Format patch"
|
|
ansible.builtin.command:
|
|
cmd: "git format-patch -1 --output {{ patch_path }}"
|
|
chdir: "{{ rust_project_dir }}"
|
|
when:
|
|
# Only prepare when there is anything to commit
|
|
- "commit is defined"
|
|
- "commit.changed"
|