Add publish job

Add a job that collects built OpenAPI specs and prepares a single
delivery. Those can be then places to some authority location similar to
the service-types-authority.

Change-Id: I18bfb2a5195f88153d3a23072bc8a4351a5b7f1b
This commit is contained in:
Artem Goncharov 2024-06-12 13:47:23 +02:00
parent bd818cc225
commit 668add9107
5 changed files with 91 additions and 5 deletions

View File

@ -0,0 +1,30 @@
---
- hosts: all
vars:
dest: "{{ zuul.project.src_dir }}/doc/build/html"
tasks:
- name: Precreate directories
ansible.builtin.file:
path: "{{ dest }}/specs/{{ zj_artifact.metadata.service_type }}"
state: "directory"
loop: "{{ zuul.artifacts }}"
loop_control:
loop_var: zj_artifact
when:
- "'metadata' in zj_artifact"
- "'type' in zj_artifact.metadata"
- "'service_type' in zj_artifact.metadata"
- "zj_artifact.metadata.type == 'openapi'"
- name: Download specs
ansible.builtin.uri:
url: "{{ zj_artifact.url }}"
dest: "{{ dest }}/specs/{{ zj_artifact.metadata.service_type }}"
loop: "{{ zuul.artifacts }}"
loop_control:
loop_var: zj_artifact
when:
- "'metadata' in zj_artifact"
- "'type' in zj_artifact.metadata"
- "'service_type' in zj_artifact.metadata"
- "zj_artifact.metadata.type == 'openapi'"

View File

@ -1,5 +1,7 @@
---
- hosts: all
vars:
specs_src: "{{ ansible_user_dir }}/{{ codegenerator_work_dir }}/openapi_specs"
tasks:
- name: Ensure local output dirs
delegate_to: localhost
@ -14,24 +16,41 @@
- name: Collect OpenAPI specs
synchronize:
dest: "{{ zj_output.dest }}/"
dest: "{{ zj_output.dest }}"
mode: pull
src: "{{ ansible_user_dir }}/{{ codegenerator_work_dir }}/{{ zj_output.src }}"
src: "{{ zj_output.src }}"
verify_host: true
owner: false
group: false
loop:
- dest: "{{ zuul.executor.work_root }}/artifacts"
src: "openapi_specs"
src: "{{ specs_src }}"
loop_control:
loop_var: zj_output
- name: Find all generated specs
ansible.builtin.find:
paths: "{{ specs_src }}"
patterns: "*.yaml"
recurse: true
# Search for anything and filter later
file_type: "any"
register: openapi_specs
- name: Return artifact to Zuul
zuul_return:
data:
zuul:
artifacts:
- name: "OpenAPI specs"
url: "artifacts/openapi_specs"
- name: "{{ openapi_service }} OpenAPI spec {{ zj_item.path | basename | splitext | first }}"
url: "artifacts/openapi_specs{{ zj_item.path | regex_replace(specs_src) }}"
metadata:
type: openapi
service_type: "{{ openapi_service }}"
version: "{{ zj_item.path | basename | splitext | first }}"
loop: "{{ openapi_specs.files }}"
loop_control:
loop_var: zj_item
when:
# only interested in files/links
- "not zj_item.isdir"

10
tox.ini
View File

@ -60,6 +60,16 @@ deps =
commands =
pre-commit run --all-files --show-diff-on-failure
[testenv:publish]
description =
No-op env for publishing built Specs
deps =
# We need any dependency, since only that causes `tox -epublish --notest` to create log dir that is required by tox-siblings role
pbr
skip_install = True
allowlist_externals =
commands =
[flake8]
application-import-names = codegenerator
# The following are ignored on purpose. It's not super worth it to fix them.

View File

@ -238,3 +238,28 @@
codegenerator_api_ref:
project: "opendev.org/openstack/placement"
path: "/api-ref/build/html/index.html"
- job:
name: publish-openapi-specs
parent: opendev-tox-docs
description: |
Published OpenAPI specs
dependencies:
- name: codegenerator-openapi-block-storage-tips-with-api-ref
soft: true
- name: codegenerator-openapi-compute-tips-with-api-ref
soft: true
- name: codegenerator-openapi-identity-tips-with-api-ref
soft: true
- name: codegenerator-openapi-image-tips-with-api-ref
soft: true
- name: codegenerator-openapi-load-balancing-tips-with-api-ref
soft: true
- name: codegenerator-openapi-network-tips-with-api-ref
soft: true
- name: codegenerator-openapi-placement-tips-with-api-ref
soft: true
pre-run:
- playbooks/openapi/fetch.yaml
vars:
tox_envlist: publish

View File

@ -13,6 +13,7 @@
- codegenerator-openapi-load-balancing-tips-with-api-ref
- codegenerator-openapi-network-tips-with-api-ref
- codegenerator-openapi-placement-tips-with-api-ref
- publish-openapi-specs
gate:
jobs:
- openstack-tox-pep8
@ -24,3 +25,4 @@
- codegenerator-openapi-load-balancing-tips-with-api-ref
- codegenerator-openapi-network-tips-with-api-ref
- codegenerator-openapi-placement-tips-with-api-ref
- publish-openapi-specs