Files
codegenerator/playbooks/rust/all.yaml
Artem Goncharov b346573617 Only compile generated rust code
We should not try to compile the code that is not being generated. This
helps preventing breaking changes but at the same time slows down
propagation of the real API changes. Downstream tools (i.e.
openstack_tui) need to be adapted in the PR propagating the sdk change
until we start generating tui code as well.

Change-Id: I3f583deb9b3c310a9b05371e583ba570f80bbb77
2024-11-28 14:53:35 +01:00

82 lines
2.7 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 -p openstack_sdk -p openstack_cli"
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 (only generated crates)"
ansible.builtin.command:
cmd: "cargo build -p openstack_sdk -p openstack_cli"
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 | quote }} -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"